aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/abstract
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/abstract')
-rw-r--r--actionpack/lib/action_controller/abstract/base.rb38
-rw-r--r--actionpack/lib/action_controller/abstract/benchmarker.rb10
-rw-r--r--actionpack/lib/action_controller/abstract/callbacks.rb27
-rw-r--r--actionpack/lib/action_controller/abstract/exceptions.rb4
-rw-r--r--actionpack/lib/action_controller/abstract/helpers.rb13
-rw-r--r--actionpack/lib/action_controller/abstract/layouts.rb29
-rw-r--r--actionpack/lib/action_controller/abstract/logger.rb14
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb32
8 files changed, 93 insertions, 74 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb
index 0e4803388a..87083a4d79 100644
--- a/actionpack/lib/action_controller/abstract/base.rb
+++ b/actionpack/lib/action_controller/abstract/base.rb
@@ -2,28 +2,27 @@ require 'active_support/core_ext/module/attr_internal'
module AbstractController
class Error < StandardError; end
-
+
class DoubleRenderError < Error
DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
def initialize(message = nil)
super(message || DEFAULT_MESSAGE)
end
- end
-
+ end
+
class Base
-
attr_internal :response_body
attr_internal :response_obj
attr_internal :action_name
class << self
- attr_reader :abstract
-
+ attr_reader :abstract
+
def abstract!
@abstract = true
end
-
+
alias_method :abstract?, :abstract
def inherited(klass)
@@ -34,13 +33,13 @@ module AbstractController
def subclasses
@subclasses ||= []
end
-
+
def internal_methods
controller = self
controller = controller.superclass until controller.abstract?
controller.public_instance_methods(true)
end
-
+
def process(action)
new.process(action.to_s)
end
@@ -48,7 +47,7 @@ module AbstractController
def hidden_actions
[]
end
-
+
def action_methods
@action_methods ||=
# All public instance methods of this class, including ancestors
@@ -61,13 +60,13 @@ module AbstractController
hidden_actions
end
end
-
+
abstract!
-
+
def initialize
self.response_obj = {}
end
-
+
def process(action)
@_action_name = action_name = action.to_s
@@ -78,26 +77,27 @@ module AbstractController
process_action(action_name)
self
end
-
+
private
-
def action_methods
self.class.action_methods
end
-
+
def action_method?(action)
action_methods.include?(action)
end
-
+
# It is possible for respond_to?(action_name) to be false and
# respond_to?(:action_missing) to be false if respond_to_action?
# is overridden in a subclass. For instance, ActionController::Base
# overrides it to include the case where a template matching the
# action_name is found.
def process_action(method_name)
- send(method_name)
+ send_action(method_name)
end
+ alias send_action send
+
def _handle_action_missing
action_missing(@_action_name)
end
@@ -112,4 +112,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb
index 9f5889c704..07294cede3 100644
--- a/actionpack/lib/action_controller/abstract/benchmarker.rb
+++ b/actionpack/lib/action_controller/abstract/benchmarker.rb
@@ -1,9 +1,9 @@
module AbstractController
module Benchmarker
- extend ActiveSupport::DependencyModule
-
- depends_on Logger
-
+ extend ActiveSupport::Concern
+
+ include Logger
+
module ClassMethods
def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true)
if logger && logger.level >= log_level
@@ -25,4 +25,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb
index e4f9dd3112..affe053bac 100644
--- a/actionpack/lib/action_controller/abstract/callbacks.rb
+++ b/actionpack/lib/action_controller/abstract/callbacks.rb
@@ -1,8 +1,8 @@
module AbstractController
module Callbacks
- extend ActiveSupport::DependencyModule
+ extend ActiveSupport::Concern
- depends_on ActiveSupport::NewCallbacks
+ include ActiveSupport::NewCallbacks
included do
define_callbacks :process_action, "response_body"
@@ -13,7 +13,7 @@ module AbstractController
super
end
end
-
+
module ClassMethods
def _normalize_callback_options(options)
if only = options[:only]
@@ -21,11 +21,17 @@ module AbstractController
options[:per_key] = {:if => only}
end
if except = options[:except]
- except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
+ except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
options[:per_key] = {:unless => except}
end
end
-
+
+ def skip_filter(*names, &blk)
+ skip_before_filter(*names, &blk)
+ skip_after_filter(*names, &blk)
+ skip_around_filter(*names, &blk)
+ end
+
[:before, :after, :around].each do |filter|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{filter}_filter(*names, &blk)
@@ -37,6 +43,15 @@ module AbstractController
end
end
+ def prepend_#{filter}_filter(*names, &blk)
+ options = names.last.is_a?(Hash) ? names.pop : {}
+ _normalize_callback_options(options)
+ names.push(blk) if block_given?
+ names.each do |name|
+ process_action_callback(:#{filter}, name, options.merge(:prepend => true))
+ end
+ end
+
def skip_#{filter}_filter(*names, &blk)
options = names.last.is_a?(Hash) ? names.pop : {}
_normalize_callback_options(options)
@@ -51,4 +66,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/action_controller/abstract/exceptions.rb
index ec4680629b..2f6c55f068 100644
--- a/actionpack/lib/action_controller/abstract/exceptions.rb
+++ b/actionpack/lib/action_controller/abstract/exceptions.rb
@@ -1,3 +1,3 @@
module AbstractController
- class ActionNotFound < StandardError ; end
-end \ No newline at end of file
+ class ActionNotFound < StandardError; end
+end
diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb
index 41decfd0c7..0a2776de9c 100644
--- a/actionpack/lib/action_controller/abstract/helpers.rb
+++ b/actionpack/lib/action_controller/abstract/helpers.rb
@@ -1,8 +1,8 @@
module AbstractController
module Helpers
- extend ActiveSupport::DependencyModule
+ extend ActiveSupport::Concern
- depends_on Renderer
+ include Renderer
included do
extlib_inheritable_accessor :master_helper_module
@@ -16,12 +16,12 @@ module AbstractController
av
end
end
-
+
module ClassMethods
def inherited(klass)
klass.master_helper_module = Module.new
klass.master_helper_module.__send__ :include, master_helper_module
-
+
super
end
@@ -57,7 +57,7 @@ module AbstractController
ruby_eval
end
end
-
+
def helper(*args, &block)
args.flatten.each do |arg|
case arg
@@ -68,6 +68,5 @@ module AbstractController
master_helper_module.module_eval(&block) if block_given?
end
end
-
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb
index 3d6810bda9..273063f74b 100644
--- a/actionpack/lib/action_controller/abstract/layouts.rb
+++ b/actionpack/lib/action_controller/abstract/layouts.rb
@@ -1,8 +1,8 @@
module AbstractController
module Layouts
- extend ActiveSupport::DependencyModule
+ extend ActiveSupport::Concern
- depends_on Renderer
+ include Renderer
included do
extlib_inheritable_accessor :_layout_conditions
@@ -17,18 +17,18 @@ module AbstractController
conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
self._layout_conditions = conditions
-
+
@_layout = layout || false # Converts nil to false
_write_layout_method
end
-
+
def _implied_layout_name
name.underscore
end
-
+
# Takes the specified layout and creates a _layout method to be called
# by _default_layout
- #
+ #
# If the specified layout is a:
# String:: return the string
# Symbol:: call the method specified by the symbol
@@ -57,11 +57,12 @@ module AbstractController
end
end
end
-
+
private
-
- def _layout(details) end # This will be overwritten
-
+ # This will be overwritten
+ def _layout(details)
+ end
+
# :api: plugin
# ====
# Override this to mutate the inbound layout name
@@ -69,7 +70,7 @@ module AbstractController
unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end
-
+
name && view_paths.find_by_parts(name, details, _layout_prefix(name))
end
@@ -77,7 +78,7 @@ module AbstractController
def _layout_prefix(name)
"layouts"
end
-
+
def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout(details)
raise ArgumentError,
@@ -87,7 +88,7 @@ module AbstractController
begin
_layout_for_name(_layout(details), details) if _action_has_layout?
rescue NameError => e
- raise NoMethodError,
+ raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
end
end
@@ -103,4 +104,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb
index 980ede0bed..d6fa843485 100644
--- a/actionpack/lib/action_controller/abstract/logger.rb
+++ b/actionpack/lib/action_controller/abstract/logger.rb
@@ -3,13 +3,13 @@ require 'active_support/core_ext/logger'
module AbstractController
module Logger
- extend ActiveSupport::DependencyModule
+ extend ActiveSupport::Concern
class DelayedLog
def initialize(&blk)
@blk = blk
end
-
+
def to_s
@blk.call
end
@@ -19,10 +19,10 @@ module AbstractController
included do
cattr_accessor :logger
end
-
+
def process(action)
ret = super
-
+
if logger
log = DelayedLog.new do
"\n\nProcessing #{self.class.name}\##{action_name} " \
@@ -32,14 +32,14 @@ module AbstractController
logger.info(log)
end
-
+
ret
end
-
+
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
- end
+ end
end
end
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index d7c68549e1..dd58c7cb64 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -2,9 +2,9 @@ require "action_controller/abstract/logger"
module AbstractController
module Renderer
- extend ActiveSupport::DependencyModule
+ extend ActiveSupport::Concern
- depends_on AbstractController::Logger
+ include AbstractController::Logger
included do
attr_internal :formats
@@ -15,22 +15,22 @@ module AbstractController
end
def _action_view
- @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
+ @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
end
-
+
def render(*args)
if response_body
raise AbstractController::DoubleRenderError, "OMG"
end
-
+
self.response_body = render_to_body(*args)
end
-
+
# Raw rendering of a template to a Rack-compatible body.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
- #
+ #
# :api: plugin
def render_to_body(options = {})
# TODO: Refactor so we can just use the normal template logic for this
@@ -46,7 +46,7 @@ module AbstractController
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
- #
+ #
# :api: plugin
def render_to_string(options = {})
AbstractController::Renderer.body_to_s(render_to_body(options))
@@ -55,8 +55,10 @@ module AbstractController
def _render_template(options)
_action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial])
end
-
- def view_paths() _view_paths end
+
+ def view_paths()
+ _view_paths
+ end
# Return a string representation of a Rack-compatible response body.
def self.body_to_s(body)
@@ -71,7 +73,6 @@ module AbstractController
end
private
-
def _determine_template(options)
name = (options[:_template_name] || action_name).to_s
@@ -81,15 +82,18 @@ module AbstractController
end
module ClassMethods
-
def append_view_path(path)
self.view_paths << path
end
-
+
+ def prepend_view_path(path)
+ self.view_paths.unshift(path)
+ end
+
def view_paths
self._view_paths
end
-
+
def view_paths=(paths)
self._view_paths = paths.is_a?(ActionView::PathSet) ?
paths : ActionView::Base.process_view_paths(paths)