Class: DuckPuncher::GemInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_puncher/gem_installer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initialize!Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/duck_puncher/gem_installer.rb', line 2

def self.initialize!
  spec_data = DuckPuncher::JSONStorage.read('load_paths.json').values
  spec_data.each do |spec|
    spec[:load_paths].each do |load_path|
      next if $LOAD_PATH.include? load_path
      $LOAD_PATH.unshift load_path
    end
    begin
      require spec[:require_with]
    rescue LoadError => e
      DuckPuncher.logger.error "Failed to load #{spec[:require_with]} from .duck_puncher/ #{e.inspect}"
    end
  end
end

Instance Method Details

#perform(*args) ⇒ Object

Parameters:

  • name (String)

    of the gem

  • version (String)

    of the gem to install (e.g. ‘1.2.3’)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/duck_puncher/gem_installer.rb', line 19

def perform(*args)
  require 'rubygems/dependency_installer'
  installer = Gem::DependencyInstaller.new(install_dir: Bundler.bundle_path.to_s, bin_dir: RbConfig::CONFIG['bindir'])
  installer.install *args.reject(&:empty?)
  installer.installed_gems.each do |gem|
    full_load_path = Bundler.bundle_path.join('gems', "#{gem.name}-#{gem.version}", "lib")
    next if $LOAD_PATH.include?(full_load_path.to_s)
    $LOAD_PATH.unshift full_load_path.to_s
    DuckPuncher::JSONStorage.write 'load_paths.json', args.first, full_load_path
  end
  installer.installed_gems.any?
rescue => e
  DuckPuncher.logger.error "Failed to install #{args.first}. #{e.inspect}"
end