Class: NodeElementOperations
- Inherits:
-
Object
- Object
- NodeElementOperations
- Includes:
- DataModelViews
- Defined in:
- lib/midas/node_element_operations.rb
Constant Summary collapse
- DefaultFieldOpSet =
{:id => :static_ops, :data => :replace_ops, :name => :replace_ops, #convenience field for a node name :tags => :list_ops}
- DefaultKeyFields =
Default works for node element operations, but not glue operations
{ :required_keys => [:id], :primary_key => :id}
- @@log =
Set Logger
TinkitLog.set(self.name, :warn)
Constants included from DataModelViews
DataModelViews::OpIdToViewType
Instance Attribute Summary collapse
-
#field_op_defs ⇒ Object
Returns the value of attribute field_op_defs.
-
#field_op_set_sym ⇒ Object
Returns the value of attribute field_op_set_sym.
-
#key_fields ⇒ Object
Returns the value of attribute key_fields.
-
#node_key ⇒ Object
Returns the value of attribute node_key.
-
#required_instance_keys ⇒ Object
Returns the value of attribute required_instance_keys.
-
#required_save_keys ⇒ Object
Returns the value of attribute required_save_keys.
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
- #get_field_op_procs(field_op_set_sym) ⇒ Object
-
#initialize(op_data = {}) ⇒ NodeElementOperations
constructor
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.
- #lookup_op_proc(ops_sym) ⇒ Object
- #set_op(ops) ⇒ Object
Methods included from DataModelViews
Constructor Details
#initialize(op_data = {}) ⇒ NodeElementOperations
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
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# 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 |
Instance Attribute Details
#field_op_defs ⇒ Object
Returns the value of attribute field_op_defs.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def field_op_defs @field_op_defs end |
#field_op_set_sym ⇒ Object
Returns the value of attribute field_op_set_sym.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def field_op_set_sym @field_op_set_sym end |
#key_fields ⇒ Object
Returns the value of attribute key_fields.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def key_fields @key_fields end |
#node_key ⇒ Object
Returns the value of attribute node_key.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def node_key @node_key end |
#required_instance_keys ⇒ Object
Returns the value of attribute required_instance_keys.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def required_instance_keys @required_instance_keys end |
#required_save_keys ⇒ Object
Returns the value of attribute required_save_keys.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def required_save_keys @required_save_keys end |
#views ⇒ Object
Returns the value of attribute views.
201 202 203 |
# File 'lib/midas/node_element_operations.rb', line 201 def views @views end |
Instance Method Details
#get_field_op_procs(field_op_set_sym) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# 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) ⇒ Object
244 245 246 |
# 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) ⇒ Object
236 237 238 239 240 241 242 |
# 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 |