Permalink
Browse files

Merge pull request #1 from threedaymonk/master

Allow recursive dependencies
  • Loading branch information...
2 parents 49b9d2e + 985d70d commit e26828fbc3e8708b19553d8255c20b6643b6b264 @JordanHatch committed Apr 16, 2012
Showing with 24 additions and 7 deletions.
  1. +7 −6 lib/bowler/dependency_tree.rb
  2. +12 −0 spec/dependency_tree_spec.rb
  3. +1 −0 spec/dsl_spec.rb
  4. +4 −1 spec/fixtures/dependency_tree_pinfile
@@ -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
@@ -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,4 +1,5 @@
require 'bowler'
+require_relative 'helpers/definition_helper'
module Bowler
@@ -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

0 comments on commit e26828f

Please sign in to comment.