Add a factory method that accepts a formula object

This commit is contained in:
Jack Nagel 2014-07-18 15:14:42 -05:00
parent 49a97c280a
commit 6f02314cba
3 changed files with 17 additions and 2 deletions

View File

@ -125,7 +125,7 @@ module Homebrew
bottle_revision = max ? max + 1 : 0 bottle_revision = max ? max + 1 : 0
end end
filename = Bottle::Filename.new(f.name, f.pkg_version, bottle_tag, bottle_revision) filename = Bottle::Filename.create(f, bottle_tag, bottle_revision)
if bottle_filename_formula_name(filename).empty? if bottle_filename_formula_name(filename).empty?
return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}" return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}"

View File

@ -116,6 +116,10 @@ class Bottle
class Filename class Filename
attr_reader :name, :version, :tag, :revision attr_reader :name, :version, :tag, :revision
def self.create(formula, tag, revision)
new(formula.name, formula.pkg_version, tag, revision)
end
def initialize(name, version, tag, revision) def initialize(name, version, tag, revision)
@name = name @name = name
@version = version @version = version
@ -152,7 +156,7 @@ class Bottle
checksum, tag = spec.checksum_for(bottle_tag) checksum, tag = spec.checksum_for(bottle_tag)
filename = Filename.new(formula.name, formula.pkg_version, tag, spec.revision) filename = Filename.create(formula, tag, spec.revision)
@resource.url = build_url(spec.root_url, filename) @resource.url = build_url(spec.root_url, filename)
@resource.download_strategy = CurlBottleDownloadStrategy @resource.download_strategy = CurlBottleDownloadStrategy
@resource.version = formula.pkg_version @resource.version = formula.pkg_version

View File

@ -1,4 +1,5 @@
require "testing_env" require "testing_env"
require "formula"
require "software_spec" require "software_spec"
class BottleFilenameTests < Homebrew::TestCase class BottleFilenameTests < Homebrew::TestCase
@ -17,4 +18,14 @@ class BottleFilenameTests < Homebrew::TestCase
assert_equal expected, fn(0).to_s assert_equal expected, fn(0).to_s
assert_equal expected, fn(0).to_str assert_equal expected, fn(0).to_str
end end
def test_create
f = formula {
url "https://example.com/foo.tar.gz"
version "1.0"
}
expected = "formula_name-1.0.tag.bottle.tar.gz"
assert_equal expected, Bottle::Filename.create(f, :tag, 0).to_s
end
end end