Ask the filename object for the prefix

This commit is contained in:
Jack Nagel 2014-07-18 15:14:42 -05:00
parent 1cc3747094
commit 49a97c280a
4 changed files with 17 additions and 10 deletions

View File

@ -19,11 +19,6 @@ def bottle_file_outdated? f, file
bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext
end end
def bottle_suffix revision
revision = revision > 0 ? ".#{revision}" : ""
".bottle#{revision}.tar.gz"
end
def bottle_native_regex def bottle_native_regex
/(\.#{bottle_tag}\.bottle\.(\d+\.)?tar\.gz)$/o /(\.#{bottle_tag}\.bottle\.(\d+\.)?tar\.gz)$/o
end end

View File

@ -192,10 +192,7 @@ module Homebrew
puts output puts output
if ARGV.include? '--rb' if ARGV.include? '--rb'
bottle_base = filename.to_s.gsub(bottle_suffix(bottle_revision), '') File.open("#{filename.prefix}.bottle.rb", "w") { |file| file.write(output) }
File.open "#{bottle_base}.bottle.rb", 'w' do |file|
file.write output
end
end end
end end

View File

@ -124,9 +124,18 @@ class Bottle
end end
def to_s def to_s
"#{name}-#{version}.#{tag}#{bottle_suffix(revision)}" prefix + suffix
end end
alias_method :to_str, :to_s alias_method :to_str, :to_s
def prefix
"#{name}-#{version}.#{tag}"
end
def suffix
s = revision > 0 ? ".#{revision}" : ""
".bottle#{s}.tar.gz"
end
end end
extend Forwardable extend Forwardable

View File

@ -6,6 +6,12 @@ class BottleFilenameTests < Homebrew::TestCase
Bottle::Filename.new("foo", "1.0", :tag, revision) Bottle::Filename.new("foo", "1.0", :tag, revision)
end end
def test_prefix_suffix
assert_equal "foo-1.0.tag", fn(0).prefix
assert_equal ".bottle.tar.gz", fn(0).suffix
assert_equal ".bottle.1.tar.gz", fn(1).suffix
end
def test_to_str def test_to_str
expected = "foo-1.0.tag.bottle.tar.gz" expected = "foo-1.0.tag.bottle.tar.gz"
assert_equal expected, fn(0).to_s assert_equal expected, fn(0).to_s