类 Gem::GemRunner

运行 gem 程序的实例。

Gem::GemRunner 仅供 RubyGems 内部使用。它不构成任何公共 API,并且可能随时因任何原因而更改。

如果您想复制 ‘gem’ 命令的功能,请直接使用它们调用的类。

公共类方法

new() 点击以切换源代码
# File rubygems/gem_runner.rb, line 23
def initialize
  @command_manager_class = Gem::CommandManager
  @config_file_class = Gem::ConfigFile
end

公共实例方法

run(args) 点击以切换源代码

使用以下参数运行 gem 命令。

# File rubygems/gem_runner.rb, line 31
def run(args)
  validate_encoding args
  build_args = extract_build_args args

  do_configuration args

  begin
    Gem.load_env_plugins
  rescue StandardError
    nil
  end
  Gem.load_plugins

  cmd = @command_manager_class.instance

  cmd.command_names.each do |command_name|
    config_args = Gem.configuration[command_name]
    config_args = case config_args
                  when String
                    config_args.split " "
                  else
                    Array(config_args)
    end
    Gem::Command.add_specific_extra_args command_name, config_args
  end

  cmd.run Gem.configuration.args, build_args
end

私有实例方法

do_configuration(args) 点击以切换源代码
# File rubygems/gem_runner.rb, line 84
def do_configuration(args)
  Gem.configuration = @config_file_class.new(args)
  Gem.use_paths Gem.configuration[:gemhome], Gem.configuration[:gempath]
  Gem::Command.extra_args = Gem.configuration[:gem]
end
validate_encoding(args) 点击以切换源代码
# File rubygems/gem_runner.rb, line 76
def validate_encoding(args)
  invalid_arg = args.find {|arg| !arg.valid_encoding? }

  if invalid_arg
    raise Gem::OptionParser::InvalidArgument.new("'#{invalid_arg.scrub}' has invalid encoding")
  end
end