Implement []= on BottleCollector

This commit is contained in:
Jack Nagel 2014-07-15 21:55:14 -05:00
parent 26f4a78825
commit 68326805ae
3 changed files with 18 additions and 13 deletions

View File

@ -68,18 +68,23 @@ class BottleCollector
@bottles = {} @bottles = {}
end end
def add(checksum, tag)
@bottles[tag] = checksum
end
def fetch_bottle_for(tag) def fetch_bottle_for(tag)
return [@bottles[tag], tag] if @bottles[tag] return [@bottles[tag], tag] if @bottles[tag]
find_altivec_tag(tag) || find_or_later_tag(tag) find_altivec_tag(tag) || find_or_later_tag(tag)
end end
def keys; @bottles.keys; end def keys
def [](arg); @bottles[arg]; end @bottles.keys
end
def [](key)
@bottles[key]
end
def []=(key, value)
@bottles[key] = value
end
# This allows generic Altivec PPC bottles to be supported in some # This allows generic Altivec PPC bottles to be supported in some
# formulae, while also allowing specific bottles in others; e.g., # formulae, while also allowing specific bottles in others; e.g.,

View File

@ -172,7 +172,7 @@ class BottleSpecification
Checksum::TYPES.each do |cksum| Checksum::TYPES.each do |cksum|
define_method(cksum) do |val| define_method(cksum) do |val|
digest, tag = val.shift digest, tag = val.shift
collector.add(Checksum.new(cksum, digest), tag) collector[tag] = Checksum.new(cksum, digest)
end end
end end

View File

@ -7,8 +7,8 @@ class BottleCollectorTests < Homebrew::TestCase
end end
def test_collector_returns_passed_tags def test_collector_returns_passed_tags
@collector.add('foo', :lion) @collector[:lion] = "foo"
@collector.add('bar', :mountain_lion) @collector[:mountain_lion] = "bar"
assert_equal ['bar', :mountain_lion], @collector.fetch_bottle_for(:mountain_lion) assert_equal ['bar', :mountain_lion], @collector.fetch_bottle_for(:mountain_lion)
end end
@ -17,19 +17,19 @@ class BottleCollectorTests < Homebrew::TestCase
end end
def test_collector_finds_or_later_tags def test_collector_finds_or_later_tags
@collector.add('foo', :lion_or_later) @collector[:lion_or_later] = "foo"
assert_equal ['foo', :lion_or_later], @collector.fetch_bottle_for(:mountain_lion) assert_equal ['foo', :lion_or_later], @collector.fetch_bottle_for(:mountain_lion)
assert_nil @collector.fetch_bottle_for(:snow_leopard) assert_nil @collector.fetch_bottle_for(:snow_leopard)
end end
def test_collector_prefers_exact_matches def test_collector_prefers_exact_matches
@collector.add('foo', :lion_or_later) @collector[:lion_or_later] = "foo"
@collector.add('bar', :mountain_lion) @collector[:mountain_lion] = "bar"
assert_equal ['bar', :mountain_lion], @collector.fetch_bottle_for(:mountain_lion) assert_equal ['bar', :mountain_lion], @collector.fetch_bottle_for(:mountain_lion)
end end
def test_collector_finds_altivec_tags def test_collector_finds_altivec_tags
@collector.add('foo', :tiger_altivec) @collector[:tiger_altivec] = "foo"
assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g4) assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g4)
assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g4e) assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g4e)
assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g5) assert_equal ['foo', :tiger_altivec], @collector.fetch_bottle_for(:tiger_g5)