aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/deprecation.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-17 09:04:21 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-17 09:04:21 -0800
commitee190b8e6db5a11beb682ee3487b605d7608ff17 (patch)
tree2346d33a3dab765d501e357a242a6656844b113b /railties/lib/rails/deprecation.rb
parent98081cbe06c389bb022d777ce03a7054061ceca5 (diff)
parent6f8159c4217dc8433a2027ced0c61e7ce94551d3 (diff)
downloadrails-ee190b8e6db5a11beb682ee3487b605d7608ff17.tar.gz
rails-ee190b8e6db5a11beb682ee3487b605d7608ff17.tar.bz2
rails-ee190b8e6db5a11beb682ee3487b605d7608ff17.zip
Merge pull request #4500 from kennyj/should_deprecate_rails_cache
[Proposal] We should deprecate the RAILS_CACHE constant.
Diffstat (limited to 'railties/lib/rails/deprecation.rb')
-rw-r--r--railties/lib/rails/deprecation.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb
new file mode 100644
index 0000000000..71adcd61f4
--- /dev/null
+++ b/railties/lib/rails/deprecation.rb
@@ -0,0 +1,39 @@
+require "active_support/string_inquirer"
+require "active_support/basic_object"
+
+module Rails
+ module Initializer
+ def self.run(&block)
+ klass = Class.new(Rails::Application)
+ klass.instance_exec(klass.config, &block)
+ klass.initialize!
+ end
+ end
+
+ 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 = ::Kernel.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 = @target.call
+ if target.respond_to?(meth)
+ target.send(meth, *args, &block)
+ else
+ super
+ end
+ end
+ end
+
+ DeprecatedConstant.deprecate("RAILS_CACHE", "::Rails.cache")
+end