Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow recursive dependencies #1

Merged
merged 5 commits into from

2 participants

This page is out of date. Refresh to see the latest.
View
13 lib/bowler/dependency_tree.rb
@@ -13,18 +13,19 @@ def initialize(definition)
@definition = definition
end
- def dependencies_for(processes)
- processes.inject([]) do |array, p|
- array += [ (@definition.tree[p] || []), p ].flatten
- end.uniq
+ def dependencies_for(processes, visited = [])
+ return [] unless processes
+ (processes - visited).map { |p|
+ [dependencies_for(@definition.tree[p], visited + [p]), p]
+ }.flatten.compact.uniq
end
def process_list_for(processes)
on = dependencies_for(processes)
- off = @definition.processes.reject {|i| on.include? i }
+ off = @definition.processes - on
[ on.map {|x| "#{x}=1" }, off.map {|x| "#{x}=0" } ].flatten.sort.join(',')
end
end
-end
+end
View
12 spec/dependency_tree_spec.rb
@@ -15,6 +15,18 @@ module Bowler
tree.dependencies_for([:foo]).should =~ [:bar, :foo, :required]
tree.dependencies_for([:nyan]).should =~ [:bar, :foo, :nyan, :required]
end
+
+ it "should find the dependencies of dependencies" do
+ tree = DependencyTree.load File.join( File.dirname(__FILE__), 'fixtures', 'dependency_tree_pinfile' )
+
+ tree.dependencies_for([:cat]).should =~ [:cat, :nyan, :bar, :foo, :required]
+ end
+
+ it "should correctly handle recursive dependencies" do
+ tree = DependencyTree.load File.join( File.dirname(__FILE__), 'fixtures', 'dependency_tree_pinfile' )
+
+ tree.dependencies_for([:loop1]).should =~ [:loop1, :loop2, :required]
+ end
end
context "given an array of one process" do
View
1  spec/dsl_spec.rb
@@ -1,4 +1,5 @@
require 'bowler'
+require_relative 'helpers/definition_helper'
module Bowler
View
5 spec/fixtures/dependency_tree_pinfile
@@ -2,4 +2,7 @@ dependency :required
process :foo => :bar
process :nyan => [:foo, :bar]
-process :rick
+process :cat => :nyan
+process :loop1 => :loop2
+process :loop2 => :loop1
+process :rick
Something went wrong with that request. Please try again.