Class: Gfid::Manager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gfid/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



7
8
9
10
# File 'lib/gfid/manager.rb', line 7

def initialize
  @gems = []
  @dependency_gems = []
end

Instance Attribute Details

#dependency_gemsObject (readonly)

Returns the value of attribute dependency_gems.



6
7
8
# File 'lib/gfid/manager.rb', line 6

def dependency_gems
  @dependency_gems
end

#gemsObject (readonly)

Returns the value of attribute gems.



6
7
8
# File 'lib/gfid/manager.rb', line 6

def gems
  @gems
end

Instance Method Details

#clear!Object



40
41
42
43
# File 'lib/gfid/manager.rb', line 40

def clear!
  @gems = []
  @dependency_gems = []
end

#collect_gemsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gfid/manager.rb', line 18

def collect_gems
  while !dependency_gems.empty?
    next_dependency_gems = []
    dependency_gems.flatten.each do |gem|
      @gems << gem
      gem.ask_dependencies.each do |dependency_gem|
        next_dependency_gems << dependency_gem if !next_dependency_gems.map { |g| g.name }.include?(dependency_gem.name)
      end
    end
    @dependency_gems = next_dependency_gems
  end
  gems
end

#download!Object



32
33
34
35
36
37
38
# File 'lib/gfid/manager.rb', line 32

def download!
  collect_gems.each do |gem|
    open(gem.filename, "wb") do |file|
      file.write gem.download!.body
    end
  end
end

#gem_name(name, version = nil) ⇒ Object



12
13
14
15
16
# File 'lib/gfid/manager.rb', line 12

def gem_name(name, version=nil)
  @gems << Gem.new(name, :version => version)
  @dependency_gems << gems.first.ask_dependencies
  @dependency_gems.flatten!
end