aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-08-03 16:03:35 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-08-26 23:11:52 -0700
commitdbb547a0565dd216089f35d82fcf17a655897603 (patch)
treef3bbc234648dc77a6711d9cb6dd1d0ab54af870d /railties
parent0aefbe52a08d60184c05a91173ad2eb256fb50c0 (diff)
downloadrails-dbb547a0565dd216089f35d82fcf17a655897603.tar.gz
rails-dbb547a0565dd216089f35d82fcf17a655897603.tar.bz2
rails-dbb547a0565dd216089f35d82fcf17a655897603.zip
Fix up constant deprecation to be less dependent on load order
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/deprecation.rb73
1 files changed, 19 insertions, 54 deletions
diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb
index 1eb6d804b6..924701a326 100644
--- a/railties/lib/rails/deprecation.rb
+++ b/railties/lib/rails/deprecation.rb
@@ -1,62 +1,27 @@
require "active_support/string_inquirer"
-require "active_support/deprecation"
+require "active_support/basic_object"
-RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
- cattr_accessor :warned
- self.warned = false
-
- def target
- Rails.root
- end
-
- def replace(*args)
- warn(caller, :replace, *args)
- end
-
- def warn(callstack, called, args)
- unless warned
- ActiveSupport::Deprecation.warn("RAILS_ROOT is deprecated! Use Rails.root instead", callstack)
- self.warned = true
+module Rails
+ class DeprecatedConstant < ActiveSupport::BasicObject
+ def self.deprecate(old, new)
+ constant = self.new(old, new)
+ eval "::#{old} = constant"
end
- end
-end).new
-
-RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
- cattr_accessor :warned
- self.warned = false
-
- 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
+ def initialize(old, new)
+ @old, @new = old, new
+ @target = eval "proc { #{new} }"
+ @warned = false
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
+ 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
-end).new
+
+ DeprecatedConstant.deprecate("RAILS_ROOT", "Rails.root")
+ DeprecatedConstant.deprecate("RAILS_ENV", "Rails.env")
+ DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "Rails.logger")
+end