mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Fix uniq filter with string input
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# 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
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
# Offense count: 51
|
||||
# Offense count: 53
|
||||
Metrics/AbcSize:
|
||||
Max: 58
|
||||
|
||||
@@ -18,7 +18,7 @@ Metrics/ClassLength:
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 15
|
||||
|
||||
# Offense count: 550
|
||||
# Offense count: 552
|
||||
# Configuration parameters: AllowURI, URISchemes.
|
||||
Metrics/LineLength:
|
||||
Max: 294
|
||||
@@ -31,7 +31,7 @@ Metrics/MethodLength:
|
||||
# Offense count: 1
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ModuleLength:
|
||||
Max: 234
|
||||
Max: 235
|
||||
|
||||
# Offense count: 6
|
||||
Metrics/PerceivedComplexity:
|
||||
|
||||
@@ -138,10 +138,12 @@ module Liquid
|
||||
# Remove duplicate elements from an array
|
||||
# provide optional property with which to determine uniqueness
|
||||
def uniq(input, property = nil)
|
||||
ary = InputIterator.new(input)
|
||||
|
||||
if property.nil?
|
||||
input.uniq
|
||||
elsif input.first.respond_to?(:[])
|
||||
input.uniq{ |a| a[property] }
|
||||
ary.uniq
|
||||
elsif ary.first.respond_to?(:[])
|
||||
ary.uniq{ |a| a[property] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -391,6 +393,10 @@ module Liquid
|
||||
reverse_each.to_a
|
||||
end
|
||||
|
||||
def uniq(&block)
|
||||
to_a.uniq(&block)
|
||||
end
|
||||
|
||||
def each
|
||||
@input.each do |e|
|
||||
yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)
|
||||
|
||||
@@ -170,6 +170,7 @@ class StandardFiltersTest < Minitest::Test
|
||||
end
|
||||
|
||||
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 [{ "a" => 1 }, { "a" => 3 }, { "a" => 2 }], @filters.uniq([{ "a" => 1 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a")
|
||||
testdrop = TestDrop.new
|
||||
|
||||
Reference in New Issue
Block a user