From e76677e69521fc0bb44352c197fb28d3226cf8a5 Mon Sep 17 00:00:00 2001 From: Edwin Cruz Date: Fri, 23 Oct 2020 12:34:23 -0500 Subject: [PATCH] Extend Spree::DeprecatedInstanceVariableProxy to work with methods or variables Previous impleemntation was only working with either attribute readers or methods, but it was not working with instance variables. It now checks whether the final target is either a method, property or an instance variable --- core/lib/spree/deprecation.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/lib/spree/deprecation.rb b/core/lib/spree/deprecation.rb index 29ca2ede097..dea78ba5ba0 100644 --- a/core/lib/spree/deprecation.rb +++ b/core/lib/spree/deprecation.rb @@ -33,9 +33,9 @@ module Spree # # Default deprecator is Spree::Deprecation. class DeprecatedInstanceVariableProxy < ActiveSupport::Deprecation::DeprecationProxy - def initialize(instance, method, var = "@#{method}", deprecator = Spree::Deprecation, message = nil) + def initialize(instance, method_or_var, var = "@#{method}", deprecator = Spree::Deprecation, message = nil) @instance = instance - @method = method + @method_or_var = method_or_var @var = var @deprecator = deprecator @message = message @@ -44,12 +44,14 @@ def initialize(instance, method, var = "@#{method}", deprecator = Spree::Depreca private def target - @instance.__send__(@method) + return @instance.instance_variable_get(@method_or_var) if @instance.instance_variable_defined?(@method_or_var) + + @instance.__send__(@method_or_var) end def warn(callstack, called, args) - message = @message || "#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}." - message = [message, "Args: #{args.inspect}"].join(" ") + message = @message || "#{@var} is deprecated! Call #{@method_or_var}.#{called} instead of #{@var}.#{called}." + message = [message, "Args: #{args.inspect}"].join(" ") unless args.empty? @deprecator.warn(message, callstack) end