Module: CodeNode::IR::Node::BuilderMethods
- Included in:
- CodeNode::IR::Node
- Defined in:
- lib/code_node/ir/node/builder_methods.rb
Overview
CodeNode::IR::Node methods used during the graph building phase
Instance Attribute Summary collapse
- #style ⇒ Object readonly
Instance Method Summary collapse
-
#add_edge(rel, other) ⇒ nil
Add an edge between this node and another with the given relation type.
-
#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)
9 10 11 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 9 def style @style end |
Instance Method Details
#add_edge(rel, other) ⇒ nil
Add an edge between this node and another with the given relation type
50 51 52 53 54 55 56 57 58 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 50 def add_edge(rel, other) this = self inv = @inverse_relation[rel] @edge[rel][other.path] = other other.instance_eval do @edge[inv][this.path] = this end nil end |
#contains(other) ⇒ nil
Add other as a child of this node
21 22 23 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 21 def contains(other) add_edge :children, other end |
#extends(other) ⇒ nil
Add other to this nodes extends set
42 43 44 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 42 def extends(other) add_edge :extends, other end |
#find(name) ⇒ Node?
Find a node contained in this node, or contained in this nodes TemplateMethods#parent, recursively.
13 14 15 16 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 13 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
35 36 37 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 35 def includes(other) add_edge :includes, other end |
#inherits_from(other) ⇒ nil
Add other as the super class of this node
28 29 30 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 28 def inherits_from(other) add_edge :inherits_from, other end |
#mark_as_singleton ⇒ nil
Mark this module node as a singleton
62 63 64 65 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 62 def mark_as_singleton throw :NodeNotAModule unless module? @singleton = true end |
#prune ⇒ Object
Remove any relations involving this node
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/code_node/ir/node/builder_methods.rb', line 68 def prune this = self @edge.each_pair do |rel, edges| inv = @inverse_relation[rel] edges.each_value do |other| other.instance_eval do @edge[inv].delete this.path end end end end |