Class: Omgcnb::ResolveDependencies
- Inherits:
-
Object
- Object
- Omgcnb::ResolveDependencies
- Defined in:
- lib/omgcnb/resolve_dependencies.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(buildpacks) ⇒ ResolveDependencies
constructor
A new instance of ResolveDependencies.
- #solution ⇒ Object
Constructor Details
#initialize(buildpacks) ⇒ ResolveDependencies
Returns a new instance of ResolveDependencies.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/omgcnb/resolve_dependencies.rb', line 5 def initialize(buildpacks) @order = [] @unsolved = buildpacks.select(&:needs_release?) @solved = buildpacks - @unsolved @buildpacks = buildpacks given_buildpacks = buildpacks.flat_map {|b| b.name } @buildpacks.each do |buildpack| depends_diff = buildpack.depends_on - given_buildpacks raise "Cannot satisfy '#{buildpack.name}' missing: #{depends_diff}" unless depends_diff.empty? end end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/omgcnb/resolve_dependencies.rb', line 18 def call while @unsolved.any? found = @unsolved.select { |buildpack| (buildpack.depends_on - @solved.map(&:name)).empty? } @order.concat(found) @solved.concat(found) @unsolved -=found end end |
#solution ⇒ Object
29 30 31 32 |
# File 'lib/omgcnb/resolve_dependencies.rb', line 29 def solution call @order end |