Class: ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy

Inherits:
DeprecationProxy show all
Defined in:
activesupport/lib/active_support/deprecation/proxy_wrappers.rb

Overview

This DeprecatedInstanceVariableProxy transforms instance variable to deprecated instance variable.

class Example
  def initialize(deprecator)
    @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
    @_request = :a_request
  end

  def request
    @_request
  end

  def old_request
    @request
  end
end

When someone execute any method on @request variable this will trigger warn method on deprecator_instance and will fetch @_request variable via request method and execute the same method on non-proxy instance variable.

Default deprecator is ActiveSupport::Deprecation.

Instance Method Summary collapse

Methods inherited from DeprecationProxy

#inspect, new

Constructor Details

#initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance) ⇒ DeprecatedInstanceVariableProxy

Returns a new instance of DeprecatedInstanceVariableProxy.



79
80
81
82
83
84
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 79

def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance)
  @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