Class: Rails::DeprecatedConstant

Inherits:
ActiveSupport::BasicObject
Defined in:
lib/rails/deprecation.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old, new) ⇒ DeprecatedConstant

Returns a new instance of DeprecatedConstant.


19
20
21
22
23
# File 'lib/rails/deprecation.rb', line 19

def initialize(old, new)
  @old, @new = old, new
  @target = ::Kernel.eval "proc { #{@new} }"
  @warned = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/deprecation.rb', line 25

def method_missing(meth, *args, &block)
  ::ActiveSupport::Deprecation.warn("#{@old} is deprecated. Please use #{@new}") unless @warned
  @warned = true

  target = @target.call
  if target.respond_to?(meth)
    target.send(meth, *args, &block)
  else
    super
  end
end

Class Method Details

.deprecate(old, new) ⇒ Object


14
15
16
17
# File 'lib/rails/deprecation.rb', line 14

def self.deprecate(old, new)
  constant = self.new(old, new)
  eval "::#{old} = constant"
end