Class: Gitgo::Repo::Node
- Inherits:
-
Object
- Object
- Gitgo::Repo::Node
- Defined in:
- lib/gitgo/repo/node.rb
Overview
Nodes are used to cache and provide access to positional information (parents, children, etc) for each node in a graph. Nodes are meant to be read-only objects and should not be modified.
Instance Attribute Summary collapse
-
#deleted ⇒ Object
True if self is deleted.
-
#nodes ⇒ Object
readonly
A back reference to the graph nodes this node belongs to.
-
#original ⇒ Object
Set to the sha for the original node this node updates, or the sha for self if self is an original node.
-
#sha ⇒ Object
readonly
The node sha.
Instance Method Summary collapse
-
#children ⇒ Object
Returns an array of deconvoluted children for self.
-
#current? ⇒ Boolean
True if self is a current version of a node (ie not deleted or updated).
-
#deconvolute(original = sha, links = nil, versions = []) ⇒ Object
Deconvolute is a utility method used by a graph to:.
-
#initialize(sha, nodes, links, updates) ⇒ Node
constructor
Initializes a new Node.
-
#inspect ⇒ Object
Returns a string like:.
-
#original? ⇒ Boolean
True if self is an original node.
-
#parents ⇒ Object
Returns an array of deconvoluted parent for self.
-
#tail? ⇒ Boolean
True if self is a tail (ie current and without children).
-
#versions ⇒ Object
Returns an array of current versions for self.
Constructor Details
#initialize(sha, nodes, links, updates) ⇒ Node
Initializes a new Node. The links and updates arrays represent raw linkage information before deconvolution and are not made available because they are changed in the course of deconvolution.
25 26 27 28 29 30 31 32 |
# File 'lib/gitgo/repo/node.rb', line 25 def initialize(sha, nodes, links, updates) @sha = sha @nodes = nodes @links = links @updates = updates @deleted = false @original = sha end |
Instance Attribute Details
#deleted ⇒ Object
True if self is deleted
16 17 18 |
# File 'lib/gitgo/repo/node.rb', line 16 def deleted @deleted end |
#nodes ⇒ Object (readonly)
A back reference to the graph nodes this node belongs to.
13 14 15 |
# File 'lib/gitgo/repo/node.rb', line 13 def nodes @nodes end |
#original ⇒ Object
Set to the sha for the original node this node updates, or the sha for self if self is an original node.
20 21 22 |
# File 'lib/gitgo/repo/node.rb', line 20 def original @original end |
#sha ⇒ Object (readonly)
The node sha
10 11 12 |
# File 'lib/gitgo/repo/node.rb', line 10 def sha @sha end |
Instance Method Details
#children ⇒ Object
Returns an array of deconvoluted children for self.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gitgo/repo/node.rb', line 66 def children @children ||= begin children = [] @links.each do |link| children.concat nodes[link.original].versions end if current? children end end |
#current? ⇒ Boolean
True if self is a current version of a node (ie not deleted or updated).
41 42 43 |
# File 'lib/gitgo/repo/node.rb', line 41 def current? !deleted && @updates.empty? end |
#deconvolute(original = sha, links = nil, versions = []) ⇒ Object
Deconvolute is a utility method used by a graph to:
-
aggregate links from previous versions to updates
-
determine the current versions for an original node
-
determine the original node for each update
This method is public so that it may be used from a Graph, but should not be called otherwise.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gitgo/repo/node.rb', line 91 def deconvolute(original=sha, links=nil, versions=[]) if original @original = original @links.concat(links) if links @versions = versions if original == sha end case when deleted # do not register deleted notes as current # so that they will fall out of the tree when @updates.empty? versions << sha else @updates.each do |update| update.deconvolute(original, @links, versions) end end versions end |
#inspect ⇒ Object
Returns a string like:
#<Gitgo::Repo::Node:object_id sha="sha">
117 118 119 |
# File 'lib/gitgo/repo/node.rb', line 117 def inspect "#<#{self.class}:#{object_id} sha=#{sha.inspect}>" end |
#original? ⇒ Boolean
True if self is an original node.
35 36 37 |
# File 'lib/gitgo/repo/node.rb', line 35 def original? original == sha end |
#parents ⇒ Object
Returns an array of deconvoluted parent for self.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitgo/repo/node.rb', line 51 def parents @parents ||= begin parents = [] nodes.each_value do |node| if node.current? && node.children.include?(sha) parents << node.sha end end if current? parents end end |
#tail? ⇒ Boolean
True if self is a tail (ie current and without children)
46 47 48 |
# File 'lib/gitgo/repo/node.rb', line 46 def tail? current? && @links.empty? end |
#versions ⇒ Object
Returns an array of current versions for self.
79 80 81 |
# File 'lib/gitgo/repo/node.rb', line 79 def versions @versions ||= deconvolute(nil) end |