Class: Milkshake::DependencyResolver
- Inherits:
-
Object
- Object
- Milkshake::DependencyResolver
- Includes:
- TSort
- Defined in:
- lib/milkshake/dependency_resolver.rb
Instance Attribute Summary collapse
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Class Method Summary collapse
Instance Method Summary collapse
- #add_dependecies! ⇒ Object
- #each ⇒ Object
-
#initialize(gems) ⇒ DependencyResolver
constructor
A new instance of DependencyResolver.
- #order_by_dependecies! ⇒ Object
- #reverse_each ⇒ Object
Constructor Details
#initialize(gems) ⇒ DependencyResolver
Returns a new instance of DependencyResolver.
16 17 18 19 20 21 22 23 24 |
# File 'lib/milkshake/dependency_resolver.rb', line 16 def initialize(gems) specs = gems.collect do |name,| find_gemspec(name,) end.compact @names = specs.collect { |spec| spec.name } @specs = specs.inject({}) { |memo, spec| memo[spec.name] = spec ; memo } @gems = gems end |
Instance Attribute Details
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
7 8 9 |
# File 'lib/milkshake/dependency_resolver.rb', line 7 def gems @gems end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
7 8 9 |
# File 'lib/milkshake/dependency_resolver.rb', line 7 def names @names end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
7 8 9 |
# File 'lib/milkshake/dependency_resolver.rb', line 7 def specs @specs end |
Class Method Details
.load_for(gems) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/milkshake/dependency_resolver.rb', line 9 def self.load_for(gems) dependency_loader = self.new(gems) dependency_loader.add_dependecies! dependency_loader.order_by_dependecies! return dependency_loader end |
Instance Method Details
#add_dependecies! ⇒ Object
26 27 28 29 30 |
# File 'lib/milkshake/dependency_resolver.rb', line 26 def add_dependecies! @specs.values.each do |spec| add_dependecies_for spec end end |
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/milkshake/dependency_resolver.rb', line 36 def each @names.each do |name| yield(@specs[name]) end end |
#order_by_dependecies! ⇒ Object
32 33 34 |
# File 'lib/milkshake/dependency_resolver.rb', line 32 def order_by_dependecies! @names = tsort end |
#reverse_each ⇒ Object
42 43 44 45 46 |
# File 'lib/milkshake/dependency_resolver.rb', line 42 def reverse_each @names.reverse.each do |name| yield(@specs[name]) end end |