Class: Qor::Dsl::Node
- Inherits:
-
Object
- Object
- Qor::Dsl::Node
- Defined in:
- lib/qor_dsl/node.rb
Instance Attribute Summary collapse
-
#all_nodes ⇒ Object
Returns the value of attribute all_nodes.
-
#block ⇒ Object
Returns the value of attribute block.
-
#children ⇒ Object
Returns the value of attribute children.
-
#config ⇒ Object
Returns the value of attribute config.
-
#data ⇒ Object
Returns the value of attribute data.
-
#dummy ⇒ Object
Returns the value of attribute dummy.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #add_config(config) ⇒ Object
- #child_config(type) ⇒ Object
- #child_config_options(type) ⇒ Object
-
#config_name ⇒ Object
Node Config.
- #config_options ⇒ Object
- #deep_find(type = nil, name = nil, &block) ⇒ Object
- #dummy? ⇒ Boolean
- #find(type = nil, name = nil, nodes = children, &block) ⇒ Object
- #first(type = nil, name = nil, &block) ⇒ Object
-
#initialize(name = nil, options = {}) ⇒ Node
constructor
A new instance of Node.
-
#inspect_name ⇒ Object
Inspect.
- #is_node?(cname = nil, sname = nil) ⇒ Boolean
- #node(type, options = {}, &blk) ⇒ Object
- #parents ⇒ Object
- #root ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
Instance Attribute Details
#all_nodes ⇒ Object
Returns the value of attribute all_nodes.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def all_nodes @all_nodes end |
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def block @block end |
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def children @children end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def config @config end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def data @data end |
#dummy ⇒ Object
Returns the value of attribute dummy.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def dummy @dummy end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/qor_dsl/node.rb', line 4 def parent @parent end |
Instance Method Details
#add_child(child) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/qor_dsl/node.rb', line 81 def add_child(child) child.parent = self children << child root.all_nodes ||= [] root.all_nodes << child end |
#add_config(config) ⇒ Object
66 67 68 69 |
# File 'lib/qor_dsl/node.rb', line 66 def add_config(config) self.config = config config.__node = self end |
#child_config(type) ⇒ Object
21 22 23 |
# File 'lib/qor_dsl/node.rb', line 21 def child_config(type) config.__children[type] || nil end |
#child_config_options(type) ⇒ Object
25 26 27 |
# File 'lib/qor_dsl/node.rb', line 25 def (type) child_config(type). || {} rescue {} end |
#config_name ⇒ Object
Node Config
13 14 15 |
# File 'lib/qor_dsl/node.rb', line 13 def config_name config.__name end |
#config_options ⇒ Object
17 18 19 |
# File 'lib/qor_dsl/node.rb', line 17 def config. || {} rescue {} end |
#deep_find(type = nil, name = nil, &block) ⇒ Object
88 89 90 91 92 |
# File 'lib/qor_dsl/node.rb', line 88 def deep_find(type=nil, name=nil, &block) nodes = root.all_nodes nodes = nodes.select {|n| n.parents.include?(self) } unless root? find(type, name, nodes, &block) end |
#dummy? ⇒ Boolean
29 30 31 |
# File 'lib/qor_dsl/node.rb', line 29 def dummy? dummy end |
#find(type = nil, name = nil, nodes = children, &block) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/qor_dsl/node.rb', line 94 def find(type=nil, name=nil, nodes=children, &block) results = nodes.select do |child| child.is_node?(type, name) && (block.nil? ? true : block.call(child)) end results = parent.find(type, name, &block) if results.length == 0 && (type)[:inherit] results = process_find_results(results, type) return results[0] if !name.nil? && results.is_a?(Array) && results.length == 1 results end |
#first(type = nil, name = nil, &block) ⇒ Object
107 108 109 110 |
# File 'lib/qor_dsl/node.rb', line 107 def first(type=nil, name=nil, &block) selected_children = find(type, name, &block) selected_children.is_a?(Array) ? selected_children[0] : selected_children end |
#inspect_name ⇒ Object
Inspect
113 114 115 |
# File 'lib/qor_dsl/node.rb', line 113 def inspect_name "{#{config_name}: #{name || 'nil'}}" end |
#is_node?(cname = nil, sname = nil) ⇒ Boolean
33 34 35 |
# File 'lib/qor_dsl/node.rb', line 33 def is_node?(cname=nil, sname=nil) (cname.nil? || (config_name.to_s == cname.to_s)) && (sname.nil? || (name.to_s == sname.to_s)) end |
#node(type, options = {}, &blk) ⇒ Object
71 72 73 |
# File 'lib/qor_dsl/node.rb', line 71 def node(type, ={}, &blk) config.node(type, , &blk) end |
#parents ⇒ Object
45 46 47 |
# File 'lib/qor_dsl/node.rb', line 45 def parents parent ? [parent, parent.parents].flatten : [] end |
#root ⇒ Object
41 42 43 |
# File 'lib/qor_dsl/node.rb', line 41 def root parent ? parent.root : self end |
#to_s ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/qor_dsl/node.rb', line 117 def to_s = { 'name' => name, 'parent' => parent && parent.inspect_name, 'config' => config_name, 'children' => children.map(&:inspect_name), 'data' => data, 'block' => block } Qor::Dsl.inspect_object(self, ) end |
#value ⇒ Object
57 58 59 60 |
# File 'lib/qor_dsl/node.rb', line 57 def value ((config.__children.size > 0 || block.nil?) ? ([:value] || name) : block.call) || (dummy? ? [:default_value] : nil) end |