Sha256: b32c6abc337634b1c48dfe7a98cdac9edfe1f86970e72e174efbfa408012e3c2

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 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.logger.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.logger.error "Failed to install #{args.first}. #{e.inspect}"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
duck_puncher-4.4.0 lib/duck_puncher/gem_installer.rb
duck_puncher-4.3.1 lib/duck_puncher/gem_installer.rb
duck_puncher-4.3.0 lib/duck_puncher/gem_installer.rb
duck_puncher-4.2.3 lib/duck_puncher/gem_installer.rb
duck_puncher-4.2.2 lib/duck_puncher/gem_installer.rb
duck_puncher-4.2.1 lib/duck_puncher/gem_installer.rb
duck_puncher-4.2.0 lib/duck_puncher/gem_installer.rb