Module: CodeNode::IR::Graph::TemplateMethods

Included in:
CodeNode::IR::Graph
Defined in:
lib/code_node/ir/graph.rb

Overview

CodeNode::IR::Graph methods which are useful in templates

Instance Method Summary collapse

Instance Method Details

#each_class {|node| ... } ⇒ nil

Iterate through each Node with Node::QueryMethods#class? in the graph

Yield Parameters:

Returns:



15
16
17
18
19
# File 'lib/code_node/ir/graph.rb', line 15

def each_class(&block)
  @nodes.values.select do |node|
    node.class?
  end.sort.each &block
end

#each_containment {|a, b| ... } ⇒ nil

Iterate through each containment relation in the graph

Examples:

# a -> b (A contains B)
module A
  module B
  end
end

Yield Parameters:

Returns:



40
41
42
43
44
45
46
# File 'lib/code_node/ir/graph.rb', line 40

def each_containment(&block)
  @nodes.values.sort.each do |node|
    if node.parent
      block.call node.parent, node
    end
  end
end

#each_extension {|a, b| ... } ⇒ nil

Iterate through each extension relation in the graph

Examples:

# a -> b (A extends B)
module A
  extend B
end

Yield Parameters:

Returns:



90
91
92
93
94
95
96
# File 'lib/code_node/ir/graph.rb', line 90

def each_extension(&block)
  @nodes.values.sort.each do |node|
    node.extensions.each do |other|
      block.call node, other
    end
  end
end

#each_inclusion {|a, b| ... } ⇒ nil

Iterate through each inclusion relation in the graph

Examples:

# a -> b (A includes B)
module A
  include B
end

Yield Parameters:

Returns:



73
74
75
76
77
78
79
# File 'lib/code_node/ir/graph.rb', line 73

def each_inclusion(&block)
  @nodes.values.sort.each do |node|
    node.inclusions.each do |other|
      block.call node, other
    end
  end
end

#each_inheritance {|a, b| ... } ⇒ nil

Iterate through each inheritance relation in the graph

Examples:

# a -> b (A inherits from B)
class A < B
end

Yield Parameters:

Returns:



56
57
58
59
60
61
62
# File 'lib/code_node/ir/graph.rb', line 56

def each_inheritance(&block)
  @nodes.values.sort.each do |node|
    if node.super_class_node
      block.call node, node.super_class_node
    end
  end
end

#each_module {|node| ... } ⇒ nil

Iterate through each Node with Node::QueryMethods#module? in the graph

Yield Parameters:

Returns:



24
25
26
27
28
# File 'lib/code_node/ir/graph.rb', line 24

def each_module(&block)
  @nodes.values.select do |node|
    node.module?
  end.sort.each &block
end