Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Teach Gem::Collection.new to flatten.

  • Loading branch information...
commit f0580fc6b0264a24313825678429a895c46755c9 1 parent fd80652
@jbarnette authored
Showing with 19 additions and 18 deletions.
  1. +3 −2 lib/rubygems/collection.rb
  2. +16 −16 test/test_gem_collection.rb
View
5 lib/rubygems/collection.rb
@@ -15,8 +15,9 @@ class Collection
# Create a new instance with an optional Array of +entries+.
- def initialize entries = nil
- @entries = (entries || []).sort_by { |e| [e.name, e.version] }.reverse!
+ def initialize *entries
+ @entries = (entries.flatten || []).
+ sort_by! { |e| [e.name, e.version] }.reverse!
end
# Return a Hash containing the entries in this collection grouped
View
32 test/test_gem_collection.rb
@@ -7,9 +7,9 @@ def test_by
a = entry "foo", "1.0.0"
b = entry "foo", "2.0.0"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
- expected = { "foo" => Gem::Collection.new([b, a]) }
+ expected = { "foo" => Gem::Collection.new(b, a) }
assert_equal expected, specs.by(:name)
end
@@ -19,7 +19,7 @@ def test_initialize
end
def test_initialize_array
- specs = Gem::Collection.new [entry("foo", "1.0.0")]
+ specs = Gem::Collection.new entry("foo", "1.0.0")
assert_equal 1, specs.count
assert_equal 1, specs.length
@@ -31,7 +31,7 @@ def test_latest
ap = entry "foo", "2.0.0.pre"
a1 = entry "foo", "2.0.0"
- specs = Gem::Collection.new [a, ap, a1]
+ specs = Gem::Collection.new a, ap, a1
assert_equal 1, specs.latest.size
assert_equal a1, specs.latest.first
end
@@ -40,7 +40,7 @@ def test_prerelease
a = entry "foo", "1.0.0"
b = entry "foo", "2.0.0.pre"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal 2, specs.size
assert_equal 1, specs.prerelease.size
assert_equal b, specs.prerelease.first
@@ -51,7 +51,7 @@ def test_prerelease_latest
b = entry "foo", "1.0.0.pre.2"
c = entry "bar", "1.0.0"
- specs = Gem::Collection.new [a, b, c]
+ specs = Gem::Collection.new a, b, c
assert_equal [b], specs.prerelease.latest.entries
end
@@ -59,7 +59,7 @@ def test_released
a = entry "foo", "1.0.0"
b = entry "foo", "2.0.0.pre"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal 2, specs.size
assert_equal 1, specs.released.size
assert_equal a, specs.released.first
@@ -69,7 +69,7 @@ def test_search
a = entry "foo", "1.0.0"
b = entry "bar", "1.0.0"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal [a], specs.search("foo").entries
assert_equal [b], specs.search("bar").entries
@@ -79,7 +79,7 @@ def test_search_regexp
a = entry "foobar", "1.0.0"
b = entry "foobaz", "1.0.0"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal [a, b], specs.search(/foo/).sort
end
@@ -87,7 +87,7 @@ def test_search_requirement
a = entry "foo", "1.0.0"
b = entry "foo", "2.0.0"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal [b], specs.search("foo", "> 1.0.0").entries
end
@@ -95,7 +95,7 @@ def test_search_platform
a = entry "foo", "1.0.0"
b = entry "foo", "1.0.0", "jruby"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal [b], specs.search("foo", :platform => "jruby").entries
end
@@ -103,12 +103,12 @@ def test_search_narrowed
a = entry "foo", "1.0.0"
b = entry "foo", "1.0.0.pre"
- specs = Gem::Collection.new [a, b]
+ specs = Gem::Collection.new a, b
assert_equal [b], specs.prerelease.search("foo").entries
end
def test_to_s
- c = Gem::Collection.new [entry("foo", "1.0.0")]
+ c = Gem::Collection.new entry("foo", "1.0.0")
assert_match(/Gem::Collection/, c.to_s)
assert_match(/foo/, c.to_s)
end
@@ -116,15 +116,15 @@ def test_to_s
def test_uniq
a = entry "foo", "1.0.0"
b = a.dup
- c = Gem::Collection.new [a, b]
+ c = Gem::Collection.new a, b
- assert_equal Gem::Collection.new([a]), c.uniq
+ assert_equal Gem::Collection.new(a), c.uniq
end
def test_uniq!
a = entry "foo", "1.0.0"
b = a.dup
- c = Gem::Collection.new [a, b]
+ c = Gem::Collection.new a, b
u = c.uniq!
assert_same c, u
Please sign in to comment.
Something went wrong with that request. Please try again.