2011-01-12 09:16:55 -05:00
|
|
|
require 'active_support/inflector/methods'
|
2009-04-22 20:41:28 -04:00
|
|
|
|
2009-04-18 00:29:30 -04:00
|
|
|
module ActiveSupport
|
|
|
|
module Deprecation
|
|
|
|
class DeprecationProxy #:nodoc:
|
2010-07-21 19:46:38 -04:00
|
|
|
def self.new(*args, &block)
|
|
|
|
object = args.first
|
2010-07-26 12:57:29 -04:00
|
|
|
|
2010-07-21 19:46:38 -04:00
|
|
|
return object unless object
|
|
|
|
super
|
|
|
|
end
|
2010-07-26 12:57:29 -04:00
|
|
|
|
2009-04-26 18:56:08 -04:00
|
|
|
instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ }
|
2009-04-18 00:29:30 -04:00
|
|
|
|
|
|
|
# Don't give a deprecation warning on inspect since test/unit and error
|
|
|
|
# logs rely on it for diagnostics.
|
|
|
|
def inspect
|
|
|
|
target.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def method_missing(called, *args, &block)
|
|
|
|
warn caller, called, args
|
|
|
|
target.__send__(called, *args, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DeprecatedObjectProxy < DeprecationProxy #:nodoc:
|
|
|
|
def initialize(object, message)
|
|
|
|
@object = object
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def target
|
|
|
|
@object
|
|
|
|
end
|
|
|
|
|
|
|
|
def warn(callstack, called, args)
|
|
|
|
ActiveSupport::Deprecation.warn(@message, callstack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
|
|
|
|
# which emits deprecation warnings on any method call (except +inspect+).
|
|
|
|
class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
|
|
|
|
def initialize(instance, method, var = "@#{method}")
|
|
|
|
@instance, @method, @var = instance, method, var
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def target
|
|
|
|
@instance.__send__(@method)
|
|
|
|
end
|
|
|
|
|
|
|
|
def warn(callstack, called, args)
|
|
|
|
ActiveSupport::Deprecation.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-26 15:31:32 -04:00
|
|
|
class DeprecatedConstantProxy < DeprecationProxy #:nodoc:all
|
2009-04-18 00:29:30 -04:00
|
|
|
def initialize(old_const, new_const)
|
|
|
|
@old_const = old_const
|
|
|
|
@new_const = new_const
|
|
|
|
end
|
|
|
|
|
|
|
|
def class
|
|
|
|
target.class
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def target
|
2009-04-22 20:41:28 -04:00
|
|
|
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
2009-04-18 00:29:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def warn(callstack, called, args)
|
|
|
|
ActiveSupport::Deprecation.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|