class Proforma::Modeling::GenericContainer
This can be used as a super-class for models which are basically containers for simple arrays of elements
Attributes
child_class[R]
child_key[R]
children[R]
Public Class Methods
new(child_key, child_class, children = [])
click to toggle source
# File lib/proforma/modeling/generic_container.rb, line 15 def initialize(child_key, child_class, children = []) raise ArgumentError, 'child_key is required' unless child_key raise ArgumentError, 'child_class is required' unless child_class @child_class = child_class @child_key = child_key.to_s.to_sym @children = child_class.array(children) end
Public Instance Methods
compile(data, evaluator)
click to toggle source
# File lib/proforma/modeling/generic_container.rb, line 40 def compile(data, evaluator) compiled_children = children.map { |child| child.compile(data, evaluator) } self.class.new(child_key => compiled_children) end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/proforma/modeling/generic_container.rb, line 30 def method_missing(method_name, *args, &block) if method_name.to_s == child_key.to_s Array(children) elsif method_name.to_s == child_setter_name @children = args else super end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/proforma/modeling/generic_container.rb, line 24 def respond_to_missing?(method_name, include_private = false) method_name.to_s == child_key.to_s || method_name.to_s == child_setter_name || super end
Private Instance Methods
child_setter_name()
click to toggle source
# File lib/proforma/modeling/generic_container.rb, line 50 def child_setter_name "#{child_key}=" end