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.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #add_config(config) ⇒ Object
-
#config_name ⇒ Object
Node Config.
- #config_options ⇒ Object
- #deep_find(type = nil, name = nil, &block) ⇒ Object
- #default_block ⇒ Object
- #default_options ⇒ Object
-
#default_value ⇒ Object
Node Data.
- #dummy? ⇒ Boolean
- #find(type = nil, name = nil, nodes = children, &block) ⇒ Object
-
#first(type = nil, name = nil, &block) ⇒ Object
Query.
-
#initialize(name = nil, options = {}) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #is_node?(node_type = nil, name_str = nil) ⇒ Boolean
- #node(type, options = {}, &blk) ⇒ Object
- #options ⇒ Object
-
#parents ⇒ Object
Node.
- #root ⇒ Object
- #root? ⇒ Boolean
- #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 |
#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
21 22 23 24 25 26 |
# File 'lib/qor_dsl/node.rb', line 21 def add_child(child) child.parent = self children << child root.all_nodes ||= [] root.all_nodes << child end |
#add_config(config) ⇒ Object
16 17 18 19 |
# File 'lib/qor_dsl/node.rb', line 16 def add_config(config) self.config = config config.__node = self end |
#config_name ⇒ Object
Node Config
30 31 32 |
# File 'lib/qor_dsl/node.rb', line 30 def config_name config.__name end |
#config_options ⇒ Object
34 35 36 |
# File 'lib/qor_dsl/node.rb', line 34 def config. || {} rescue {} end |
#deep_find(type = nil, name = nil, &block) ⇒ Object
101 102 103 104 105 |
# File 'lib/qor_dsl/node.rb', line 101 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 |
#default_block ⇒ Object
86 87 88 |
# File 'lib/qor_dsl/node.rb', line 86 def default_block [:default_block] end |
#default_options ⇒ Object
76 77 78 |
# File 'lib/qor_dsl/node.rb', line 76 def [:default_options] end |
#default_value ⇒ Object
Node Data
68 69 70 |
# File 'lib/qor_dsl/node.rb', line 68 def default_value [:default_value] end |
#dummy? ⇒ Boolean
58 59 60 |
# File 'lib/qor_dsl/node.rb', line 58 def dummy? !!dummy end |
#find(type = nil, name = nil, nodes = children, &block) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/qor_dsl/node.rb', line 107 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] process_find_results(results, type) end |
#first(type = nil, name = nil, &block) ⇒ Object
Query
96 97 98 99 |
# File 'lib/qor_dsl/node.rb', line 96 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 ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/qor_dsl/node.rb', line 117 def inspect = { 'name' => name, 'config' => config_name, 'parent' => parent && parent.inspect_name, 'children' => children.map(&:inspect_name), 'data' => data, 'block' => block } Qor::Dsl.inspect_object(self, ) end |
#is_node?(node_type = nil, name_str = nil) ⇒ Boolean
62 63 64 |
# File 'lib/qor_dsl/node.rb', line 62 def is_node?(node_type=nil, name_str=nil) (node_type.nil? || (config_name.to_s == node_type.to_s)) && (name_str.nil? || (name.to_s == name_str.to_s)) end |
#node(type, options = {}, &blk) ⇒ Object
12 13 14 |
# File 'lib/qor_dsl/node.rb', line 12 def node(type, ={}, &blk) config.node(type, , &blk) end |
#options ⇒ Object
80 81 82 83 84 |
# File 'lib/qor_dsl/node.rb', line 80 def return data[-1] if data.is_a?(Array) && data[-1].is_a?(Hash) return name if name.is_a?(Hash) return || {} end |
#parents ⇒ Object
Node
40 41 42 |
# File 'lib/qor_dsl/node.rb', line 40 def parents parent ? [parent, parent.parents].flatten : [] end |
#root ⇒ Object
50 51 52 |
# File 'lib/qor_dsl/node.rb', line 50 def root parent ? parent.root : self end |
#value ⇒ Object
72 73 74 |
# File 'lib/qor_dsl/node.rb', line 72 def value ((config.__children.size > 0 || block.nil?) ? ([:value] || name) : block.call) || default_value end |