1. Gem::
  2. Commands::
  3. ExecCommand

class Gem::Commands::ExecCommand

Public Class Methods

Source
# File lib/rubygems/commands/exec_command.rb, line 12definitializesuper"exec","Run a command from a gem", {version:Gem::Requirement.default,  }add_version_optionadd_prerelease_option"to be installed"add_option"-g","--gem GEM","run the executable from the given gem"do|value,options|options[:gem_name] =valueendadd_option(:"Install/Update","--conservative","Prefer the most recent installed version, ","rather than the latest version overall")do|_value,options|options[:conservative] =trueendend
Calls superclass methodGem::Command::new

Public Instance Methods

Source
# File lib/rubygems/commands/exec_command.rb, line 59defexecutecheck_executableprint_commandifoptions[:gem_name]=="gem"&&options[:executable]=="gem"set_gem_exec_install_pathsGem::GemRunner.new.runoptions[:args]returnelsifoptions[:conservative]install_if_neededelseinstallactivate!endload!end

Private Instance Methods

Source
# File lib/rubygems/commands/exec_command.rb, line 187defactivate!gem(options[:gem_name],options[:version])Gem.finish_resolveverbose"activated #{options[:gem_name]} (#{Gem.loaded_specs[options[:gem_name]].version})"end
Source
# File lib/rubygems/commands/exec_command.rb, line 114defcheck_executableifoptions[:executable].nil?raiseGem::CommandLineError,"Please specify an executable to run (e.g. #{program_name} COMMAND)"endend
Source
# File lib/rubygems/commands/exec_command.rb, line 79defhandle_options(args)args =add_extra_args(args)check_deprecated_options(args)@options =Marshal.loadMarshal.dump@defaults# deep copyparser.order!(args)do|v|# put the non-option back at the front of the list of argumentsargs.unshift(v)# stop parsing once we hit the first non-option,# so you can call `gem exec rails --version` and it prints the rails# version rather than rubygem'sbreakend@options[:args] =argsoptions[:executable],gem_version =extract_gem_name_and_version(options[:args].shift)options[:gem_name]||=options[:executable]ifgem_versionifoptions[:version].none?options[:version] =Gem::Requirement.new(gem_version)elseoptions[:version].concat [gem_version]endendifoptions[:prerelease]&&!options[:version].prerelease?ifoptions[:version].none?options[:version] =Gem::Requirement.default_prereleaseelseoptions[:version].concat [Gem::Requirement.default_prerelease]endendend
Source
# File lib/rubygems/commands/exec_command.rb, line 148definstallset_gem_exec_install_pathsgem_name =options[:gem_name]gem_version =options[:version]install_options =options.merge(minimal_deps:false,wrappers:true  )suppress_always_installdodep_installer =Gem::DependencyInstaller.newinstall_optionsrequest_set =dep_installer.resolve_dependenciesgem_name,gem_versionverbose"Gems to install:"request_set.sorted_requests.eachdo|activation_request|verbose"\t#{activation_request.full_name}"endrequest_set.installinstall_optionsendGem::Specification.resetrescueGem::InstallError=>ealert_error"Error installing #{gem_name}:\n\t#{e.message}"terminate_interaction1rescueGem::GemNotFoundException=>eshow_lookup_failuree.name,e.version,e.errors,falseterminate_interaction2rescueGem::UnsatisfiableDependencyError=>eshow_lookup_failuree.name,e.version,e.errors,false,"'#{gem_name}' (#{gem_version})"terminate_interaction2end
Source
# File lib/rubygems/commands/exec_command.rb, line 132definstall_if_neededactivate!rescueGem::MissingSpecErrorverbose"#{Gem::Dependency.new(options[:gem_name], options[:version])} not available locally, installing from remote"installactivate!end
Source
# File lib/rubygems/commands/exec_command.rb, line 194defload!argv =ARGV.cloneARGV.replaceoptions[:args]executable =options[:executable]contains_executable =Gem.loaded_specs.values.selectdo|spec|spec.executables.include?(executable)endifcontains_executable.any? {|s|s.name==executable }contains_executable.select! {|s|s.name==executable }endifcontains_executable.empty?spec =Gem.loaded_specs[executable]ifspec.nil?||spec.executables.empty?alert_error"Failed to load executable `#{executable}`," \" are you sure the gem `#{options[:gem_name]}` contains it?"terminate_interaction1endifspec.executables.size>1alert_error"Ambiguous which executable from gem `#{executable}` should be run: " \"the options are #{spec.executables.sort}, specify one via COMMAND, and use `-g` and `-v` to specify gem and version"terminate_interaction1endcontains_executable<<specexecutable =spec.executableendifcontains_executable.size>1alert_error"Ambiguous which gem `#{executable}` should come from: " \"the options are #{contains_executable.map(&:name)}, " \"specify one via `-g`"terminate_interaction1endold_exe =$0$0 =executableloadGem.activate_bin_path(contains_executable.first.name,executable,">= 0.a")ensure$0 =old_exeifold_exeARGV.replaceargvend
Source
# File lib/rubygems/commands/exec_command.rb, line 121defprint_commandverbose"running #{program_name} with:\n"opts =options.reject {|_,v|v.nil?||Array(v).empty? }max_length =opts.map {|k,_|k.size }.maxopts.eachdo|k,v|nextifv.nil?verbose"\t#{k.to_s.rjust(max_length)}: #{v}"endverbose""end
Source
# File lib/rubygems/commands/exec_command.rb, line 140defset_gem_exec_install_pathshome =Gem.dirENV["GEM_PATH"] = ([home]+Gem.path).join(File::PATH_SEPARATOR)ENV["GEM_HOME"] =homeGem.clear_pathsend
Source
# File lib/rubygems/commands/exec_command.rb, line 242defsuppress_always_installname =:always_installcls =::Gem::Resolver::InstallerSetmethod =cls.instance_method(name)cls.remove_method(name)cls.define_method(name) { [] }beginyieldensurecls.remove_method(name)cls.define_method(name,method)endend