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)
129 130 131 |
# File 'lib/code_node/ir/node.rb', line 129 def style @style end |
Instance Method Details
#contains(other) ⇒ nil
Add other as a child of this node
141 142 143 144 145 146 |
# File 'lib/code_node/ir/node.rb', line 141 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
171 172 173 174 175 176 |
# File 'lib/code_node/ir/node.rb', line 171 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.
133 134 135 136 |
# File 'lib/code_node/ir/node.rb', line 133 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
161 162 163 164 165 166 |
# File 'lib/code_node/ir/node.rb', line 161 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
151 152 153 154 155 156 |
# File 'lib/code_node/ir/node.rb', line 151 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
180 181 182 183 |
# File 'lib/code_node/ir/node.rb', line 180 def mark_as_singleton throw :NodeNotAModule unless module? @singleton = true end |
#prune ⇒ Object
Remove any relations involving this node
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 212 |
# File 'lib/code_node/ir/node.rb', line 186 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 |