1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/deprecation.rb

27 lines
822 B
Ruby

require "active_support/string_inquirer"
require "active_support/basic_object"
module Rails
class DeprecatedConstant < ActiveSupport::BasicObject
def self.deprecate(old, new)
constant = self.new(old, new)
eval "::#{old} = constant"
end
def initialize(old, new)
@old, @new = old, new
@target = eval "proc { #{new} }"
@warned = false
end
def method_missing(meth, *args, &block)
ActiveSupport::Deprecation.warn("#{@old} is deprecated. Please use #{@new}") unless @warned
@warned = true
@target.call.send(meth, *args, &block)
end
end
DeprecatedConstant.deprecate("RAILS_ROOT", "Rails.root")
DeprecatedConstant.deprecate("RAILS_ENV", "Rails.env")
DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "Rails.logger")
end