mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Rename 'has_key?' and 'has_interrupt?'
This commit is contained in:
@@ -28,6 +28,9 @@ Lint/UnusedBlockArgument:
|
|||||||
Lint/EndAlignment:
|
Lint/EndAlignment:
|
||||||
AlignWith: variable
|
AlignWith: variable
|
||||||
|
|
||||||
|
Lint/UnusedMethodArgument:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Style/SingleLineBlockParams:
|
Style/SingleLineBlockParams:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,6 @@
|
|||||||
# 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: 11
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Lint/UnusedMethodArgument:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 51
|
# Offense count: 51
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 58
|
Max: 58
|
||||||
@@ -70,11 +65,6 @@ Style/MultilineBlockChain:
|
|||||||
Style/Next:
|
Style/Next:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
|
||||||
Style/PredicateName:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 7
|
# Offense count: 7
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: AllowAsExpressionSeparator.
|
# Configuration parameters: AllowAsExpressionSeparator.
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ module Liquid
|
|||||||
|
|
||||||
@nodelist.each do |token|
|
@nodelist.each do |token|
|
||||||
# Break out if we have any unhanded interrupts.
|
# Break out if we have any unhanded interrupts.
|
||||||
break if context.has_interrupt?
|
break if context.interrupt?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# If we get an Interrupt that means the block must stop processing. An
|
# If we get an Interrupt that means the block must stop processing. An
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# are there any not handled interrupts?
|
# are there any not handled interrupts?
|
||||||
def has_interrupt?
|
def interrupt?
|
||||||
!@interrupts.empty?
|
!@interrupts.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ module Liquid
|
|||||||
evaluate(Expression.parse(expression))
|
evaluate(Expression.parse(expression))
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_key?(key)
|
def key?(key)
|
||||||
self[key] != nil
|
self[key] != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ module Liquid
|
|||||||
def find_variable(key)
|
def find_variable(key)
|
||||||
# This was changed from find() to find_index() because this is a very hot
|
# This was changed from find() to find_index() because this is a very hot
|
||||||
# path and find_index() is optimized in MRI to reduce object allocation
|
# path and find_index() is optimized in MRI to reduce object allocation
|
||||||
index = @scopes.find_index { |s| s.has_key?(key) }
|
index = @scopes.find_index { |s| s.key?(key) }
|
||||||
scope = @scopes[index] if index
|
scope = @scopes[index] if index
|
||||||
|
|
||||||
variable = nil
|
variable = nil
|
||||||
@@ -203,7 +203,7 @@ module Liquid
|
|||||||
def squash_instance_assigns_with_environments
|
def squash_instance_assigns_with_environments
|
||||||
@scopes.last.each_key do |k|
|
@scopes.last.each_key do |k|
|
||||||
@environments.each do |env|
|
@environments.each do |env|
|
||||||
if env.has_key?(k)
|
if env.key?(k)
|
||||||
scopes.last[k] = lookup_and_evaluate(env, k)
|
scopes.last[k] = lookup_and_evaluate(env, k)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_key?(_name)
|
def key?(_name)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ module Liquid
|
|||||||
result << @for_block.render(context)
|
result << @for_block.render(context)
|
||||||
|
|
||||||
# Handle any interrupts if they exist.
|
# Handle any interrupts if they exist.
|
||||||
if context.has_interrupt?
|
if context.interrupt?
|
||||||
interrupt = context.pop_interrupt
|
interrupt = context.pop_interrupt
|
||||||
break if interrupt.is_a? BreakInterrupt
|
break if interrupt.is_a? BreakInterrupt
|
||||||
next if interrupt.is_a? ContinueInterrupt
|
next if interrupt.is_a? ContinueInterrupt
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def [](tag_name)
|
def [](tag_name)
|
||||||
return nil unless @tags.has_key?(tag_name)
|
return nil unless @tags.key?(tag_name)
|
||||||
return @cache[tag_name] if Liquid.cache_classes
|
return @cache[tag_name] if Liquid.cache_classes
|
||||||
|
|
||||||
lookup_class(@tags[tag_name]).tap { |o| @cache[tag_name] = o }
|
lookup_class(@tags[tag_name]).tap { |o| @cache[tag_name] = o }
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ module Liquid
|
|||||||
# If object is a hash- or array-like object we look for the
|
# If object is a hash- or array-like object we look for the
|
||||||
# presence of the key and if its available we return it
|
# presence of the key and if its available we return it
|
||||||
if object.respond_to?(:[]) &&
|
if object.respond_to?(:[]) &&
|
||||||
((object.respond_to?(:has_key?) && object.has_key?(key)) ||
|
((object.respond_to?(:key?) && object.key?(key)) ||
|
||||||
(object.respond_to?(:fetch) && key.is_a?(Integer)))
|
(object.respond_to?(:fetch) && key.is_a?(Integer)))
|
||||||
|
|
||||||
# if its a proc we will replace the entry with the proc
|
# if its a proc we will replace the entry with the proc
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class ContextTest < Minitest::Test
|
|||||||
def test_has_key_will_not_add_an_error_for_missing_keys
|
def test_has_key_will_not_add_an_error_for_missing_keys
|
||||||
with_error_mode :strict do
|
with_error_mode :strict do
|
||||||
context = Context.new
|
context = Context.new
|
||||||
context.has_key?('unknown')
|
context.key?('unknown')
|
||||||
assert_empty context.errors
|
assert_empty context.errors
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
mock_any = Spy.on_instance_method(Array, :any?)
|
mock_any = Spy.on_instance_method(Array, :any?)
|
||||||
mock_empty = Spy.on_instance_method(Array, :empty?)
|
mock_empty = Spy.on_instance_method(Array, :empty?)
|
||||||
|
|
||||||
@context.has_interrupt?
|
@context.interrupt?
|
||||||
|
|
||||||
refute mock_any.has_been_called?
|
refute mock_any.has_been_called?
|
||||||
assert mock_empty.has_been_called?
|
assert mock_empty.has_been_called?
|
||||||
|
|||||||
Reference in New Issue
Block a user