module Tengine::Support::Config::Definition

Attributes

__name__[RW]
__parent__[RW]
children[RW]

Public Class Methods

included(klass) click to toggle source
# File lib/tengine/support/config/definition.rb, line 13
def included(klass)
  klass.extend(ClassMethods)
  klass.class_eval do
    self.class_attribute :children, :instance_writer => false, :instance_reader => false
    self.children = []
    self.class_attribute :definition_reference_names, :instance_writer => false
    self.definition_reference_names = []
  end
end

Public Instance Methods

[](child_name) click to toggle source
# File lib/tengine/support/config/definition.rb, line 160
def [](child_name)
  self.send(child_name)
end
[]=(child_name, value) click to toggle source
# File lib/tengine/support/config/definition.rb, line 164
def []=(child_name, value)
  self.send("#{child_name}=", value)
end
accept_visitor(visitor) click to toggle source
# File lib/tengine/support/config/definition.rb, line 132
def accept_visitor(visitor)
  visitor.visit(self)
end
action?() click to toggle source
# File lib/tengine/support/config/definition.rb, line 157
def action?; false; end
child_by_name(__name__) click to toggle source
# File lib/tengine/support/config/definition.rb, line 107
def child_by_name(__name__)
  (children || []).detect{|child| child.__name__ == __name__}
end
find(name_array) click to toggle source
# File lib/tengine/support/config/definition.rb, line 111
def find(name_array)
  name_array = Array(name_array)
  head = name_array.shift
  if child = child_by_name(head)
    name_array.empty? ? child : child.find(name_array)
  else
    nil
  end
end
get_value(obj) click to toggle source
# File lib/tengine/support/config/definition.rb, line 144
def get_value(obj)
  obj.is_a?(Proc) ? self.instance_eval(&obj) : obj
end
instantiate_children() click to toggle source
# File lib/tengine/support/config/definition.rb, line 98
def instantiate_children
  @children = self.class.children.map do |class_child|
    child = class_child.dup
    child.__parent__ = self
    child
  end
  self
end
load(hash) click to toggle source
# File lib/tengine/support/config/definition.rb, line 128
def load(hash)
  hash.each{|__name__, value| send("#{__name__}=", value)}
end
long_opt() click to toggle source
# File lib/tengine/support/config/definition.rb, line 153
def long_opt
  '--' << name_array.join('-').gsub(%r{_}, '-')
end
name_array() click to toggle source
# File lib/tengine/support/config/definition.rb, line 140
def name_array
  (__parent__ ? __parent__.name_array : []) + [__name__]
end
root() click to toggle source
# File lib/tengine/support/config/definition.rb, line 136
def root
  __parent__ ? __parent__.root : nil
end
separator?() click to toggle source
# File lib/tengine/support/config/definition.rb, line 158
def separator?; false; end
short_opt() click to toggle source
# File lib/tengine/support/config/definition.rb, line 148
def short_opt
  r = root.mapping[ name_array ]
  r ? "-#{r}" : nil
end
to_hash() click to toggle source
# File lib/tengine/support/config/definition.rb, line 121
def to_hash
  children.inject({}) do |dest, child|
    dest[child.__name__] = child.to_hash
    dest
  end
end