Class: Capricorn::Satellite::DependencyLoader

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/capricorn/satellite/dependency_loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#enginesObject (readonly)

Returns the value of attribute engines.



7
8
9
# File 'lib/capricorn/satellite/dependency_loader.rb', line 7

def engines
  @engines
end

#namesObject (readonly)

Returns the value of attribute names.



7
8
9
# File 'lib/capricorn/satellite/dependency_loader.rb', line 7

def names
  @names
end

#specsObject (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

#eachObject



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_eachObject



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