class Gem::Commands::ExecCommand

Public Class Methods

new() click to toggle source
Calls superclass method Gem::Command::new
# File rubygems/commands/exec_command.rb, line 12
def initialize
  super "exec", "Run a command from a gem", {
    version: Gem::Requirement.default,
  }

  add_version_option
  add_prerelease_option "to be installed"

  add_option "-g", "--gem GEM", "run the executable from the given gem" do |value, options|
    options[:gem_name] = value
  end

  add_option(:"Install/Update", "--conservative",
    "Prefer the most recent installed version, ",
    "rather than the latest version overall") do |_value, options|
    options[:conservative] = true
  end
end

Public Instance Methods

execute() click to toggle source
# File rubygems/commands/exec_command.rb, line 59
def execute
  gem_paths = { "GEM_HOME" => Gem.paths.home, "GEM_PATH" => Gem.paths.path.join(File::PATH_SEPARATOR), "GEM_SPEC_CACHE" => Gem.paths.spec_cache_dir }.compact

  check_executable

  print_command
  if options[:gem_name] == "gem" && options[:executable] == "gem"
    set_gem_exec_install_paths
    Gem::GemRunner.new.run options[:args]
    return
  elsif options[:conservative]
    install_if_needed
  else
    install
    activate!
  end

  load!
ensure
  ENV.update(gem_paths) if gem_paths
  Gem.clear_paths
end