Simplify SoftwareSpec checksum methods

Reader methods for specific checksum types have been absent from the
Formula class for some time, so there isn't any reason to expose them in
SoftwareSpec, either.

Thus, these methods now only act as setters, and #checksum should be
used to access the constructed Checksum object.
This commit is contained in:
Jack Nagel 2013-03-18 14:59:10 -05:00
parent 456386c9b1
commit c8168d8a4a
4 changed files with 11 additions and 31 deletions

View File

@ -202,22 +202,15 @@ end
# MD5 support # MD5 support
class Formula class Formula
def self.md5(val=nil) def self.md5(val)
unless val.nil? @stable ||= SoftwareSpec.new
@stable ||= SoftwareSpec.new @stable.md5(val)
@stable.md5(val)
end
return @stable ? @stable.md5 : @md5
end end
end end
class SoftwareSpec class SoftwareSpec
def md5(val=nil) def md5(val)
if val.nil? @checksum = Checksum.new(:md5, val)
@checksum if checksum.nil? or @checksum.hash_type == :md5
else
@checksum = Checksum.new(:md5, val)
end
end end
end end

View File

@ -677,12 +677,9 @@ private
Checksum::TYPES.each do |cksum| Checksum::TYPES.each do |cksum|
class_eval <<-EOS, __FILE__, __LINE__ + 1 class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{cksum}(val=nil) def #{cksum}(val)
unless val.nil? @stable ||= SoftwareSpec.new
@stable ||= SoftwareSpec.new @stable.#{cksum}(val)
@stable.#{cksum}(val)
end
return @stable ? @stable.#{cksum} : @#{cksum}
end end
EOS EOS
end end

View File

@ -33,12 +33,8 @@ class SoftwareSpec
# The methods that follow are used in the block-form DSL spec methods # The methods that follow are used in the block-form DSL spec methods
Checksum::TYPES.each do |cksum| Checksum::TYPES.each do |cksum|
class_eval <<-EOS, __FILE__, __LINE__ + 1 class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{cksum}(val=nil) def #{cksum}(val)
if val.nil? @checksum = Checksum.new(:#{cksum}, val)
@checksum if @checksum.nil? or @checksum.hash_type == :#{cksum}
else
@checksum = Checksum.new(:#{cksum}, val)
end
end end
EOS EOS
end end
@ -94,11 +90,9 @@ class Bottle < SoftwareSpec
# a Hash, which indicates the platform the checksum applies on. # a Hash, which indicates the platform the checksum applies on.
Checksum::TYPES.each do |cksum| Checksum::TYPES.each do |cksum|
class_eval <<-EOS, __FILE__, __LINE__ + 1 class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{cksum}(val=nil) def #{cksum}(val)
@#{cksum} ||= Hash.new @#{cksum} ||= Hash.new
case val case val
when nil
@#{cksum}[MacOS.cat]
when Hash when Hash
key, value = val.shift key, value = val.shift
@#{cksum}[value] = Checksum.new(:#{cksum}, key) @#{cksum}[value] = Checksum.new(:#{cksum}, key)

View File

@ -111,10 +111,6 @@ class FormulaTests < Test::Unit::TestCase
assert_match /[0-9a-fA-F]{40}/, f.stable.checksum.hexdigest assert_match /[0-9a-fA-F]{40}/, f.stable.checksum.hexdigest
assert_match /[0-9a-fA-F]{64}/, f.devel.checksum.hexdigest assert_match /[0-9a-fA-F]{64}/, f.devel.checksum.hexdigest
assert_nil f.stable.sha256
assert_nil f.bottle.sha256
assert_nil f.devel.sha1
assert_equal 1, f.stable.mirrors.length assert_equal 1, f.stable.mirrors.length
assert f.bottle.mirrors.empty? assert f.bottle.mirrors.empty?
assert_equal 1, f.devel.mirrors.length assert_equal 1, f.devel.mirrors.length