mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Merge pull request #595 from Shopify/uniq_on_strings
Fix uniq filter with string input
This commit is contained in:
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
# This configuration was generated by `rubocop --auto-gen-config`
|
# This configuration was generated by `rubocop --auto-gen-config`
|
||||||
# on 2015-06-04 13:07:29 -0400 using RuboCop version 0.31.0.
|
# on 2015-06-04 22:53:26 -0400 using RuboCop version 0.31.0.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
# versions of RuboCop, may require this file to be generated again.
|
# versions of RuboCop, may require this file to be generated again.
|
||||||
|
|
||||||
# Offense count: 51
|
# Offense count: 53
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 58
|
Max: 58
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ Metrics/ClassLength:
|
|||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Max: 15
|
Max: 15
|
||||||
|
|
||||||
# Offense count: 550
|
# Offense count: 552
|
||||||
# Configuration parameters: AllowURI, URISchemes.
|
# Configuration parameters: AllowURI, URISchemes.
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 294
|
Max: 294
|
||||||
@@ -31,7 +31,7 @@ Metrics/MethodLength:
|
|||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Configuration parameters: CountComments.
|
# Configuration parameters: CountComments.
|
||||||
Metrics/ModuleLength:
|
Metrics/ModuleLength:
|
||||||
Max: 234
|
Max: 235
|
||||||
|
|
||||||
# Offense count: 6
|
# Offense count: 6
|
||||||
Metrics/PerceivedComplexity:
|
Metrics/PerceivedComplexity:
|
||||||
|
|||||||
@@ -138,10 +138,12 @@ module Liquid
|
|||||||
# Remove duplicate elements from an array
|
# Remove duplicate elements from an array
|
||||||
# provide optional property with which to determine uniqueness
|
# provide optional property with which to determine uniqueness
|
||||||
def uniq(input, property = nil)
|
def uniq(input, property = nil)
|
||||||
|
ary = InputIterator.new(input)
|
||||||
|
|
||||||
if property.nil?
|
if property.nil?
|
||||||
input.uniq
|
ary.uniq
|
||||||
elsif input.first.respond_to?(:[])
|
elsif ary.first.respond_to?(:[])
|
||||||
input.uniq{ |a| a[property] }
|
ary.uniq{ |a| a[property] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -391,6 +393,10 @@ module Liquid
|
|||||||
reverse_each.to_a
|
reverse_each.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uniq(&block)
|
||||||
|
to_a.uniq(&block)
|
||||||
|
end
|
||||||
|
|
||||||
def each
|
def each
|
||||||
@input.each do |e|
|
@input.each do |e|
|
||||||
yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)
|
yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_uniq
|
def test_uniq
|
||||||
|
assert_equal ["foo"], @filters.uniq("foo")
|
||||||
assert_equal [1, 3, 2, 4], @filters.uniq([1, 1, 3, 2, 3, 1, 4, 3, 2, 1])
|
assert_equal [1, 3, 2, 4], @filters.uniq([1, 1, 3, 2, 3, 1, 4, 3, 2, 1])
|
||||||
assert_equal [{ "a" => 1 }, { "a" => 3 }, { "a" => 2 }], @filters.uniq([{ "a" => 1 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a")
|
assert_equal [{ "a" => 1 }, { "a" => 3 }, { "a" => 2 }], @filters.uniq([{ "a" => 1 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a")
|
||||||
testdrop = TestDrop.new
|
testdrop = TestDrop.new
|
||||||
|
|||||||
Reference in New Issue
Block a user