123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Deprecation::DeprecatedConstantProxy

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Module
Instance Chain:
Inherits: Module
Defined in: activesupport/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

::Module - Inherited

DelegationError

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

::Module - Inherited

#anonymous?

A module may or may not have a name.

Instance Method Summary

::Module - Inherited

#alias_attribute

Allows you to make aliases for attributes, which includes getter, setter, and a predicate.

#attr_internal
#attr_internal_accessor

Declares an attribute reader and writer backed by an internally-named instance variable.

#attr_internal_reader

Declares an attribute reader backed by an internally-named instance variable.

#attr_internal_writer

Declares an attribute writer backed by an internally-named instance variable.

#cattr_accessor
#cattr_reader
#cattr_writer
#deep_dup

Returns a copy of module or class if it’s anonymous.

#delegate

Provides a delegate class method to easily expose contained objects’ public methods as your own.

#delegate_missing_to

When building decorators, a common pattern may emerge:

#deprecate

deprecate :foo, deprecator: MyLib.deprecator

#mattr_accessor

Defines both class and instance accessors for class attributes.

#mattr_reader

Defines a class attribute and creates a class and instance reader methods.

#mattr_writer

Defines a class attribute and creates a class and instance writer methods to allow assignment to the attribute.

#module_parent

Returns the module which contains this one according to its name.

#module_parent_name

Returns the name of the module containing this one.

#module_parents

Returns all the parents of this module according to its name, ordered from nested outwards.

#redefine_method

Replaces the existing method definition, if there is one, with the passed block as its body.

#redefine_singleton_method

Replaces the existing singleton method definition, if there is one, with the passed block as its body.

#remove_possible_method

Removes the named method, if it exists.

#remove_possible_singleton_method

Removes the named singleton method, if it exists.

#silence_redefinition_of_method

Marks the named method as intended to be redefined, if it exists.

#thread_cattr_accessor
#thread_cattr_reader
#thread_cattr_writer
#thread_mattr_accessor

Defines both class and instance accessors for class attributes.

#attr_internal_define, #as_json, #method_visibility,
#thread_mattr_reader

Defines a per-thread class attribute and creates class and instance reader methods.

#thread_mattr_writer

Defines a per-thread class attribute and creates a class and instance writer methods to allow assignment to the attribute.

::Module::Concerning - Included

#concern

A low-cruft shortcut to define a concern.

#concerning

Define a new concern and mix it in.

Constructor Details

.new(*args, **options, &block) ⇒ DeprecatedConstantProxy

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 121

def self.new(*args, **options, &block)
  object = args.first

  return object unless object
  super
end

#initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.") ⇒ DeprecatedConstantProxy

[ GitHub ]

  
# File 'activesupport/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 = message
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 183

def method_missing(...)
  @deprecator.warn(@message, caller_locations)
  target.__send__(...)
end

Instance Attribute Details

#hash (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 147

delegate :hash, :instance_methods, :name, :respond_to?, to: :target

#instance_methods (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 147

delegate :hash, :instance_methods, :name, :respond_to?, to: :target

#name (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 147

delegate :hash, :instance_methods, :name, :respond_to?, to: :target

Instance Method Details

#append_features(base)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 158

def append_features(base)
  @deprecator.warn(@message, caller_locations)
  base.include(target)
end

#class

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
[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 154

def class
  target.class
end

#const_missing(name) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 178

def const_missing(name)
  @deprecator.warn(@message, caller_locations)
  target.const_get(name)
end

#extended(base)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 168

def extended(base)
  @deprecator.warn(@message, caller_locations)
  base.extend(target)
end

#inspect

Don’t give a deprecation warning on inspect since test/unit and error logs rely on it for diagnostics.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 141

def inspect
  target.inspect
end

#prepend_features(base)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 163

def prepend_features(base)
  @deprecator.warn(@message, caller_locations)
  base.prepend(target)
end

#respond_to?Boolean

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 147

delegate :hash, :instance_methods, :name, :respond_to?, to: :target

#target (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/proxy_wrappers.rb', line 174

def target
  ActiveSupport::Inflector.constantize(@new_const.to_s)
end