Class: ActiveSupport::Deprecation::DeprecatedConstantProxy
- Inherits:
-
DeprecationProxy
- Object
- DeprecationProxy
- ActiveSupport::Deprecation::DeprecatedConstantProxy
- Defined in:
- lib/active_support/deprecation/proxy_wrappers.rb
Overview
DeprecatedConstantProxy transforms a constant into a deprecated one. It takes the names of an old (deprecated) constant and of a new constant (both in string form) and optionally a deprecator. The deprecator defaults to ActiveSupport::Deprecator
if none is specified. The deprecated constant now returns the value of the new one.
PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
(In a later update, the original implementation of `PLANETS` has been removed.)
PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
PLANETS.map { |planet| planet.capitalize }
# => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
(Backtrace information…)
["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
Instance Method Summary collapse
-
#class ⇒ Object
Returns the class of the new constant.
-
#initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.") ⇒ DeprecatedConstantProxy
constructor
A new instance of DeprecatedConstantProxy.
Methods inherited from DeprecationProxy
Constructor Details
#initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.") ⇒ DeprecatedConstantProxy
Returns a new instance of DeprecatedConstantProxy.
125 126 127 128 129 130 |
# File 'lib/active_support/deprecation/proxy_wrappers.rb', line 125 def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.") @old_const = old_const @new_const = new_const @deprecator = deprecator @message = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveSupport::Deprecation::DeprecationProxy
Instance Method Details
#class ⇒ Object
Returns the class of the new constant.
PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
PLANETS.class # => Array
137 138 139 |
# File 'lib/active_support/deprecation/proxy_wrappers.rb', line 137 def class target.class end |