Class: Gem::Commands::ChecksumCommand

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

Instance Method Summary collapse

Constructor Details

#initializeChecksumCommand

Returns a new instance of ChecksumCommand.



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

def initialize
  super 'checksum', 'Calculate the checksum for a gem'

  add_option('--compare-to',
             'Boolean compare to the generated checksum') do
    |value, options|
    options[:compare_to] = value
  end

  add_option('--checksum-folder',
             'Folder to write generated checksum to') do
    |value, options|
    options[:checksum_folder] = value
  end

end

Instance Method Details

#argumentsObject



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

def arguments
  "GEM_NAME           the name of the gem you wish to hash"
end

#descriptionObject



30
31
32
33
34
# File 'lib/rubygems/commands/checksum_command.rb', line 30

def description
  <<END
Calculcates the checksum for a gem
END
end

#executeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubygems/commands/checksum_command.rb', line 36

def execute
  gem_path = next_optional_arg
  fail "No .gem path passed in" if gem_path.nil?
  checker = GemChecksum::Checker.new(gem_path)

  say checksum = checker.generate_checksum

  say checker.write_checksum(next_optional_arg) if options[:checksum_folder]

  if options[:compare_to]
    compare_to = next_optional_arg
    if checker.validate_checksum(compare_to)
      say "Checksum validated"
    else
      say "Calculated checksum not equal to given checksum: " <<
          "\nExpected:\t#{compare_to}\nCalculcated:\t#{checksum}"
    end
  end
end

#usageObject



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

def usage
  "#{program_name} GEM_NAME"
end