Module: CodeNode::IR::Node::BuilderMethods
- Included in:
- CodeNode::IR::Node
- Defined in:
- lib/code_node/ir/node.rb
Overview
CodeNode::IR::Node methods used during the graph building phase
Instance Attribute Summary collapse
- #style ⇒ Object readonly
Instance Method Summary collapse
-
#contains(other) ⇒ nil
Add other as a child of this node.
-
#extends(other) ⇒ nil
Add other to this nodes extends set.
-
#find(name) ⇒ Node?
Find a node contained in this node, or contained in this nodes TemplateMethods#parent, recursively.
-
#includes(other) ⇒ nil
Add other to this nodes includes set.
-
#inherits_from(other) ⇒ nil
Add other as the super class of this node.
-
#mark_as_singleton ⇒ nil
Mark this module node as a singleton.
-
#prune ⇒ Object
Remove any relations involving this node.
Instance Attribute Details
#style ⇒ Object (readonly)
128 129 130 |
# File 'lib/code_node/ir/node.rb', line 128 def style @style end |
Instance Method Details
#contains(other) ⇒ nil
Add other as a child of this node
140 141 142 143 144 145 |
# File 'lib/code_node/ir/node.rb', line 140 def contains(other) this = self @children[other.path] = other other.instance_eval {@parent = this} nil end |
#extends(other) ⇒ nil
Add other to this nodes extends set
170 171 172 173 174 175 |
# File 'lib/code_node/ir/node.rb', line 170 def extends(other) this = self @extends[other.path] = other other.instance_eval {@extended_by[this.path] = this} nil end |
#find(name) ⇒ Node?
Find a node contained in this node, or contained in this nodes TemplateMethods#parent, recursively.
132 133 134 135 |
# File 'lib/code_node/ir/node.rb', line 132 def find(name) path = (@path + [name].flatten).join '::' @children[path] || (@parent && @parent.find(name)) end |
#includes(other) ⇒ nil
Add other to this nodes includes set
160 161 162 163 164 165 |
# File 'lib/code_node/ir/node.rb', line 160 def includes(other) this = self @includes[other.path] = other other.instance_eval {@included_by[this.path] = this} nil end |
#inherits_from(other) ⇒ nil
Add other as the super class of this node
150 151 152 153 154 155 |
# File 'lib/code_node/ir/node.rb', line 150 def inherits_from(other) this = self @inherits_from = other other.instance_eval {@inherited_by[this.path] = this} nil end |
#mark_as_singleton ⇒ nil
Mark this module node as a singleton
179 180 181 182 |
# File 'lib/code_node/ir/node.rb', line 179 def mark_as_singleton throw :NodeNotAModule unless module? @singleton = true end |
#prune ⇒ Object
Remove any relations involving this node
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/code_node/ir/node.rb', line 185 def prune this = self if @inherits_from @inherits_from.instance_eval {@inherited_by.delete this.path} end @inherited_by.each_value do |other| other.instance_eval {@inherits_from = nil} end if @parent @parent.instance_eval {@children.delete this.path} end @children.each_value do |other| other.instance_eval {@parent = nil} end @includes.each_value do |other| other.instance_eval {@included_by.delete this.path} end @included_by.each_value do |other| other.instance_eval {@includes.delete this.path} end @extends.each_value do |other| other.instance_eval {@extended_by.delete this.path} end @extended_by.each_value do |other| other.instance_eval {@extends.delete this.path} end end |