Class: Qor::Dsl::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/qor_dsl/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, node = nil) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/qor_dsl/config.rb', line 6

def initialize type, node=nil
  self.__name = type
  self.__node = node
end

Instance Attribute Details

#__blockObject

Returns the value of attribute __block.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __block
  @__block
end

#__childrenObject

Returns the value of attribute __children.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __children
  @__children
end

#__nameObject

Returns the value of attribute __name.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __name
  @__name
end

#__nodeObject

Returns the value of attribute __node.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __node
  @__node
end

#__optionsObject

Returns the value of attribute __options.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __options
  @__options
end

#__parentObject

Returns the value of attribute __parent.



4
5
6
# File 'lib/qor_dsl/config.rb', line 4

def __parent
  @__parent
end

Instance Method Details

#__add_child(type, options, child) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/qor_dsl/config.rb', line 23

def __add_child(type, options, child)
  child.__parent  = self
  child.__options = options
  self.__children[type.to_sym] = child

  method_defination = <<-DOC
    def #{type}(name=nil, *data, &blk)
      config = __children['#{type}'.to_sym]
      node = Qor::Dsl::Node.new(name)
      node.add_config(config)
      node.data = data
      node.block = blk
      __node.add_child(node)
      node.config.instance_eval(&blk) if block_given? && (config.__children.size > 0)
    end
  DOC

  self.instance_eval method_defination
end

#inspectObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/qor_dsl/config.rb', line 43

def inspect
  obj_options = {
    'name' => __name,
    'parent' => __parent && __parent.__name,
    'children' => __children.keys,
    'options' => __options,
    'block' => __block
  }
  Qor::Dsl.inspect_object(self, obj_options)
end

#node(type, options = {}, &blk) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/qor_dsl/config.rb', line 11

def node(type, options={}, &blk)
  child = Qor::Dsl::Config.new(type)
  child.instance_eval(&blk) if block_given?
  __add_child(type, options, child)

  self
end