aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-01-18 01:53:09 +0900
committerkennyj <kennyj@gmail.com>2012-01-18 01:53:09 +0900
commit6f8159c4217dc8433a2027ced0c61e7ce94551d3 (patch)
treed61c8f237d88fd5f8702a98f128e0d9ea58ae393 /railties/lib/rails
parent4280b20cde6d0ec4694f25288832d098c83cceba (diff)
downloadrails-6f8159c4217dc8433a2027ced0c61e7ce94551d3.tar.gz
rails-6f8159c4217dc8433a2027ced0c61e7ce94551d3.tar.bz2
rails-6f8159c4217dc8433a2027ced0c61e7ce94551d3.zip
Deprecate RAILS_CACHE constant.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application/bootstrap.rb8
-rw-r--r--railties/lib/rails/deprecation.rb39
2 files changed, 43 insertions, 4 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index f96a7d1772..d55ec982ec 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -50,11 +50,11 @@ module Rails
# Initialize cache early in the stack so railties can make use of it.
initializer :initialize_cache, :group => :all do
- unless defined?(RAILS_CACHE)
- silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) }
+ unless Rails.cache
+ Rails.cache = ActiveSupport::Cache.lookup_store(config.cache_store)
- if RAILS_CACHE.respond_to?(:middleware)
- config.middleware.insert_before("Rack::Runtime", RAILS_CACHE.middleware)
+ if Rails.cache.respond_to?(:middleware)
+ config.middleware.insert_before("Rack::Runtime", Rails.cache.middleware)
end
end
end
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