Class: Fathom::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/fathom/node.rb
Overview
Spira.add_repository(:default, @repository)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Node
Returns a new instance of Node.
14
15
16
17
18
19
20
21
|
# File 'lib/fathom/node.rb', line 14
def initialize(opts={})
symbolize_keys!(opts)
@name = opts[:name]
assert_distribution(opts)
@description = opts[:description]
@values = opts[:values]
assert_links(opts)
end
|
Instance Attribute Details
#description ⇒ Object
See notes in the spec about this. include Spira::Resource
12
13
14
|
# File 'lib/fathom/node.rb', line 12
def description
@description
end
|
#distribution ⇒ Object
See notes in the spec about this. include Spira::Resource
12
13
14
|
# File 'lib/fathom/node.rb', line 12
def distribution
@distribution
end
|
#name ⇒ Object
See notes in the spec about this. include Spira::Resource
12
13
14
|
# File 'lib/fathom/node.rb', line 12
def name
@name
end
|
#values ⇒ Object
See notes in the spec about this. include Spira::Resource
12
13
14
|
# File 'lib/fathom/node.rb', line 12
def values
@values
end
|
Instance Method Details
#add_child(child) ⇒ Object
52
53
54
55
56
|
# File 'lib/fathom/node.rb', line 52
def add_child(child)
self.children << child
self.add_accessor_for_node(child)
child.register_parent(self)
end
|
#add_parent(parent) ⇒ Object
32
33
34
35
36
|
# File 'lib/fathom/node.rb', line 32
def add_parent(parent)
self.parents << parent
self.add_accessor_for_node(parent)
parent.register_child(self)
end
|
#children ⇒ Object
48
49
50
|
# File 'lib/fathom/node.rb', line 48
def children
@children ||= []
end
|
#inspect ⇒ Object
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/fathom/node.rb', line 72
def inspect
"#{self.class.to_s}: " + [
self.name,
self.description,
"children:",
self.children.map {|e| e.simple_inspect }.inspect,
"parents: ",
self.parents.map {|e| e.simple_inspect }.inspect,
].compact.join(", ")
end
|
#name_sym ⇒ Object
23
24
25
26
|
# File 'lib/fathom/node.rb', line 23
def name_sym
return nil unless self.name
@name_sym ||= self.name.to_s.downcase.gsub(/\s+|-+/, '_').to_sym
end
|
#parents ⇒ Object
28
29
30
|
# File 'lib/fathom/node.rb', line 28
def parents
@parents ||= []
end
|
#register_child(child) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/fathom/node.rb', line 38
def register_child(child)
raise "Cannot register a child if this node is not a parent already. Use add_parent to the other node or add_child to this node." unless
child.parents.include?(self)
unless children.include?(child)
self.add_accessor_for_node(child)
children << child
end
true
end
|
#register_parent(parent) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/fathom/node.rb', line 58
def register_parent(parent)
raise "Cannot register a parent if this node is not a child already. Use add_child to the other node or add_parent to this node." unless
parent.children.include?(self)
unless parents.include?(parent)
self.add_accessor_for_node(parent)
parents << parent
end
true
end
|
#simple_inspect ⇒ Object
68
69
70
|
# File 'lib/fathom/node.rb', line 68
def simple_inspect
self.name ? "#{self.name} (#{self.class.to_s})" : self.class.to_s
end
|