Class: Gem::Commands::DefaultCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/default_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(output = STDOUT) ⇒ DefaultCommand

Returns a new instance of DefaultCommand.



5
6
7
8
9
10
11
12
# File 'lib/rubygems/commands/default_command.rb', line 5

def initialize(output = STDOUT)
  super 'default', description
  @output = output

  add_option('-v', '--version VERSION', 'Gem version to be a default gem') do |version, _options|
    options[:version] = version
  end
end

Instance Method Details

#descriptionObject



18
19
20
# File 'lib/rubygems/commands/default_command.rb', line 18

def description
  'Allows you to change an arbitrary installed gem to a default gem'
end

#executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems/commands/default_command.rb', line 22

def execute
  gem_name = options[:args][0]
  if gem_name.nil?
    abort 'gem name is not specified. Usage: `gem default gem_name -v 1.2.3`'
  end

  DefaultGemInstaller.new(
    gem_home: Gem.paths.home,
    ruby_arch_dir: RbConfig::CONFIG['rubyarchdir'],
    ruby_bin_dir: RbConfig::CONFIG['bindir'],
    ruby_lib_dir: RbConfig::CONFIG['rubylibdir'],
    dlext: RbConfig::CONFIG['DLEXT'],
  ).install(gem_name, version: options[:version])
end

#usageObject



14
15
16
# File 'lib/rubygems/commands/default_command.rb', line 14

def usage
  "#{program_name} GEMNAME"
end