mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix up constant deprecation to be less dependent on load order
This commit is contained in:
parent
0aefbe52a0
commit
dbb547a056
1 changed files with 20 additions and 55 deletions
|
@ -1,62 +1,27 @@
|
||||||
require "active_support/string_inquirer"
|
require "active_support/string_inquirer"
|
||||||
require "active_support/deprecation"
|
require "active_support/basic_object"
|
||||||
|
|
||||||
RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
|
module Rails
|
||||||
cattr_accessor :warned
|
class DeprecatedConstant < ActiveSupport::BasicObject
|
||||||
self.warned = false
|
def self.deprecate(old, new)
|
||||||
|
constant = self.new(old, new)
|
||||||
|
eval "::#{old} = constant"
|
||||||
|
end
|
||||||
|
|
||||||
def target
|
def initialize(old, new)
|
||||||
Rails.root
|
@old, @new = old, new
|
||||||
end
|
@target = eval "proc { #{new} }"
|
||||||
|
@warned = false
|
||||||
|
end
|
||||||
|
|
||||||
def replace(*args)
|
def method_missing(meth, *args, &block)
|
||||||
warn(caller, :replace, *args)
|
ActiveSupport::Deprecation.warn("#{@old} is deprecated. Please use #{@new}") unless @warned
|
||||||
end
|
@warned = true
|
||||||
|
@target.call.send(meth, *args, &block)
|
||||||
def warn(callstack, called, args)
|
|
||||||
unless warned
|
|
||||||
ActiveSupport::Deprecation.warn("RAILS_ROOT is deprecated! Use Rails.root instead", callstack)
|
|
||||||
self.warned = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end).new
|
|
||||||
|
|
||||||
RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
|
DeprecatedConstant.deprecate("RAILS_ROOT", "Rails.root")
|
||||||
cattr_accessor :warned
|
DeprecatedConstant.deprecate("RAILS_ENV", "Rails.env")
|
||||||
self.warned = false
|
DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "Rails.logger")
|
||||||
|
end
|
||||||
def target
|
|
||||||
Rails.env
|
|
||||||
end
|
|
||||||
|
|
||||||
def replace(*args)
|
|
||||||
warn(caller, :replace, *args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def warn(callstack, called, args)
|
|
||||||
unless warned
|
|
||||||
ActiveSupport::Deprecation.warn("RAILS_ENV is deprecated! Use Rails.env instead", callstack)
|
|
||||||
self.warned = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end).new
|
|
||||||
|
|
||||||
RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
|
|
||||||
cattr_accessor :warned
|
|
||||||
self.warned = false
|
|
||||||
|
|
||||||
def target
|
|
||||||
Rails.logger
|
|
||||||
end
|
|
||||||
|
|
||||||
def replace(*args)
|
|
||||||
warn(caller, :replace, *args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def warn(callstack, called, args)
|
|
||||||
unless warned
|
|
||||||
ActiveSupport::Deprecation.warn("RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead", callstack)
|
|
||||||
self.warned = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end).new
|
|
||||||
|
|
Loading…
Reference in a new issue