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

Instance Method Summary collapse

Instance Attribute Details

#styleObject (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

Parameters:

  • rel (Symbol)

    the type of relation

  • other (Node)

    another node

Returns:

  • (nil)


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

Parameters:

  • other (Node)

    another node

Returns:

  • (nil)


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

Parameters:

  • other (Node)

    another node

Returns:

  • (nil)


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.

Returns:



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

Parameters:

  • other (Node)

    another node

Returns:

  • (nil)


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

Parameters:

  • other (Node)

    another node

Returns:

  • (nil)


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_singletonnil

Mark this module node as a singleton

Returns:

  • (nil)


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

#pruneObject

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