diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/deprecation.rb | 39 |
3 files changed, 49 insertions, 5 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 658756ad51..77a09507a8 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -8,6 +8,7 @@ require 'active_support/core_ext/array/extract_options' require 'rails/application' require 'rails/version' +require 'rails/deprecation' require 'active_support/railtie' require 'action_dispatch/railtie' @@ -77,7 +78,11 @@ module Rails end def cache - RAILS_CACHE + @@cache ||= nil + end + + def cache=(cache) + @@cache = cache end # Returns all rails groups for loading based on: 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 |