Class: ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
DeprecationProxy
|
|
Instance Chain:
self,
DeprecationProxy
|
|
Inherits: |
ActiveSupport::Deprecation::DeprecationProxy
|
Defined in: | activesupport/lib/active_support/deprecation/proxy_wrappers.rb |
Overview
DeprecatedInstanceVariableProxy
transforms an instance variable into a deprecated one. It takes an instance of a class, a method on that class, an instance variable, and a deprecator as the last argument.
Trying to use the deprecated instance variable will result in a deprecation warning, pointing to the method as a replacement.
class Example
def initialize
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, ActiveSupport::Deprecation.new)
@_request = :special_request
end
def request
@_request
end
def old_request
@request
end
end
example = Example.new
# => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
example.old_request.to_s
# => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
@request.to_s
(Backtrace information…)
"special_request"
example.request.to_s
# => "special_request"
Class Method Summary
- .new(instance, method, var = "@#{method}", deprecator:) ⇒ DeprecatedInstanceVariableProxy constructor
DeprecationProxy
- Inherited
Instance Method Summary
- #target private
- #warn(callstack, called, args) private
DeprecationProxy
- Inherited
#inspect | Don’t give a deprecation warning on inspect since test/unit and error logs rely on it for diagnostics. |
#method_missing |
Constructor Details
.new(instance, method, var = "@#{method}", deprecator:) ⇒ DeprecatedInstanceVariableProxy
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 88
def initialize(instance, method, var = "@#{method}", deprecator:) @instance = instance @method = method @var = var @deprecator = deprecator end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveSupport::Deprecation::DeprecationProxy
Instance Method Details
#target (private)
[ GitHub ]# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 96
def target @instance.__send__(@method) end