Class: Gem::Tasks::Sign::Checksum

Inherits:
Task
  • Object
show all
Defined in:
lib/rubygems/tasks/sign/checksum.rb

Overview

The sign:checksum task.

Constant Summary

Constants included from Printing

Printing::ANSI_BRIGHT, Printing::ANSI_CLEAR, Printing::ANSI_GREEN, Printing::ANSI_RED, Printing::ANSI_YELLOW, Printing::DEBUG_PREFIX, Printing::ERROR_PREFIX, Printing::STATUS_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Task

#project

Instance Method Summary collapse

Methods inherited from Task

#bundle, #gem, #gemspec_tasks, #invoke, #namespaced_tasks, #run, #task?

Methods included from Printing

#debug, #error, #status

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Checksum

Initializes the sign:checksum task.

Parameters:

  • options (Hash) (defaults to: {})

    Digest options.

Options Hash (options):

  • :md5 (Boolean) — default: true

    Specifies whether MD5 checksums are enabled.

  • :sha1 (Boolean) — default: true

    Specifies whether SHA1 checksums are enabled.

  • :sha2 (Boolean) — default: false

    Specifies whether SHA2 checksums are enabled.

  • :sha512 (Boolean) — default: false

    Specifies whether SHA512 checksums are enabled.

Yields:

  • (_self)

Yield Parameters:


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/tasks/sign/checksum.rb', line 43

def initialize(options={})
  super()

  @md5    = options.fetch(:md5,   true)
  @sha1   = options.fetch(:sha1,  true)
  @sha2   = options.fetch(:sha2,  false)
  @sha512 = options.fetch(:sha512,false)

  yield self if block_given?
  define
end

Instance Attribute Details

#md5=(value) ⇒ Object (writeonly)

Enables or disables MD5 checksums.


14
15
16
# File 'lib/rubygems/tasks/sign/checksum.rb', line 14

def md5=(value)
  @md5 = value
end

#sha1=(value) ⇒ Object (writeonly)

Enables or disables SHA1 checksums.


17
18
19
# File 'lib/rubygems/tasks/sign/checksum.rb', line 17

def sha1=(value)
  @sha1 = value
end

#sha2=(value) ⇒ Object (writeonly)

Enables or disables SHA2 checksums.


20
21
22
# File 'lib/rubygems/tasks/sign/checksum.rb', line 20

def sha2=(value)
  @sha2 = value
end

#sha512=(value) ⇒ Object (writeonly)

Enables or disables SHA512 checksums.


23
24
25
# File 'lib/rubygems/tasks/sign/checksum.rb', line 23

def sha512=(value)
  @sha512 = value
end

Instance Method Details

#defineObject

Defines the sign:checksum tasks.


86
87
88
89
90
# File 'lib/rubygems/tasks/sign/checksum.rb', line 86

def define
  super(:checksum)

  task :checksum => 'sign:checksum'
end

#md5?Boolean

Specifies whether MD5 checksums are enabled.

Returns:

  • (Boolean)

60
# File 'lib/rubygems/tasks/sign/checksum.rb', line 60

def md5?; @md5; end

#sha1?Boolean

Specifies whether SHA1 checksums are enabled.

Returns:

  • (Boolean)

67
# File 'lib/rubygems/tasks/sign/checksum.rb', line 67

def sha1?; @sha1; end

#sha2?Boolean

Specifies whether SHA2 checksums are enabled.

Returns:

  • (Boolean)

74
# File 'lib/rubygems/tasks/sign/checksum.rb', line 74

def sha2?; @sha2; end

#sha512?Boolean

Specifies whether SHA512 checksums are enabled.

Returns:

  • (Boolean)

81
# File 'lib/rubygems/tasks/sign/checksum.rb', line 81

def sha512?; @sha512; end

#sign(path) ⇒ Object

Prints the checksums of a package.

Parameters:

  • path (String)

    The path to the package.


100
101
102
103
104
105
106
107
108
109
# File 'lib/rubygems/tasks/sign/checksum.rb', line 100

def sign(path)
  status "Checksums for #{File.basename(path)}:"

  puts
  puts "  md5:    #{Digest::MD5.file(path)}"    if @md5
  puts "  sha1:   #{Digest::SHA1.file(path)}"   if @sha1
  puts "  sha2:   #{Digest::SHA2.file(path)}"   if @sha2
  puts "  sha512: #{Digest::SHA512.file(path)}" if @sha512
  puts
end