Class: CodeNode::IR::Node

Inherits:
Object
  • Object
show all
Includes:
BuilderMethods, QueryMethods, TemplateMethods, Cog::Generator
Defined in:
lib/code_node/ir/node.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

#children, #name, #parent

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

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

Methods included from BuilderMethods

#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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/code_node/ir/node.rb', line 224

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
  @parent = nil
  @children = {}
  @inherits_from = nil
  @inherited_by = {}
  @includes = {}
  @included_by = {}
  @extends = {}
  @extended_by = {}
end

Instance Method Details

#<=>(other) ⇒ FixNum

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

Returns:



245
246
247
# File 'lib/code_node/ir/node.rb', line 245

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