aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/helpers.rb10
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb8
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb18
-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
-rw-r--r--actionpack/lib/action_view/base.rb3
-rw-r--r--actionpack/lib/action_view/template/handler.rb4
-rw-r--r--actionpack/lib/action_view/template/resolver.rb3
13 files changed, 72 insertions, 40 deletions
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index eb621c0865..578b884a4d 100644
--- a/actionpack/lib/abstract_controller/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
@@ -1,4 +1,6 @@
require 'active_support/dependencies'
+require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/module/delegation'
module AbstractController
module Helpers
@@ -12,10 +14,10 @@ module AbstractController
end
included do
- extlib_inheritable_accessor(:_helpers) { Module.new }
- extlib_inheritable_accessor(:_helper_serial) do
- AbstractController::Helpers.next_serial
- end
+ class_attribute :_helpers, :_helper_serial
+ delegate :_helpers, :to => :'self.class'
+ self._helpers = Module.new
+ self._helper_serial = ::AbstractController::Helpers.next_serial
end
module ClassMethods
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index 56ddf9bf01..0d214396aa 100644
--- a/actionpack/lib/abstract_controller/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/module/delegation'
+
module AbstractController
# Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
# repeated setups. The inclusion pattern has pages that look like this:
@@ -161,8 +164,9 @@ module AbstractController
include Rendering
included do
- extlib_inheritable_accessor(:_layout_conditions) { Hash.new }
- extlib_inheritable_accessor(:_action_has_layout) { Hash.new }
+ class_attribute :_layout_conditions
+ delegate :_layout_conditions, :to => :'self.class'
+ self._layout_conditions = {}
_write_layout_method
end
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index ac407bda5e..619a49571b 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -1,4 +1,7 @@
require "abstract_controller/base"
+require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/array/wrap'
module AbstractController
class DoubleRenderError < Error
@@ -13,8 +16,9 @@ module AbstractController
extend ActiveSupport::Concern
included do
- extlib_inheritable_accessor :_view_paths
- self._view_paths ||= ActionView::PathSet.new
+ class_attribute :_view_paths
+ delegate :_view_paths, :to => :'self.class'
+ self._view_paths = ActionView::PathSet.new
end
# An instance of a view class. The default view class is ActionView::Base
@@ -156,7 +160,6 @@ module AbstractController
elsif options.key?(:file)
options[:_template_name] = options[:file]
end
-
name = (options[:_template_name] || options[:action] || action_name).to_s
options[:_prefix] ||= _prefix if (options.keys & [:partial, :file, :template]).empty?
@@ -201,7 +204,7 @@ module AbstractController
# the default view path. You may also provide a custom view path
# (see ActionView::ViewPathSet for more information)
def append_view_path(path)
- self.view_paths << path
+ self.view_paths = view_paths.dup + Array.wrap(path)
end
# Prepend a path to the list of view paths for this controller.
@@ -212,12 +215,12 @@ module AbstractController
# (see ActionView::ViewPathSet for more information)
def prepend_view_path(path)
clear_template_caches!
- self.view_paths.unshift(path)
+ self.view_paths = Array.wrap(path) + view_paths.dup
end
# A list of all of the default view paths for this controller.
def view_paths
- self._view_paths
+ _view_paths
end
# Set the view paths.
@@ -228,7 +231,8 @@ module AbstractController
def view_paths=(paths)
clear_template_caches!
self._view_paths = paths.is_a?(ActionView::PathSet) ? paths : ActionView::Base.process_view_paths(paths)
+ _view_paths.freeze
end
end
end
-end \ No newline at end of file
+end
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
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 148d507f1c..4096c296c3 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/module/attr_internal'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/class/attribute'
module ActionView #:nodoc:
class ActionViewError < StandardError #:nodoc:
@@ -244,7 +245,7 @@ module ActionView #:nodoc:
ActionView::PathSet.new(Array(value))
end
- extlib_inheritable_accessor :helpers
+ class_attribute :helpers
attr_reader :helpers
def self.for_controller(controller)
diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb
index 221d1bd5c5..8ecc911519 100644
--- a/actionpack/lib/action_view/template/handler.rb
+++ b/actionpack/lib/action_view/template/handler.rb
@@ -1,5 +1,5 @@
-require "active_support/core_ext/class/inheritable_attributes"
require "action_dispatch/http/mime_type"
+require 'active_support/core_ext/class/attribute'
# Legacy TemplateHandler stub
module ActionView
@@ -23,7 +23,7 @@ module ActionView
end
class Template::Handler
- extlib_inheritable_accessor :default_format
+ class_attribute :default_format
self.default_format = Mime::HTML
def self.call(template)
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index af5d6f6d18..6878067f7c 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -1,5 +1,6 @@
require "pathname"
require "active_support/core_ext/class"
+require "active_support/core_ext/array/wrap"
require "action_view/template"
module ActionView
@@ -11,7 +12,7 @@ module ActionView
def self.register_detail(name, options = {})
registered_details[name] = lambda do |val|
- val ||= yield
+ val = Array.wrap(val || yield)
val |= [nil] unless options[:allow_nil] == false
val
end