mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Refactor: avoid usage of public_send
This commit is contained in:
@@ -424,7 +424,7 @@ module Liquid
|
|||||||
# @liquid_syntax array | where: string, string
|
# @liquid_syntax array | where: string, string
|
||||||
# @liquid_return [array[untyped]]
|
# @liquid_return [array[untyped]]
|
||||||
def where(input, property, target_value = nil)
|
def where(input, property, target_value = nil)
|
||||||
filter_array(input, property, target_value, :select)
|
filter_array(input, property, target_value) { |ary, &block| ary.select(&block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @liquid_public_docs
|
# @liquid_public_docs
|
||||||
@@ -437,7 +437,7 @@ module Liquid
|
|||||||
# @liquid_syntax array | reject: string, string
|
# @liquid_syntax array | reject: string, string
|
||||||
# @liquid_return [array[untyped]]
|
# @liquid_return [array[untyped]]
|
||||||
def reject(input, property, target_value = nil)
|
def reject(input, property, target_value = nil)
|
||||||
filter_array(input, property, target_value, :reject)
|
filter_array(input, property, target_value) { |ary, &block| ary.reject(&block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @liquid_public_docs
|
# @liquid_public_docs
|
||||||
@@ -450,7 +450,7 @@ module Liquid
|
|||||||
# @liquid_syntax array | some: string, string
|
# @liquid_syntax array | some: string, string
|
||||||
# @liquid_return [boolean]
|
# @liquid_return [boolean]
|
||||||
def has(input, property, target_value = nil)
|
def has(input, property, target_value = nil)
|
||||||
filter_array(input, property, target_value, :any?)
|
filter_array(input, property, target_value) { |ary, &block| ary.any?(&block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @liquid_public_docs
|
# @liquid_public_docs
|
||||||
@@ -463,7 +463,7 @@ module Liquid
|
|||||||
# @liquid_syntax array | find: string, string
|
# @liquid_syntax array | find: string, string
|
||||||
# @liquid_return [untyped]
|
# @liquid_return [untyped]
|
||||||
def find(input, property, target_value = nil)
|
def find(input, property, target_value = nil)
|
||||||
filter_array(input, property, target_value, :find)
|
filter_array(input, property, target_value) { |ary, &block| ary.find(&block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @liquid_public_docs
|
# @liquid_public_docs
|
||||||
@@ -476,7 +476,7 @@ module Liquid
|
|||||||
# @liquid_syntax array | find_index: string, string
|
# @liquid_syntax array | find_index: string, string
|
||||||
# @liquid_return [number]
|
# @liquid_return [number]
|
||||||
def find_index(input, property, target_value = nil)
|
def find_index(input, property, target_value = nil)
|
||||||
filter_array(input, property, target_value, :find_index)
|
filter_array(input, property, target_value) { |ary, &block| ary.find_index(&block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @liquid_public_docs
|
# @liquid_public_docs
|
||||||
@@ -948,12 +948,12 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :context
|
attr_reader :context
|
||||||
|
|
||||||
def filter_array(input, property, target_value, method)
|
def filter_array(input, property, target_value, &block)
|
||||||
ary = InputIterator.new(input, context)
|
ary = InputIterator.new(input, context)
|
||||||
|
|
||||||
return [] if ary.empty?
|
return [] if ary.empty?
|
||||||
|
|
||||||
ary.public_send(method) do |item|
|
block.call(ary) do |item|
|
||||||
if target_value.nil?
|
if target_value.nil?
|
||||||
fetch_property(item, property)
|
fetch_property(item, property)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user