Class: ActiveSupport::Deprecation::DeprecatedConstantProxy
- Defined in:
 - lib/active_support/deprecation/proxy_wrappers.rb
 
Overview
DeprecatedConstantProxy transforms a constant into a deprecated one. It takes the full names of an old (deprecated) constant and of a new constant (both in string form) and a deprecator. 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", ActiveSupport::Deprecation.new)
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"]
  Constant Summary
Constants inherited from Module
Class Method Summary collapse
Instance Method Summary collapse
- #append_features(base) ⇒ Object
 - 
  
    
      #class  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the class of the new constant.
 - #extended(base) ⇒ Object
 - 
  
    
      #initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.")  ⇒ DeprecatedConstantProxy 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of DeprecatedConstantProxy.
 - 
  
    
      #inspect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Don’t give a deprecation warning on inspect since test/unit and error logs rely on it for diagnostics.
 - #prepend_features(base) ⇒ Object
 
Methods inherited from Module
#alias_attribute, #anonymous?, #as_json, #attr_internal_accessor, #attr_internal_reader, #attr_internal_writer, #deep_dup, #delegate, #delegate_missing_to, #deprecate, #mattr_accessor, #mattr_reader, #mattr_writer, #method_visibility, #module_parent, #module_parent_name, #module_parents, #redefine_method, #redefine_singleton_method, #remove_possible_method, #remove_possible_singleton_method, #silence_redefinition_of_method, #thread_mattr_accessor, #thread_mattr_reader, #thread_mattr_writer
Methods included from Module::Concerning
Constructor Details
#initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.") ⇒ DeprecatedConstantProxy
Returns a new instance of DeprecatedConstantProxy.
      128 129 130 131 132 133 134 135  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 128 def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.") Kernel.require "active_support/inflector/methods" @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
#method_missing ⇒ Object (private)
      183 184 185 186  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 183 def method_missing(...) @deprecator.warn(@message, caller_locations) target.__send__(...) end  | 
  
Class Method Details
.new(*args, **options, &block) ⇒ Object
      121 122 123 124 125 126  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 121 def self.new(*args, **, &block) object = args.first return object unless object super end  | 
  
Instance Method Details
#append_features(base) ⇒ Object
      158 159 160 161  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 158 def append_features(base) @deprecator.warn(@message, caller_locations) base.include(target) end  | 
  
#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
  
      154 155 156  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 154 def class target.class end  | 
  
#extended(base) ⇒ Object
      168 169 170 171  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 168 def extended(base) @deprecator.warn(@message, caller_locations) base.extend(target) end  | 
  
#inspect ⇒ Object
Don’t give a deprecation warning on inspect since test/unit and error logs rely on it for diagnostics.
      141 142 143  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 141 def inspect target.inspect end  | 
  
#prepend_features(base) ⇒ Object
      163 164 165 166  | 
    
      # File 'lib/active_support/deprecation/proxy_wrappers.rb', line 163 def prepend_features(base) @deprecator.warn(@message, caller_locations) base.prepend(target) end  |