Move bottle filename construction to a class

This commit is contained in:
Jack Nagel 2014-07-18 15:14:42 -05:00
parent 7d28a6c54b
commit a87d2108ea
4 changed files with 36 additions and 24 deletions

View File

@ -3,14 +3,6 @@ require 'os/mac'
require 'extend/ARGV'
require 'bottle_version'
def bottle_filename options={}
name = options.fetch(:name)
version = options.fetch(:version)
tag = options.fetch(:tag)
revision = options.fetch(:revision)
"#{name}-#{version}.#{tag}#{bottle_suffix(revision)}"
end
def built_as_bottle? f
return false unless f.installed?
tab = Tab.for_keg(f.installed_prefix)
@ -36,8 +28,9 @@ def bottle_native_regex
/(\.#{bottle_tag}\.bottle\.(\d+\.)?tar\.gz)$/o
end
def bottle_url(root_url, filename_options)
"#{root_url}/#{bottle_filename(filename_options)}"
def bottle_url(root_url, *filename_args)
filename = Bottle::Filename.new(*filename_args)
"#{root_url}/#{filename}"
end
def bottle_tag

View File

@ -125,12 +125,7 @@ module Homebrew
bottle_revision = max ? max + 1 : 0
end
filename = bottle_filename(
:name => f.name,
:version => f.pkg_version,
:revision => bottle_revision,
:tag => bottle_tag
)
filename = Bottle::Filename.new(f.name, f.pkg_version, bottle_tag, bottle_revision)
if bottle_filename_formula_name(filename).empty?
return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}"
@ -197,7 +192,7 @@ module Homebrew
puts output
if ARGV.include? '--rb'
bottle_base = filename.gsub(bottle_suffix(bottle_revision), '')
bottle_base = filename.to_s.gsub(bottle_suffix(bottle_revision), '')
File.open "#{bottle_base}.bottle.rb", 'w' do |file|
file.write output
end

View File

@ -113,6 +113,22 @@ class HeadSoftwareSpec < SoftwareSpec
end
class Bottle
class Filename
attr_reader :name, :version, :tag, :revision
def initialize(name, version, tag, revision)
@name = name
@version = version
@tag = tag
@revision = revision
end
def to_s
"#{name}-#{version}.#{tag}#{bottle_suffix(revision)}"
end
alias_method :to_str, :to_s
end
extend Forwardable
attr_reader :name, :resource, :prefix, :cellar, :revision
@ -127,13 +143,7 @@ class Bottle
checksum, tag = spec.checksum_for(bottle_tag)
@resource.url = bottle_url(
spec.root_url,
:name => formula.name,
:version => formula.pkg_version,
:revision => spec.revision,
:tag => tag
)
@resource.url = bottle_url(spec.root_url, formula.name, formula.pkg_version, tag, spec.revision)
@resource.download_strategy = CurlBottleDownloadStrategy
@resource.version = formula.pkg_version
@resource.checksum = checksum

View File

@ -0,0 +1,14 @@
require "testing_env"
require "software_spec"
class BottleFilenameTests < Homebrew::TestCase
def fn(revision)
Bottle::Filename.new("foo", "1.0", :tag, revision)
end
def test_to_str
expected = "foo-1.0.tag.bottle.tar.gz"
assert_equal expected, fn(0).to_s
assert_equal expected, fn(0).to_str
end
end