Class: MultiRepo::Node
- Inherits:
-
Object
- Object
- MultiRepo::Node
- Defined in:
- lib/multirepo/logic/node.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children ⇒ Object
- #ensure_no_dependency_cycle(node) ⇒ Object
- #find_descendants_recursive(node) ⇒ Object
-
#initialize(path, parent = nil, depth = 0) ⇒ Node
constructor
A new instance of Node.
- #name ⇒ Object
- #ordered_descendants ⇒ Object
- #ordered_descendants_including_self ⇒ Object
Constructor Details
#initialize(path, parent = nil, depth = 0) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 |
# File 'lib/multirepo/logic/node.rb', line 10 def initialize(path, parent = nil, depth = 0) @path = path @depth = depth @parent = parent end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
7 8 9 |
# File 'lib/multirepo/logic/node.rb', line 7 def depth @depth end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/multirepo/logic/node.rb', line 8 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/multirepo/logic/node.rb', line 6 def path @path end |
Instance Method Details
#==(other) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/multirepo/logic/node.rb', line 68 def ==(other) other.class == self.class && otherPath = Utils.standard_path(other.path) thisPath = Utils.standard_path(@path) otherPath.casecmp(thisPath) == 0 end |
#children ⇒ Object
20 21 22 23 24 |
# File 'lib/multirepo/logic/node.rb', line 20 def children return [] unless Utils.multirepo_enabled?(@path) config_entries = ConfigFile.new(@path).load_entries return config_entries.map { |e| Node.new(e.path, self, @depth + 1) } end |
#ensure_no_dependency_cycle(node) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/multirepo/logic/node.rb', line 50 def ensure_no_dependency_cycle(node) parent = node.parent visited = [] while parent visited.push(parent) if parent == node Console.log_warning("Dependency cycle detected:") visited.reverse.each_with_index do |n, i| description = "[first]" if i == visited.count - 1 description = "itself" if visited.count == 1 Console.log_warning("'#{n.path}' depends on #{description}") end fail MultiRepoException, "Dependency cycles are not supported by multirepo." end parent = parent.parent # Will eventually be nil (root node), which will break out of the loop end end |
#find_descendants_recursive(node) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/multirepo/logic/node.rb', line 42 def find_descendants_recursive(node) ensure_no_dependency_cycle(node) descendants = node.children descendants.each { |d| descendants.push(*find_descendants_recursive(d)) } return descendants end |
#name ⇒ Object
16 17 18 |
# File 'lib/multirepo/logic/node.rb', line 16 def name Pathname.new(File.(@path)).basename.to_s end |
#ordered_descendants ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/multirepo/logic/node.rb', line 30 def ordered_descendants descendants = find_descendants_recursive(self) unique_paths = descendants.map(&:path).uniq unique_nodes = unique_paths.collect do |path| nodes_for_path = descendants.select { |d| d.path == path } next nodes_for_path.sort_by(&:depth).first end return unique_nodes.sort_by(&:depth).reverse end |
#ordered_descendants_including_self ⇒ Object
26 27 28 |
# File 'lib/multirepo/logic/node.rb', line 26 def ordered_descendants_including_self return ordered_descendants.push(self) end |