Class: Gem::Commands::CheckoutCommand

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

Instance Method Summary collapse

Constructor Details

#initializeCheckoutCommand

Returns a new instance of CheckoutCommand.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems/commands/checkout_command.rb', line 7

def initialize
  super 'checkout', description
  add_option('-v', '--version VERSION', 'version to checkout') do |version, options|
    options[:version] = version
  end

  add_option('-d', '--debug LEVEL', 'set debug mode (0=debug)') do |level, options|
    options[:debug_level] = Integer(level)
  end

  add_option('-s', '--[no-]verify',  'verify sources match gem exactly') do |verify, options|
    options[:verify] = verify
  end
end

Instance Method Details

#argumentsObject

:nodoc:



22
23
24
# File 'lib/rubygems/commands/checkout_command.rb', line 22

def arguments # :nodoc:
  "checkout        checkout the original repository at the same version"
end

#defaults_strObject

:nodoc:



30
31
32
# File 'lib/rubygems/commands/checkout_command.rb', line 30

def defaults_str # :nodoc:
  ""
end

#descriptionObject

:nodoc:



34
35
36
# File 'lib/rubygems/commands/checkout_command.rb', line 34

def description # :nodoc:
  "Checkout a gem's repository or sources at the same version"
end

#executeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubygems/commands/checkout_command.rb', line 38

def execute
  logger = Logger.new(STDERR)
  logger.level = options[:debug_level] || Logger::WARN
  Gem::Checkout.logger = logger

  name = get_one_gem_name
  source = Gem::Checkout::Source.new(name, options[:version])
  version = source.version

  repository = source.repository
  repository.clone(directory: name)
  Dir.chdir(name) do
    repository.checkout(source.source_reference)
    if options[:verify]
      verifier = Gem::Checkout::Verifier.new(name, version)
      verifier.verify!
    end
  end
rescue Gem::Checkout::Repository::Error => ex
  alert_error ex.message
  terminate_interaction 1
rescue Gem::Checkout::Verifier::Error => ex
  alert_error ex.message
  terminate_interaction 1
end

#usageObject

:nodoc:



26
27
28
# File 'lib/rubygems/commands/checkout_command.rb', line 26

def usage # :nodoc:
  "#{program_name}"
end