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

children[RW]
location[RW]
name[RW]
parent[RW]

Public Class Methods

has_many(children_name, args) click to toggle source

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
has_many_relationships() click to toggle source

@return [Hash] relationships for the composite

# File lib/automation_object/helpers/composite.rb, line 84
def has_many_relationships
  @has_many_relationships ||= {}
end
has_one(child_name, args) click to toggle source

@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
has_one_relationships() click to toggle source

@return [Hash] hash of relationships

# File lib/automation_object/helpers/composite.rb, line 95
def has_one_relationships
  @has_one_relationships ||= {}
end
new(name = :top, parent = nil, location = 'top') click to toggle source

@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

add_has_many_relationships() click to toggle source
# 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
add_has_one_relationships() click to toggle source
# 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
get_child(_name, _options) click to toggle source

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
get_children(_name, _options) click to toggle source

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
top() click to toggle source

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