aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/metal.rb9
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb4
-rw-r--r--actionpack/lib/action_controller/metal/hide_actions.rb9
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb21
-rw-r--r--actionpack/lib/action_controller/metal/renderers.rb10
-rw-r--r--actionpack/lib/action_controller/metal/request_forgery_protection.rb6
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb7
7 files changed, 43 insertions, 23 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 57627a6f0b..2b35e111ec 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/class/attribute'
module ActionController
# ActionController::Metal provides a way to get a valid Rack application from a controller.
@@ -90,7 +90,12 @@ module ActionController
end
end
- extlib_inheritable_accessor(:middleware_stack) { ActionDispatch::MiddlewareStack.new }
+ class_attribute :middleware_stack
+ self.middleware_stack = ActionDispatch::MiddlewareStack.new
+
+ def self.inherited(base)
+ self.middleware_stack = base.middleware_stack.dup
+ end
def self.use(*args)
middleware_stack.use(*args)
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index 05843a061b..1b5a4c3080 100644
--- a/actionpack/lib/action_controller/metal/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute'
+
module ActionController
# The Rails framework provides a large number of helpers for working with +assets+, +dates+, +forms+,
# +numbers+ and model objects, to name a few. These helpers are available to all templates
@@ -50,7 +52,7 @@ module ActionController
include AbstractController::Helpers
included do
- extlib_inheritable_accessor(:helpers_path)
+ class_attribute :helpers_path
self.helpers_path = []
end
diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb
index cdacdc40a6..e893acffdf 100644
--- a/actionpack/lib/action_controller/metal/hide_actions.rb
+++ b/actionpack/lib/action_controller/metal/hide_actions.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute'
+
module ActionController
# ActionController::HideActions adds the ability to prevent public methods on a controller
# to be called as actions.
@@ -5,7 +7,8 @@ module ActionController
extend ActiveSupport::Concern
included do
- extlib_inheritable_accessor(:hidden_actions) { Set.new }
+ class_attribute :hidden_actions
+ self.hidden_actions = Set.new
end
private
@@ -14,7 +17,7 @@ module ActionController
# action name is in the list of hidden actions.
def action_method?(action_name)
self.class.visible_action?(action_name) do
- !hidden_actions.include?(action_name) && super
+ !self.class.hidden_actions.include?(action_name) && super
end
end
@@ -24,7 +27,7 @@ module ActionController
# ==== Parameters
# *args<#to_s>:: A list of actions
def hide_action(*args)
- hidden_actions.merge(args.map! {|a| a.to_s })
+ self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s))
end
def inherited(klass)
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index 08599d660e..e70a20b2be 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -1,11 +1,12 @@
require 'abstract_controller/collector'
+require 'active_support/core_ext/class/attribute'
module ActionController #:nodoc:
module MimeResponds #:nodoc:
extend ActiveSupport::Concern
included do
- extlib_inheritable_accessor :responder, :mimes_for_respond_to, :instance_writer => false
+ class_attribute :responder, :mimes_for_respond_to
self.responder = ActionController::Responder
clear_respond_to
end
@@ -38,18 +39,20 @@ module ActionController #:nodoc:
only_actions = Array(options.delete(:only))
except_actions = Array(options.delete(:except))
+ new = mimes_for_respond_to.dup
mimes.each do |mime|
mime = mime.to_sym
- mimes_for_respond_to[mime] = {}
- mimes_for_respond_to[mime][:only] = only_actions unless only_actions.empty?
- mimes_for_respond_to[mime][:except] = except_actions unless except_actions.empty?
+ new[mime] = {}
+ new[mime][:only] = only_actions unless only_actions.empty?
+ new[mime][:except] = except_actions unless except_actions.empty?
end
+ self.mimes_for_respond_to = new.freeze
end
# Clear all mimes in respond_to.
#
def clear_respond_to
- self.mimes_for_respond_to = ActiveSupport::OrderedHash.new
+ self.mimes_for_respond_to = ActiveSupport::OrderedHash.new.freeze
end
end
@@ -218,12 +221,12 @@ module ActionController #:nodoc:
#
def respond_with(*resources, &block)
raise "In order to use respond_with, first you need to declare the formats your " <<
- "controller responds to in the class level" if mimes_for_respond_to.empty?
+ "controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if response = retrieve_response_from_mimes(&block)
options = resources.extract_options!
options.merge!(:default_response => response)
- (options.delete(:responder) || responder).call(self, resources, options)
+ (options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
@@ -235,8 +238,8 @@ module ActionController #:nodoc:
def collect_mimes_from_class_level #:nodoc:
action = action_name.to_sym
- mimes_for_respond_to.keys.select do |mime|
- config = mimes_for_respond_to[mime]
+ self.class.mimes_for_respond_to.keys.select do |mime|
+ config = self.class.mimes_for_respond_to[mime]
if config[:except]
!config[:except].include?(action)
diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb
index c1ba47927a..639b508746 100644
--- a/actionpack/lib/action_controller/metal/renderers.rb
+++ b/actionpack/lib/action_controller/metal/renderers.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute'
+
module ActionController
def self.add_renderer(key, &block)
Renderers.add(key, &block)
@@ -7,8 +9,8 @@ module ActionController
extend ActiveSupport::Concern
included do
- extlib_inheritable_accessor :_renderers
- self._renderers = {}
+ class_attribute :_renderers
+ self._renderers = {}.freeze
end
module ClassMethods
@@ -30,9 +32,11 @@ module ActionController
end
def use_renderers(*args)
+ new = _renderers.dup
args.each do |key|
- _renderers[key] = RENDERERS[key]
+ new[key] = RENDERERS[key]
end
+ self._renderers = new.freeze
_write_render_options
end
alias use_renderer use_renderers
diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
index f1fb4d7ce5..276c703307 100644
--- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb
+++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute'
+
module ActionController #:nodoc:
class InvalidAuthenticityToken < ActionControllerError #:nodoc:
end
@@ -13,7 +15,7 @@ module ActionController #:nodoc:
cattr_accessor :request_forgery_protection_token
# Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode.
- extlib_inheritable_accessor :allow_forgery_protection
+ class_attribute :allow_forgery_protection
self.allow_forgery_protection = true
helper_method :form_authenticity_token
@@ -107,7 +109,7 @@ module ActionController #:nodoc:
end
def protect_against_forgery?
- allow_forgery_protection
+ self.class.allow_forgery_protection
end
end
end
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index 387e6a554b..51702368c1 100644
--- a/actionpack/lib/action_controller/metal/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute'
+
module ActionController
# In <b>routes.rb</b> one defines URL-to-controller mappings, but the reverse
# is also possible: an URL can be generated from one of your routing definitions.
@@ -85,9 +87,8 @@ module ActionController
included do
ActionController::Routing::Routes.install_helpers(self)
- extlib_inheritable_accessor :default_url_options,
- :instance_writer => false, :instance_reader => false
- self.default_url_options ||= {}
+ class_attribute :default_url_options
+ self.default_url_options = {}
end
# Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in