class AutomationObject::Composite
Composite
is a super class that helps build composite objects based of a Hash
Composite
classes should inherit from this class and use the class-level methods to add the components
Attributes
Public Class Methods
Has many children relationship for the composite @param children_name [Symbol] name of the children, should be a BluePrint
method @param args [Hash] additional arguments, expects interface
# File lib/automation_object/helpers/composite.rb, line 79 def has_many(children_name, args) has_many_relationships[children_name] = args end
@return [Hash] relationships for the composite
# File lib/automation_object/helpers/composite.rb, line 84 def has_many_relationships @has_many_relationships ||= {} end
@param child_name [Symbol] name of key @param args [Hash] arguments
# File lib/automation_object/helpers/composite.rb, line 90 def has_one(child_name, args) has_one_relationships[child_name] = args end
@return [Hash] hash of relationships
# File lib/automation_object/helpers/composite.rb, line 95 def has_one_relationships @has_one_relationships ||= {} end
@param name [Symbol] name of the object @param parent [Object, nil] parent composite object @param location [String] string location for error/debugging purposes
# File lib/automation_object/helpers/composite.rb, line 18 def initialize(name = :top, parent = nil, location = 'top') self.name = name self.parent = parent self.location = location before_create_run add_has_one_relationships add_has_many_relationships after_create_run end
Public Instance Methods
# File lib/automation_object/helpers/composite.rb, line 67 def add_has_many_relationships self.class.has_many_relationships.each do |name, options| composite_children = get_children(name, options) children[name] = composite_children add_attribute(name, children[name]) end end
# File lib/automation_object/helpers/composite.rb, line 60 def add_has_one_relationships self.class.has_one_relationships.each do |name, options| children[name] = get_child(name, options) add_attribute(name, children[name]) end end
Abstract argument, override @param _name [Symbol] name of child @param _options [Hash] options for child @return child [Object] return child composite object
# File lib/automation_object/helpers/composite.rb, line 48 def get_child(_name, _options) raise 'Abstract method' end
Abstract argument, override @param _name [Symbol] name of child @param _options [Hash] options for child @return children [Hash] return children and names
# File lib/automation_object/helpers/composite.rb, line 56 def get_children(_name, _options) raise 'Abstract method' end
Get top composite Object @return [AutomationObject::Composite]
# File lib/automation_object/helpers/composite.rb, line 39 def top # Should recursively call top until parent is nil parent.nil? ? self : parent.top end