Extract tag and checksum selection from DSL method

This commit is contained in:
Jack Nagel 2014-04-01 16:03:08 -05:00
parent 7552669719
commit 7d3215c9f4

View File

@ -47,7 +47,7 @@ class SoftwareSpec
end end
def bottled? def bottled?
bottle_specification.fully_specified? bottle_specification.tag?(bottle_tag)
end end
def bottle &block def bottle &block
@ -124,16 +124,19 @@ class Bottle
@name = f.name @name = f.name
@resource = Resource.new @resource = Resource.new
@resource.owner = f @resource.owner = f
checksum, tag = spec.checksum_for(bottle_tag)
@resource.url = bottle_url( @resource.url = bottle_url(
spec.root_url, spec.root_url,
:name => f.name, :name => f.name,
:version => f.pkg_version, :version => f.pkg_version,
:revision => spec.revision, :revision => spec.revision,
:tag => spec.current_tag :tag => tag
) )
@resource.download_strategy = CurlBottleDownloadStrategy @resource.download_strategy = CurlBottleDownloadStrategy
@resource.version = f.pkg_version @resource.version = f.pkg_version
@resource.checksum = spec.checksum @resource.checksum = checksum
@prefix = spec.prefix @prefix = spec.prefix
@cellar = spec.cellar @cellar = spec.cellar
@revision = spec.revision @revision = spec.revision
@ -146,7 +149,7 @@ end
class BottleSpecification class BottleSpecification
attr_rw :root_url, :prefix, :cellar, :revision attr_rw :root_url, :prefix, :cellar, :revision
attr_reader :current_tag, :checksum, :collector attr_reader :checksum, :collector
def initialize def initialize
@revision = 0 @revision = 0
@ -156,23 +159,21 @@ class BottleSpecification
@collector = BottleCollector.new @collector = BottleCollector.new
end end
def fully_specified? def tag?(tag)
checksum && !checksum.empty? !!collector.fetch_bottle_for(tag)
end end
# Checksum methods in the DSL's bottle block optionally take # Checksum methods in the DSL's bottle block optionally take
# 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 define_method(cksum) do |val|
def #{cksum}(val) digest, tag = val.shift
digest, tag = val.shift collector.add(Checksum.new(cksum, digest), tag)
collector.add(Checksum.new(:#{cksum}, digest), tag) end
end
cksum, current_tag = collector.fetch_bottle_for(bottle_tag) def checksum_for(tag)
@checksum = cksum if cksum collector.fetch_bottle_for(tag)
@current_tag = current_tag if cksum
end
EOS
end end
def checksums def checksums