actionpack 4.2.10 → 7.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +86 -600
- data/MIT-LICENSE +1 -1
- data/README.rdoc +13 -14
- data/lib/abstract_controller/asset_paths.rb +5 -1
- data/lib/abstract_controller/base.rb +166 -136
- data/lib/abstract_controller/caching/fragments.rb +149 -0
- data/lib/abstract_controller/caching.rb +68 -0
- data/lib/abstract_controller/callbacks.rb +126 -57
- data/lib/abstract_controller/collector.rb +13 -15
- data/lib/abstract_controller/deprecator.rb +9 -0
- data/lib/abstract_controller/error.rb +8 -0
- data/lib/abstract_controller/helpers.rb +181 -132
- data/lib/abstract_controller/logger.rb +5 -1
- data/lib/abstract_controller/railties/routes_helpers.rb +10 -3
- data/lib/abstract_controller/rendering.rb +56 -56
- data/lib/abstract_controller/translation.rb +29 -15
- data/lib/abstract_controller/url_for.rb +15 -11
- data/lib/abstract_controller.rb +21 -5
- data/lib/action_controller/api/api_rendering.rb +18 -0
- data/lib/action_controller/api.rb +154 -0
- data/lib/action_controller/base.rb +219 -155
- data/lib/action_controller/caching.rb +28 -68
- data/lib/action_controller/deprecator.rb +9 -0
- data/lib/action_controller/form_builder.rb +55 -0
- data/lib/action_controller/log_subscriber.rb +35 -22
- data/lib/action_controller/metal/allow_browser.rb +119 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +17 -0
- data/lib/action_controller/metal/conditional_get.rb +259 -122
- data/lib/action_controller/metal/content_security_policy.rb +86 -0
- data/lib/action_controller/metal/cookies.rb +9 -5
- data/lib/action_controller/metal/data_streaming.rb +87 -104
- data/lib/action_controller/metal/default_headers.rb +21 -0
- data/lib/action_controller/metal/etag_with_flash.rb +22 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +35 -26
- data/lib/action_controller/metal/exceptions.rb +71 -24
- data/lib/action_controller/metal/flash.rb +26 -19
- data/lib/action_controller/metal/head.rb +45 -36
- data/lib/action_controller/metal/helpers.rb +80 -64
- data/lib/action_controller/metal/http_authentication.rb +297 -244
- data/lib/action_controller/metal/implicit_render.rb +57 -9
- data/lib/action_controller/metal/instrumentation.rb +76 -64
- data/lib/action_controller/metal/live.rb +238 -176
- data/lib/action_controller/metal/logging.rb +22 -0
- data/lib/action_controller/metal/mime_responds.rb +177 -166
- data/lib/action_controller/metal/parameter_encoding.rb +84 -0
- data/lib/action_controller/metal/params_wrapper.rb +145 -118
- data/lib/action_controller/metal/permissions_policy.rb +38 -0
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +203 -64
- data/lib/action_controller/metal/renderers.rb +108 -65
- data/lib/action_controller/metal/rendering.rb +216 -56
- data/lib/action_controller/metal/request_forgery_protection.rb +496 -163
- data/lib/action_controller/metal/rescue.rb +19 -21
- data/lib/action_controller/metal/streaming.rb +179 -138
- data/lib/action_controller/metal/strong_parameters.rb +1058 -382
- data/lib/action_controller/metal/testing.rb +11 -17
- data/lib/action_controller/metal/url_for.rb +37 -21
- data/lib/action_controller/metal.rb +236 -138
- data/lib/action_controller/railtie.rb +89 -11
- data/lib/action_controller/railties/helpers.rb +5 -1
- data/lib/action_controller/renderer.rb +161 -0
- data/lib/action_controller/template_assertions.rb +13 -0
- data/lib/action_controller/test_case.rb +425 -497
- data/lib/action_controller.rb +44 -22
- data/lib/action_dispatch/constants.rb +34 -0
- data/lib/action_dispatch/deprecator.rb +9 -0
- data/lib/action_dispatch/http/cache.rb +119 -63
- data/lib/action_dispatch/http/content_disposition.rb +47 -0
- data/lib/action_dispatch/http/content_security_policy.rb +364 -0
- data/lib/action_dispatch/http/filter_parameters.rb +36 -34
- data/lib/action_dispatch/http/filter_redirect.rb +24 -12
- data/lib/action_dispatch/http/headers.rb +66 -31
- data/lib/action_dispatch/http/mime_negotiation.rb +106 -75
- data/lib/action_dispatch/http/mime_type.rb +196 -136
- data/lib/action_dispatch/http/mime_types.rb +25 -7
- data/lib/action_dispatch/http/parameters.rb +97 -45
- data/lib/action_dispatch/http/permissions_policy.rb +187 -0
- data/lib/action_dispatch/http/rack_cache.rb +6 -0
- data/lib/action_dispatch/http/request.rb +299 -170
- data/lib/action_dispatch/http/response.rb +311 -160
- data/lib/action_dispatch/http/upload.rb +52 -23
- data/lib/action_dispatch/http/url.rb +201 -125
- data/lib/action_dispatch/journey/formatter.rb +110 -50
- data/lib/action_dispatch/journey/gtg/builder.rb +37 -50
- data/lib/action_dispatch/journey/gtg/simulator.rb +20 -17
- data/lib/action_dispatch/journey/gtg/transition_table.rb +96 -36
- data/lib/action_dispatch/journey/nfa/dot.rb +5 -14
- data/lib/action_dispatch/journey/nodes/node.rb +100 -20
- data/lib/action_dispatch/journey/parser.rb +19 -17
- data/lib/action_dispatch/journey/parser.y +4 -3
- data/lib/action_dispatch/journey/parser_extras.rb +14 -4
- data/lib/action_dispatch/journey/path/pattern.rb +79 -63
- data/lib/action_dispatch/journey/route.rb +108 -44
- data/lib/action_dispatch/journey/router/utils.rb +41 -29
- data/lib/action_dispatch/journey/router.rb +64 -57
- data/lib/action_dispatch/journey/routes.rb +23 -21
- data/lib/action_dispatch/journey/scanner.rb +28 -17
- data/lib/action_dispatch/journey/visitors.rb +100 -54
- data/lib/action_dispatch/journey/visualizer/fsm.js +49 -24
- data/lib/action_dispatch/journey/visualizer/index.html.erb +1 -1
- data/lib/action_dispatch/journey.rb +7 -5
- data/lib/action_dispatch/log_subscriber.rb +25 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +46 -0
- data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
- data/lib/action_dispatch/middleware/callbacks.rb +7 -6
- data/lib/action_dispatch/middleware/cookies.rb +471 -328
- data/lib/action_dispatch/middleware/debug_exceptions.rb +149 -66
- data/lib/action_dispatch/middleware/debug_locks.rb +129 -0
- data/lib/action_dispatch/middleware/debug_view.rb +73 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +275 -73
- data/lib/action_dispatch/middleware/executor.rb +32 -0
- data/lib/action_dispatch/middleware/flash.rb +143 -101
- data/lib/action_dispatch/middleware/host_authorization.rb +171 -0
- data/lib/action_dispatch/middleware/public_exceptions.rb +36 -27
- data/lib/action_dispatch/middleware/reloader.rb +10 -92
- data/lib/action_dispatch/middleware/remote_ip.rb +133 -107
- data/lib/action_dispatch/middleware/request_id.rb +29 -15
- data/lib/action_dispatch/middleware/server_timing.rb +78 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +49 -27
- data/lib/action_dispatch/middleware/session/cache_store.rb +33 -16
- data/lib/action_dispatch/middleware/session/cookie_store.rb +86 -80
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +66 -36
- data/lib/action_dispatch/middleware/ssl.rb +134 -36
- data/lib/action_dispatch/middleware/stack.rb +109 -44
- data/lib/action_dispatch/middleware/static.rb +159 -90
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +7 -24
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +36 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +46 -36
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +12 -0
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +26 -7
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +139 -15
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +6 -6
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +7 -7
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +9 -9
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +7 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +125 -93
- data/lib/action_dispatch/railtie.rb +44 -16
- data/lib/action_dispatch/request/session.rb +159 -69
- data/lib/action_dispatch/request/utils.rb +97 -23
- data/lib/action_dispatch/routing/endpoint.rb +11 -2
- data/lib/action_dispatch/routing/inspector.rb +195 -106
- data/lib/action_dispatch/routing/mapper.rb +1338 -955
- data/lib/action_dispatch/routing/polymorphic_routes.rb +234 -201
- data/lib/action_dispatch/routing/redirection.rb +78 -51
- data/lib/action_dispatch/routing/route_set.rb +460 -374
- data/lib/action_dispatch/routing/routes_proxy.rb +36 -12
- data/lib/action_dispatch/routing/url_for.rb +172 -124
- data/lib/action_dispatch/routing.rb +159 -158
- data/lib/action_dispatch/system_test_case.rb +206 -0
- data/lib/action_dispatch/system_testing/browser.rb +84 -0
- data/lib/action_dispatch/system_testing/driver.rb +85 -0
- data/lib/action_dispatch/system_testing/server.rb +33 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +164 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +23 -0
- data/lib/action_dispatch/testing/assertion_response.rb +48 -0
- data/lib/action_dispatch/testing/assertions/response.rb +71 -39
- data/lib/action_dispatch/testing/assertions/routing.rb +228 -103
- data/lib/action_dispatch/testing/assertions.rb +9 -6
- data/lib/action_dispatch/testing/integration.rb +486 -306
- data/lib/action_dispatch/testing/request_encoder.rb +60 -0
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +35 -22
- data/lib/action_dispatch/testing/test_request.rb +29 -34
- data/lib/action_dispatch/testing/test_response.rb +48 -15
- data/lib/action_dispatch.rb +82 -40
- data/lib/action_pack/gem_version.rb +8 -4
- data/lib/action_pack/version.rb +6 -2
- data/lib/action_pack.rb +21 -18
- metadata +146 -56
- data/lib/action_controller/caching/fragments.rb +0 -103
- data/lib/action_controller/metal/force_ssl.rb +0 -97
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/http/parameter_filter.rb +0 -72
- data/lib/action_dispatch/journey/backwards.rb +0 -5
- data/lib/action_dispatch/journey/nfa/builder.rb +0 -76
- data/lib/action_dispatch/journey/nfa/simulator.rb +0 -47
- data/lib/action_dispatch/journey/nfa/transition_table.rb +0 -163
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/middleware/params_parser.rb +0 -60
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +0 -27
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :markup: markdown
|
4
|
+
|
5
|
+
module AbstractController
|
6
|
+
module Caching
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
eager_autoload do
|
11
|
+
autoload :Fragments
|
12
|
+
end
|
13
|
+
|
14
|
+
module ConfigMethods
|
15
|
+
def cache_store
|
16
|
+
config.cache_store
|
17
|
+
end
|
18
|
+
|
19
|
+
def cache_store=(store)
|
20
|
+
config.cache_store = ActiveSupport::Cache.lookup_store(*store)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def cache_configured?
|
25
|
+
perform_caching && cache_store
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
include ConfigMethods
|
30
|
+
include AbstractController::Caching::Fragments
|
31
|
+
|
32
|
+
included do
|
33
|
+
extend ConfigMethods
|
34
|
+
|
35
|
+
config_accessor :default_static_extension
|
36
|
+
self.default_static_extension ||= ".html"
|
37
|
+
|
38
|
+
config_accessor :perform_caching
|
39
|
+
self.perform_caching = true if perform_caching.nil?
|
40
|
+
|
41
|
+
config_accessor :enable_fragment_cache_logging
|
42
|
+
self.enable_fragment_cache_logging = false
|
43
|
+
|
44
|
+
class_attribute :_view_cache_dependencies, default: []
|
45
|
+
helper_method :view_cache_dependencies if respond_to?(:helper_method)
|
46
|
+
end
|
47
|
+
|
48
|
+
module ClassMethods
|
49
|
+
def view_cache_dependency(&dependency)
|
50
|
+
self._view_cache_dependencies += [dependency]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def view_cache_dependencies
|
55
|
+
self.class._view_cache_dependencies.filter_map { |dep| instance_exec(&dep) }
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
# Convenience accessor.
|
60
|
+
def cache(key, options = {}, &block) # :doc:
|
61
|
+
if cache_configured?
|
62
|
+
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
|
63
|
+
else
|
64
|
+
yield
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,77 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :markup: markdown
|
4
|
+
|
1
5
|
module AbstractController
|
6
|
+
# # Abstract Controller Callbacks
|
7
|
+
#
|
8
|
+
# Abstract Controller provides hooks during the life cycle of a controller
|
9
|
+
# action. Callbacks allow you to trigger logic during this cycle. Available
|
10
|
+
# callbacks are:
|
11
|
+
#
|
12
|
+
# * `after_action`
|
13
|
+
# * `append_after_action`
|
14
|
+
# * `append_around_action`
|
15
|
+
# * `append_before_action`
|
16
|
+
# * `around_action`
|
17
|
+
# * `before_action`
|
18
|
+
# * `prepend_after_action`
|
19
|
+
# * `prepend_around_action`
|
20
|
+
# * `prepend_before_action`
|
21
|
+
# * `skip_after_action`
|
22
|
+
# * `skip_around_action`
|
23
|
+
# * `skip_before_action`
|
2
24
|
module Callbacks
|
3
25
|
extend ActiveSupport::Concern
|
4
26
|
|
5
|
-
# Uses ActiveSupport::Callbacks as the base functionality. For
|
6
|
-
#
|
7
|
-
#
|
27
|
+
# Uses ActiveSupport::Callbacks as the base functionality. For more details on
|
28
|
+
# the whole callback system, read the documentation for
|
29
|
+
# ActiveSupport::Callbacks.
|
8
30
|
include ActiveSupport::Callbacks
|
9
31
|
|
10
32
|
included do
|
11
33
|
define_callbacks :process_action,
|
12
|
-
terminator: ->(controller,
|
34
|
+
terminator: ->(controller, result_lambda) { result_lambda.call; controller.performed? },
|
13
35
|
skip_after_callbacks_if_terminated: true
|
36
|
+
mattr_accessor :raise_on_missing_callback_actions, default: false
|
14
37
|
end
|
15
38
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
39
|
+
class ActionFilter # :nodoc:
|
40
|
+
def initialize(filters, conditional_key, actions)
|
41
|
+
@filters = filters.to_a
|
42
|
+
@conditional_key = conditional_key
|
43
|
+
@actions = Array(actions).map(&:to_s).to_set
|
44
|
+
end
|
45
|
+
|
46
|
+
def match?(controller)
|
47
|
+
if controller.raise_on_missing_callback_actions
|
48
|
+
missing_action = @actions.find { |action| !controller.available_action?(action) }
|
49
|
+
if missing_action
|
50
|
+
filter_names = @filters.length == 1 ? @filters.first.inspect : @filters.inspect
|
51
|
+
|
52
|
+
message = <<~MSG
|
53
|
+
The #{missing_action} action could not be found for the #{filter_names}
|
54
|
+
callback on #{controller.class.name}, but it is listed in the controller's
|
55
|
+
#{@conditional_key.inspect} option.
|
56
|
+
|
57
|
+
Raising for missing callback actions is a new default in Rails 7.1, if you'd
|
58
|
+
like to turn this off you can delete the option from the environment configurations
|
59
|
+
or set `config.action_controller.raise_on_missing_callback_actions` to `false`.
|
60
|
+
MSG
|
61
|
+
|
62
|
+
raise ActionNotFound.new(message, controller, missing_action)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
@actions.include?(controller.action_name)
|
21
67
|
end
|
68
|
+
|
69
|
+
alias after match?
|
70
|
+
alias before match?
|
71
|
+
alias around match?
|
22
72
|
end
|
23
73
|
|
24
74
|
module ClassMethods
|
25
|
-
# If
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# :if => proc {|c|
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
75
|
+
# If `:only` or `:except` are used, convert the options into the `:if` and
|
76
|
+
# `:unless` options of ActiveSupport::Callbacks.
|
77
|
+
#
|
78
|
+
# The basic idea is that `:only => :index` gets converted to `:if => proc {|c|
|
79
|
+
# c.action_name == "index" }`.
|
80
|
+
#
|
81
|
+
# Note that `:only` has priority over `:if` in case they are used together.
|
82
|
+
#
|
83
|
+
# only: :index, if: -> { true } # the :if option will be ignored.
|
84
|
+
#
|
85
|
+
# Note that `:if` has priority over `:except` in case they are used together.
|
86
|
+
#
|
87
|
+
# except: :index, if: -> { true } # the :except option will be ignored.
|
88
|
+
#
|
89
|
+
# #### Options
|
90
|
+
# * `only` - The callback should be run only for this action.
|
91
|
+
# * `except` - The callback should be run for all actions except this action.
|
92
|
+
#
|
33
93
|
def _normalize_callback_options(options)
|
34
94
|
_normalize_callback_option(options, :only, :if)
|
35
95
|
_normalize_callback_option(options, :except, :unless)
|
36
96
|
end
|
37
97
|
|
38
98
|
def _normalize_callback_option(options, from, to) # :nodoc:
|
39
|
-
if
|
40
|
-
|
41
|
-
|
99
|
+
if from_value = options.delete(from)
|
100
|
+
filters = options[:filters]
|
101
|
+
from_value = ActionFilter.new(filters, from, from_value)
|
102
|
+
options[to] = Array(options[to]).unshift(from_value)
|
42
103
|
end
|
43
104
|
end
|
44
105
|
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# * <tt>names</tt> - A list of valid names that could be used for
|
49
|
-
# callbacks. Note that skipping uses Ruby equality, so it's
|
50
|
-
# impossible to skip a callback defined using an anonymous proc
|
51
|
-
# using #skip_action_callback
|
52
|
-
def skip_action_callback(*names)
|
53
|
-
skip_before_action(*names)
|
54
|
-
skip_after_action(*names)
|
55
|
-
skip_around_action(*names)
|
56
|
-
end
|
57
|
-
alias_method :skip_filter, :skip_action_callback
|
58
|
-
|
59
|
-
# Take callback names and an optional callback proc, normalize them,
|
60
|
-
# then call the block with each callback. This allows us to abstract
|
61
|
-
# the normalization across several methods that use it.
|
106
|
+
# Take callback names and an optional callback proc, normalize them, then call
|
107
|
+
# the block with each callback. This allows us to abstract the normalization
|
108
|
+
# across several methods that use it.
|
62
109
|
#
|
63
|
-
#
|
64
|
-
# *
|
65
|
-
#
|
66
|
-
# *
|
110
|
+
# #### Parameters
|
111
|
+
# * `callbacks` - An array of callbacks, with an optional options hash as the
|
112
|
+
# last parameter.
|
113
|
+
# * `block` - A proc that should be added to the callbacks.
|
114
|
+
#
|
115
|
+
#
|
116
|
+
# #### Block Parameters
|
117
|
+
# * `name` - The callback to be added.
|
118
|
+
# * `options` - A hash of options to be used when adding the callback.
|
67
119
|
#
|
68
|
-
# ==== Block Parameters
|
69
|
-
# * <tt>name</tt> - The callback to be added
|
70
|
-
# * <tt>options</tt> - A hash of options to be used when adding the callback
|
71
120
|
def _insert_callbacks(callbacks, block = nil)
|
72
121
|
options = callbacks.extract_options!
|
73
|
-
_normalize_callback_options(options)
|
74
122
|
callbacks.push(block) if block
|
123
|
+
options[:filters] = callbacks
|
124
|
+
_normalize_callback_options(options)
|
125
|
+
options.delete(:filters)
|
75
126
|
callbacks.each do |callback|
|
76
127
|
yield callback, options
|
77
128
|
end
|
@@ -83,13 +134,22 @@ module AbstractController
|
|
83
134
|
# :call-seq: before_action(names, block)
|
84
135
|
#
|
85
136
|
# Append a callback before actions. See _insert_callbacks for parameter details.
|
137
|
+
#
|
138
|
+
# If the callback renders or redirects, the action will not run. If there are
|
139
|
+
# additional callbacks scheduled to run after that callback, they are also
|
140
|
+
# cancelled.
|
86
141
|
|
87
142
|
##
|
88
143
|
# :method: prepend_before_action
|
89
144
|
#
|
90
145
|
# :call-seq: prepend_before_action(names, block)
|
91
146
|
#
|
92
|
-
# Prepend a callback before actions. See _insert_callbacks for parameter
|
147
|
+
# Prepend a callback before actions. See _insert_callbacks for parameter
|
148
|
+
# details.
|
149
|
+
#
|
150
|
+
# If the callback renders or redirects, the action will not run. If there are
|
151
|
+
# additional callbacks scheduled to run after that callback, they are also
|
152
|
+
# cancelled.
|
93
153
|
|
94
154
|
##
|
95
155
|
# :method: skip_before_action
|
@@ -104,6 +164,10 @@ module AbstractController
|
|
104
164
|
# :call-seq: append_before_action(names, block)
|
105
165
|
#
|
106
166
|
# Append a callback before actions. See _insert_callbacks for parameter details.
|
167
|
+
#
|
168
|
+
# If the callback renders or redirects, the action will not run. If there are
|
169
|
+
# additional callbacks scheduled to run after that callback, they are also
|
170
|
+
# cancelled.
|
107
171
|
|
108
172
|
##
|
109
173
|
# :method: after_action
|
@@ -145,7 +209,8 @@ module AbstractController
|
|
145
209
|
#
|
146
210
|
# :call-seq: prepend_around_action(names, block)
|
147
211
|
#
|
148
|
-
# Prepend a callback around actions. See _insert_callbacks for parameter
|
212
|
+
# Prepend a callback around actions. See _insert_callbacks for parameter
|
213
|
+
# details.
|
149
214
|
|
150
215
|
##
|
151
216
|
# :method: skip_around_action
|
@@ -160,37 +225,41 @@ module AbstractController
|
|
160
225
|
# :call-seq: append_around_action(names, block)
|
161
226
|
#
|
162
227
|
# Append a callback around actions. See _insert_callbacks for parameter details.
|
163
|
-
|
164
|
-
#
|
165
|
-
# for each of before, after, and around.
|
228
|
+
# set up before_action, prepend_before_action, skip_before_action, etc. for each
|
229
|
+
# of before, after, and around.
|
166
230
|
[:before, :after, :around].each do |callback|
|
167
231
|
define_method "#{callback}_action" do |*names, &blk|
|
168
232
|
_insert_callbacks(names, blk) do |name, options|
|
169
233
|
set_callback(:process_action, callback, name, options)
|
170
234
|
end
|
171
235
|
end
|
172
|
-
alias_method :"#{callback}_filter", :"#{callback}_action"
|
173
236
|
|
174
237
|
define_method "prepend_#{callback}_action" do |*names, &blk|
|
175
238
|
_insert_callbacks(names, blk) do |name, options|
|
176
|
-
set_callback(:process_action, callback, name, options.merge(:
|
239
|
+
set_callback(:process_action, callback, name, options.merge(prepend: true))
|
177
240
|
end
|
178
241
|
end
|
179
|
-
alias_method :"prepend_#{callback}_filter", :"prepend_#{callback}_action"
|
180
242
|
|
181
|
-
# Skip a before, after or around callback. See _insert_callbacks
|
182
|
-
#
|
243
|
+
# Skip a before, after or around callback. See _insert_callbacks for details on
|
244
|
+
# the allowed parameters.
|
183
245
|
define_method "skip_#{callback}_action" do |*names|
|
184
246
|
_insert_callbacks(names) do |name, options|
|
185
247
|
skip_callback(:process_action, callback, name, options)
|
186
248
|
end
|
187
249
|
end
|
188
|
-
alias_method :"skip_#{callback}_filter", :"skip_#{callback}_action"
|
189
250
|
|
190
251
|
# *_action is the same as append_*_action
|
191
252
|
alias_method :"append_#{callback}_action", :"#{callback}_action"
|
192
|
-
alias_method :"append_#{callback}_filter", :"#{callback}_action"
|
193
253
|
end
|
194
254
|
end
|
255
|
+
|
256
|
+
private
|
257
|
+
# Override `AbstractController::Base#process_action` to run the `process_action`
|
258
|
+
# callbacks around the normal behavior.
|
259
|
+
def process_action(...)
|
260
|
+
run_callbacks(:process_action) do
|
261
|
+
super
|
262
|
+
end
|
263
|
+
end
|
195
264
|
end
|
196
265
|
end
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :markup: markdown
|
4
|
+
|
1
5
|
require "action_dispatch/http/mime_type"
|
2
6
|
|
3
7
|
module AbstractController
|
4
8
|
module Collector
|
5
9
|
def self.generate_method_for_mime(mime)
|
6
10
|
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
|
7
|
-
const = sym.upcase
|
8
11
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
|
-
def #{sym}(
|
10
|
-
custom(Mime
|
11
|
-
end
|
12
|
+
def #{sym}(...)
|
13
|
+
custom(Mime[:#{sym}], ...)
|
14
|
+
end
|
12
15
|
RUBY
|
13
16
|
end
|
14
17
|
|
@@ -17,27 +20,22 @@ module AbstractController
|
|
17
20
|
end
|
18
21
|
|
19
22
|
Mime::Type.register_callback do |mime|
|
20
|
-
generate_method_for_mime(mime) unless
|
23
|
+
generate_method_for_mime(mime) unless instance_methods.include?(mime.to_sym)
|
21
24
|
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
const_name = symbol.upcase
|
27
|
-
|
28
|
-
unless Mime.const_defined?(const_name)
|
26
|
+
private
|
27
|
+
def method_missing(symbol, ...)
|
28
|
+
unless mime_constant = Mime[symbol]
|
29
29
|
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
|
30
|
-
"
|
30
|
+
"https://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
|
31
31
|
"If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
|
32
32
|
"be sure to nest your variant response within a format response: " \
|
33
33
|
"format.html { |html| html.tablet { ... } }"
|
34
34
|
end
|
35
35
|
|
36
|
-
mime_constant = Mime.const_get(const_name)
|
37
|
-
|
38
36
|
if Mime::SET.include?(mime_constant)
|
39
37
|
AbstractController::Collector.generate_method_for_mime(mime_constant)
|
40
|
-
|
38
|
+
public_send(symbol, ...)
|
41
39
|
else
|
42
40
|
super
|
43
41
|
end
|