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