Class: CodeNode::IR::Node

Inherits:
Object
  • Object
show all
Includes:
BuilderMethods, QueryMethods, TemplateMethods, Cog::Generator
Defined in:
lib/code_node/ir/node.rb,
lib/code_node/ir/node/query_methods.rb,
lib/code_node/ir/node/builder_methods.rb,
lib/code_node/ir/node/template_methods.rb

Overview

A node in the Graph Nodes come in two flavors: QueryMethods#class? and QueryMethods#module? nodes

Defined Under Namespace

Modules: BuilderMethods, QueryMethods, TemplateMethods

Instance Attribute Summary

Attributes included from TemplateMethods

#name

Attributes included from BuilderMethods

#style

Instance Method Summary collapse

Methods included from QueryMethods

#class?, #extends?, #includes?, #inherits_from?, #island?, #module?, #path, #singleton?

Methods included from TemplateMethods

#children, #extensions, #inclusions, #key, #label, #parent, #stamp_styles, #super_class_node

Methods included from BuilderMethods

#add_edge, #contains, #extends, #find, #includes, #inherits_from, #mark_as_singleton, #prune

Constructor Details

#initialize(name, opt = {}) ⇒ Node

Initialize a node

Parameters:

  • name (String, Array)
  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :parent (Node) — default: nil

    if provided, the parent’s path is prepended to name. The parent child is not made at this time though. See CodeNode::IR::Node::BuilderMethods#contains instead.

  • :node_type (Symbol) — default: :module

    either :module or :class



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/code_node/ir/node.rb', line 23

def initialize(name, opt={})
  @style = {}
  @node_type = opt[:node_type] || :module
  parent_path = opt[:parent] ? opt[:parent].instance_eval {@path} : []
  @path = if name.is_a? Array
    parent_path + name
  else
    parent_path + [name]
  end
  @name = @path.last
  @inverse_relation = {} # :rel => :inv_rel
  @edge = {} # :rel => { 'node::path' =>  }
  define_relation :parent, :children
  define_relation :inherits_from, :inherited_by
  define_relation :includes, :included_by
  define_relation :extends, :extended_by
end

Instance Method Details

#<=>(other) ⇒ FixNum

Returns order nodes by CodeNode::IR::Node::QueryMethods#path.

Returns:



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

def <=>(other)
  path <=> other.path
end

#define_relation(rel, inv) ⇒ Object

Parameters:

  • rel (Symbol)

    the name of a relation

  • inv (Symbol)

    the name of the inverse relation



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

def define_relation(rel, inv)
  @inverse_relation[rel] = inv
  @inverse_relation[inv] = rel
  @edge[rel] = {}
  @edge[inv] = {}
end