Sha256: ed015ddee690e694e1191d47f959690b8a5ffe12544406c3c46b55d975bd4323

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

require 'rubygems/dependency_installer'

class DuckPuncher::GemInstaller
  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.log.error "Failed to load #{spec[:require_with]} from .duck_puncher/ #{e.inspect}"
      end
    end
  end

  # @param [String] name of the gem
  # @param [String] version of the gem to install (e.g. '1.2.3')
  def perform(*args)
    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.log.error "Failed to install #{args.first}. #{e.inspect}"
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
duck_puncher-4.1.0 lib/duck_puncher/gem_installer.rb
duck_puncher-4.0.0 lib/duck_puncher/gem_installer.rb
duck_puncher-3.0.0 lib/duck_puncher/gem_installer.rb
duck_puncher-2.16.0 lib/duck_puncher/gem_installer.rb
duck_puncher-2.15.0 lib/duck_puncher/gem_installer.rb
duck_puncher-2.14.1 lib/duck_puncher/gem_installer.rb
duck_puncher-2.14.0 lib/duck_puncher/gem_installer.rb
duck_puncher-2.13.0 lib/duck_puncher/gem_installer.rb
duck_puncher-2.12.1 lib/duck_puncher/gem_installer.rb
duck_puncher-2.12.0 lib/duck_puncher/gem_installer.rb