mirror of
https://github.com/kemko/liquid.git
synced 2026-01-07 18:55:41 +03:00
Switch to aliasing methods
This commit is contained in:
@@ -80,3 +80,7 @@ require 'liquid/usage'
|
||||
# Load all the tags of the standard library
|
||||
#
|
||||
Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
|
||||
|
||||
# Load all usage tracking
|
||||
#
|
||||
Dir["#{__dir__}/liquid/usages/*.rb"].each { |f| require f }
|
||||
|
||||
@@ -4,7 +4,11 @@ module Liquid
|
||||
@messages = {}
|
||||
class << self
|
||||
def enable
|
||||
Dir["#{__dir__}/usages/*.rb"].each { |f| require f }
|
||||
Liquid::Context.send(:alias_method, :try_variable_find_in_environments, :try_variable_find_in_environments_usage)
|
||||
end
|
||||
|
||||
def disable
|
||||
Liquid::Context.send(:alias_method, :try_variable_find_in_environments, :try_variable_find_in_environments_original)
|
||||
end
|
||||
|
||||
def track(message)
|
||||
|
||||
26
lib/liquid/usages/try_variables.rb
Normal file
26
lib/liquid/usages/try_variables.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
module Liquid
|
||||
class Context
|
||||
alias try_variable_find_in_environments_original try_variable_find_in_environments
|
||||
|
||||
def try_variable_find_in_environments_usage(key, raise_on_not_found:)
|
||||
Usage.track("Using try_variable_find_in_environment")
|
||||
@environments.each do |environment|
|
||||
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
|
||||
if !found_variable.nil? || @strict_variables && raise_on_not_found
|
||||
return found_variable
|
||||
end
|
||||
|
||||
Usage.track("try_variable_find_in_environment reports Nil but responds to key") if environment.key?(key)
|
||||
end
|
||||
@static_environments.each do |environment|
|
||||
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
|
||||
if !found_variable.nil? || @strict_variables && raise_on_not_found
|
||||
return found_variable
|
||||
end
|
||||
|
||||
Usage.track("try_variable_find_in_environment reports Nil but responds to key") if environment.key?(key)
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user