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

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

Overview

Node methods which are useful in templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenHash<String,Node> (readonly)

The child nodes of this node

Examples:

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

Returns:



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

def children
  @children
end

#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}


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

def name
  @name
end

#parentNode (readonly)

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



25
26
27
# File 'lib/code_node/ir/node.rb', line 25

def parent
  @parent
end

Instance Method Details

#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



49
50
51
# File 'lib/code_node/ir/node.rb', line 49

def extensions
  @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



44
45
46
# File 'lib/code_node/ir/node.rb', line 44

def inclusions
  @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.



54
55
56
# File 'lib/code_node/ir/node.rb', line 54

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.



59
60
61
# File 'lib/code_node/ir/node.rb', line 59

def label
  @parent.nil? ? path : name
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"



65
66
67
68
69
70
71
# File 'lib/code_node/ir/node.rb', line 65

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.



39
40
41
# File 'lib/code_node/ir/node.rb', line 39

def super_class_node
  @inherits_from
end