Class: Capricorn::Satellite::DependencyLoader
- Inherits:
-
Object
- Object
- Capricorn::Satellite::DependencyLoader
- Includes:
- TSort
- Defined in:
- lib/capricorn/satellite/dependency_loader.rb
Instance Attribute Summary collapse
-
#engines ⇒ Object
readonly
Returns the value of attribute engines.
-
#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(engines) ⇒ DependencyLoader
constructor
A new instance of DependencyLoader.
- #order_by_dependecies! ⇒ Object
- #reverse_each ⇒ Object
Constructor Details
#initialize(engines) ⇒ DependencyLoader
Returns a new instance of DependencyLoader.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 17 def initialize(engines) specs = engines.collect do |k,r| s = Gem.source_index.find_name(k, Gem::Requirement.new(r[:version] || ">= 0.0.0")) s.last end.compact @names = specs.collect { |spec| spec.name } @specs = specs.inject({}) { |h, spec| h[spec.name] = spec ; h } @engines = engines end |
Instance Attribute Details
#engines ⇒ Object (readonly)
Returns the value of attribute engines.
7 8 9 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 7 def engines @engines end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
7 8 9 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 7 def names @names end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
7 8 9 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 7 def specs @specs end |
Class Method Details
.load_for(engines) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 9 def self.load_for(engines) dependency_loader = self.new(engines) dependency_loader.add_dependecies! dependency_loader.order_by_dependecies! return dependency_loader end |
Instance Method Details
#add_dependecies! ⇒ Object
28 29 30 31 32 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 28 def add_dependecies! @specs.values.each do |spec| add_dependecies_for spec end end |
#each ⇒ Object
38 39 40 41 42 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 38 def each @names.each do |name| yield(@specs[name]) end end |
#order_by_dependecies! ⇒ Object
34 35 36 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 34 def order_by_dependecies! @names = tsort end |
#reverse_each ⇒ Object
44 45 46 47 48 |
# File 'lib/capricorn/satellite/dependency_loader.rb', line 44 def reverse_each @names.reverse.each do |name| yield(@specs[name]) end end |