Module: CodeNode::IR::Node::TemplateMethods

Included in:
CodeNode::IR::Node
Defined in:
lib/code_node/ir/node/template_methods.rb

Overview

Node methods which are useful in templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString (readonly)

Returns the name of the node. Not necessarilly unique.

Returns:

  • (String)

    the name of the node. Not necessarilly unique.

See Also:

  • CodeNode::IR::Node::TemplateMethods.{{#path}


10
11
12
# File 'lib/code_node/ir/node/template_methods.rb', line 10

def name
  @name
end

Instance Method Details

#childrenHash<String,Node>

The child nodes of this node

Examples:

module Foo     # Foo has children
  module Bar   # Bar
  end          # and
  class Car    # Car
  end
end

Returns:



31
32
33
# File 'lib/code_node/ir/node/template_methods.rb', line 31

def children
  @edge[:children]
end

#extensionsArray<Node>

Returns module nodes for which this node has an extend statement.

Returns:

  • (Array<Node>)

    module nodes for which this node has an extend statement



46
47
48
# File 'lib/code_node/ir/node/template_methods.rb', line 46

def extensions
  @edge[:extends].values.sort
end

#inclusionsArray<Node>

Returns module nodes for which this node has an include statement.

Returns:

  • (Array<Node>)

    module nodes for which this node has an include statement



41
42
43
# File 'lib/code_node/ir/node/template_methods.rb', line 41

def inclusions
  @edge[:includes].values.sort
end

#keyString

Returns fully qualified identifier for the node in the form Foo_Bar_Car. Ideal for graphviz identifiers.

Returns:

  • (String)

    fully qualified identifier for the node in the form Foo_Bar_Car. Ideal for graphviz identifiers.



51
52
53
# File 'lib/code_node/ir/node/template_methods.rb', line 51

def key
  @path.join '_'
end

#labelString

Returns how the node will be labelled in the graph. Nodes without parents display their full QueryMethods#path, while nodes with parents only display their #name.

Returns:

  • (String)

    how the node will be labelled in the graph. Nodes without parents display their full QueryMethods#path, while nodes with parents only display their #name.



56
57
58
# File 'lib/code_node/ir/node/template_methods.rb', line 56

def label
  parent.nil? ? path : name
end

#parentNode

Returns node which contains this node.

Examples:

module Foo     # Foo is the parent
  module Bar   # to Bar
  end
end

Returns:

  • (Node)

    node which contains this node



18
19
20
# File 'lib/code_node/ir/node/template_methods.rb', line 18

def parent
  @edge[:parent].values.first
end

#stamp_stylesString

Stamp the accumulated GraphViz styles in a format suitable for inclusion in a .dot file

Returns:

  • (String)

    style in the form key1="value1" key2="value2"



62
63
64
65
66
67
68
# File 'lib/code_node/ir/node/template_methods.rb', line 62

def stamp_styles
  x = []
  style.each_pair do |key, value|
    x << "#{key}=\"#{value}\""
  end
  x.join ' '
end

#super_class_nodeNode?

Returns the super class of this class. Will be nil for modules.

Returns:

  • (Node, nil)

    the super class of this class. Will be nil for modules.



36
37
38
# File 'lib/code_node/ir/node/template_methods.rb', line 36

def super_class_node
  @edge[:inherits_from].values.first
end