class AutomationObject::Dsl::Base

Base DSL Object

Public Class Methods

has_many(children_name, composite_class) 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 composite_class [Class] interface

# File lib/automation_object/dsl/_base.rb, line 72
def has_many(children_name, composite_class)
  has_many_relationships[children_name] = composite_class
end
has_many_relationships() click to toggle source

@return [Hash] relationships for the composite

# File lib/automation_object/dsl/_base.rb, line 77
def has_many_relationships
  @has_many_relationships ||= {}
end
new(blue_prints, state) click to toggle source

@param [AutomationObject::BluePrint::Composite::] blue_prints @param [AutomationObject::State::Session] state

Calls superclass method
# File lib/automation_object/dsl/_base.rb, line 9
def initialize(blue_prints, state)
  ostruct_hash = {}

  # Add attributes the call super
  self.class.has_many_relationships.each do |name, composite_class|
    blue_prints.send(name).each do |child_key, child_blue_prints|
      child_state = state.send(name)[child_key]
      ostruct_hash[child_key] = composite_class.new(child_blue_prints, child_state, child_key)
    end
  end

  super ostruct_hash
end

Public Instance Methods

formatted_name(key, indent) click to toggle source

@param key [String] @param indent [Integer] @return [String]

# File lib/automation_object/dsl/_base.rb, line 52
def formatted_name(key, indent)
  color = self[key].active? ? :green : :blue
  "\n#{' ' * indent} #{key}:".colorize(color)
end
inspect(_indent = 5) click to toggle source

@param _indent [Integer] @return [String]

# File lib/automation_object/dsl/_base.rb, line 38
def inspect(_indent = 5)
  string = self.class.to_s

  to_h.each do |key, value|
    string += formatted_name(key, _indent)
    string += sub_inspect(value, _indent)
  end

  string
end
method_missing(method, *args, &block) click to toggle source

@param [Symbol] method @param [Array, nil] args @param [Proc] block

Calls superclass method
# File lib/automation_object/dsl/_base.rb, line 26
def method_missing(method, *args, &block)
  return super if to_h.key?(method)

  raise NoMethodError.new("undefined method '#{method}'", method, args)
end
sub_inspect(value, indent) click to toggle source

@param value [Object] @param indent [Integer] @return [String]

# File lib/automation_object/dsl/_base.rb, line 60
def sub_inspect(value, indent)
  if value.is_a?(Base)
    " #{value.inspect(indent + 10)}"
  else
    " #{value.inspect}"
  end
end
to_s() click to toggle source
# File lib/automation_object/dsl/_base.rb, line 32
def to_s
  inspect
end