class NodeElementOperations
Constants
- DefaultFieldOpSet
- DefaultKeyFields
Default works for node element operations, but not glue operations
Attributes
field_op_defs[RW]
field_op_set_sym[RW]
key_fields[RW]
node_key[RW]
required_instance_keys[RW]
required_save_keys[RW]
views[RW]
Public Class Methods
new(op_data = {})
click to toggle source
With no parameters - Defaults are used :op_sets_mod => The module with the data operations that apply to the data fields :field_op_set => The assignment of data fields to the data operations
# File lib/midas/node_element_operations.rb, line 212 def initialize(op_data = {}) @@log.debug {"Node Element Initialized with: #{op_data.inspect}"} if @@log.debug? #set the module with the operation definition and include them @ops_set_module = op_data[:op_sets_mod] ||DefaultOpSets self.class.__send__(:include, @ops_set_module) #why is this private? am I doing something wrong? #set the mapping between fields and the type of operations supported by those fields @field_op_set_sym = DefaultFieldOpSet.merge(op_data[:field_op_set] || {}) @@log.info {"Field Operations Set: #{@field_op_set_sym.inspect}"} if @@log.info? @field_op_defs = get_field_op_procs(@field_op_set_sym) #set the key fields that will work as node/record identifiers or other key fields @key_fields = op_data[:key_fields]||DefaultKeyFields raise "key_fields are required" unless @key_fields #we are no longer differentiating between keys required for insantiation and persistence #this can be added in the future easily though. @required_instance_keys = @key_fields[:required_keys] @required_save_keys = @key_fields[:required_keys] @node_key = @key_fields[:primary_key] @views = default_views(@field_op_set_sym) #TODO: Allow custom views in the future end
Public Instance Methods
get_field_op_procs(field_op_set_sym)
click to toggle source
# File lib/midas/node_element_operations.rb, line 248 def get_field_op_procs(field_op_set_sym) field_op_defs = {} #convert from symbol to actual Proc. Using symbol allows the type of op to be passed around #needed because the Proc is anonymous so self-referential data is hard to get @field_op_set_sym.each do |field, ops_sym| if ops_sym.class == Symbol ops_proc = lookup_op_proc(ops_sym) field_op_defs[field] = ops_proc else raise "Unrecognized operation definition label #{ops_orig.inspect}" end end field_op_defs end
lookup_op_proc(ops_sym)
click to toggle source
# File lib/midas/node_element_operations.rb, line 244 def lookup_op_proc(ops_sym) proc = @ops_set_module.op_sets_to_def_table[ops_sym] end
set_op(ops)
click to toggle source
# File lib/midas/node_element_operations.rb, line 236 def set_op(ops) ops.each do |field, ops_sym| op_proc = self.lookup_op_proc(ops_sym) ops[field] = op_proc end @field_op_defs = @field_op_defs.merge(ops) end