Class: GemsSnapshot::YmlImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/gems_snapshot/importer/yml_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/gems_snapshot/importer/yml_importer.rb', line 8

def errors
  @errors
end

Instance Method Details

#import(filename) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gems_snapshot/importer/yml_importer.rb', line 10

def import(filename)
  yml_hash = YAML.load(File.read(filename))  #TODO: validate file content someday

  yml_hash['gems'].each do |hash_gem|
    gem_name = hash_gem['name']
    hash_gem['versions'].each do |version|

      if Gem.available? gem_name, version
        puts "#{gem_name}-#{version} already available!"
        next
      end

      gem_name = check_for_cache(gem_name, version)

      puts "Going to install #{gem_name} -v#{version} ... wish me luck!"
      begin
        gem_install(gem_name, version)
      rescue Gem::InstallError => e
        errors << "Error installing #{gem_name}:\n\t#{e.message}"
      rescue Gem::GemNotFoundException => e
        errors << "Gem not found #{e.message}"
      end

    end
  end
end