Class: CodeNode::IR::Node
- Inherits:
-
Object
- Object
- CodeNode::IR::Node
- 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
Attributes included from BuilderMethods
Instance Method Summary collapse
-
#<=>(other) ⇒ FixNum
Order nodes by QueryMethods#path.
- #define_relation(rel, inv) ⇒ Object
-
#initialize(name, opt = {}) ⇒ Node
constructor
Initialize a node.
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
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.
51 52 53 |
# File 'lib/code_node/ir/node.rb', line 51 def <=>(other) path <=> other.path end |
#define_relation(rel, inv) ⇒ Object
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 |