actionpack 6.0.0

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.

Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +311 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +58 -0
  5. data/lib/abstract_controller.rb +27 -0
  6. data/lib/abstract_controller/asset_paths.rb +12 -0
  7. data/lib/abstract_controller/base.rb +267 -0
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/caching/fragments.rb +150 -0
  10. data/lib/abstract_controller/callbacks.rb +224 -0
  11. data/lib/abstract_controller/collector.rb +43 -0
  12. data/lib/abstract_controller/error.rb +6 -0
  13. data/lib/abstract_controller/helpers.rb +194 -0
  14. data/lib/abstract_controller/logger.rb +14 -0
  15. data/lib/abstract_controller/railties/routes_helpers.rb +20 -0
  16. data/lib/abstract_controller/rendering.rb +127 -0
  17. data/lib/abstract_controller/translation.rb +32 -0
  18. data/lib/abstract_controller/url_for.rb +35 -0
  19. data/lib/action_controller.rb +67 -0
  20. data/lib/action_controller/api.rb +150 -0
  21. data/lib/action_controller/api/api_rendering.rb +16 -0
  22. data/lib/action_controller/base.rb +271 -0
  23. data/lib/action_controller/caching.rb +46 -0
  24. data/lib/action_controller/form_builder.rb +50 -0
  25. data/lib/action_controller/log_subscriber.rb +81 -0
  26. data/lib/action_controller/metal.rb +256 -0
  27. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  28. data/lib/action_controller/metal/conditional_get.rb +280 -0
  29. data/lib/action_controller/metal/content_security_policy.rb +52 -0
  30. data/lib/action_controller/metal/cookies.rb +16 -0
  31. data/lib/action_controller/metal/data_streaming.rb +151 -0
  32. data/lib/action_controller/metal/default_headers.rb +17 -0
  33. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  34. data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
  35. data/lib/action_controller/metal/exceptions.rb +74 -0
  36. data/lib/action_controller/metal/flash.rb +61 -0
  37. data/lib/action_controller/metal/force_ssl.rb +58 -0
  38. data/lib/action_controller/metal/head.rb +60 -0
  39. data/lib/action_controller/metal/helpers.rb +122 -0
  40. data/lib/action_controller/metal/http_authentication.rb +518 -0
  41. data/lib/action_controller/metal/implicit_render.rb +63 -0
  42. data/lib/action_controller/metal/instrumentation.rb +105 -0
  43. data/lib/action_controller/metal/live.rb +314 -0
  44. data/lib/action_controller/metal/mime_responds.rb +324 -0
  45. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  46. data/lib/action_controller/metal/params_wrapper.rb +297 -0
  47. data/lib/action_controller/metal/redirecting.rb +133 -0
  48. data/lib/action_controller/metal/renderers.rb +181 -0
  49. data/lib/action_controller/metal/rendering.rb +122 -0
  50. data/lib/action_controller/metal/request_forgery_protection.rb +456 -0
  51. data/lib/action_controller/metal/rescue.rb +28 -0
  52. data/lib/action_controller/metal/streaming.rb +223 -0
  53. data/lib/action_controller/metal/strong_parameters.rb +1105 -0
  54. data/lib/action_controller/metal/testing.rb +16 -0
  55. data/lib/action_controller/metal/url_for.rb +58 -0
  56. data/lib/action_controller/railtie.rb +89 -0
  57. data/lib/action_controller/railties/helpers.rb +24 -0
  58. data/lib/action_controller/renderer.rb +130 -0
  59. data/lib/action_controller/template_assertions.rb +11 -0
  60. data/lib/action_controller/test_case.rb +626 -0
  61. data/lib/action_dispatch.rb +114 -0
  62. data/lib/action_dispatch/http/cache.rb +226 -0
  63. data/lib/action_dispatch/http/content_disposition.rb +45 -0
  64. data/lib/action_dispatch/http/content_security_policy.rb +284 -0
  65. data/lib/action_dispatch/http/filter_parameters.rb +86 -0
  66. data/lib/action_dispatch/http/filter_redirect.rb +37 -0
  67. data/lib/action_dispatch/http/headers.rb +132 -0
  68. data/lib/action_dispatch/http/mime_negotiation.rb +177 -0
  69. data/lib/action_dispatch/http/mime_type.rb +350 -0
  70. data/lib/action_dispatch/http/mime_types.rb +50 -0
  71. data/lib/action_dispatch/http/parameter_filter.rb +12 -0
  72. data/lib/action_dispatch/http/parameters.rb +136 -0
  73. data/lib/action_dispatch/http/rack_cache.rb +63 -0
  74. data/lib/action_dispatch/http/request.rb +427 -0
  75. data/lib/action_dispatch/http/response.rb +534 -0
  76. data/lib/action_dispatch/http/upload.rb +92 -0
  77. data/lib/action_dispatch/http/url.rb +350 -0
  78. data/lib/action_dispatch/journey.rb +7 -0
  79. data/lib/action_dispatch/journey/formatter.rb +189 -0
  80. data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
  81. data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
  82. data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
  83. data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
  84. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  85. data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
  86. data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
  87. data/lib/action_dispatch/journey/nodes/node.rb +141 -0
  88. data/lib/action_dispatch/journey/parser.rb +199 -0
  89. data/lib/action_dispatch/journey/parser.y +50 -0
  90. data/lib/action_dispatch/journey/parser_extras.rb +31 -0
  91. data/lib/action_dispatch/journey/path/pattern.rb +203 -0
  92. data/lib/action_dispatch/journey/route.rb +204 -0
  93. data/lib/action_dispatch/journey/router.rb +153 -0
  94. data/lib/action_dispatch/journey/router/utils.rb +102 -0
  95. data/lib/action_dispatch/journey/routes.rb +81 -0
  96. data/lib/action_dispatch/journey/scanner.rb +71 -0
  97. data/lib/action_dispatch/journey/visitors.rb +268 -0
  98. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  99. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  100. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  101. data/lib/action_dispatch/middleware/actionable_exceptions.rb +39 -0
  102. data/lib/action_dispatch/middleware/callbacks.rb +34 -0
  103. data/lib/action_dispatch/middleware/cookies.rb +663 -0
  104. data/lib/action_dispatch/middleware/debug_exceptions.rb +185 -0
  105. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  106. data/lib/action_dispatch/middleware/debug_view.rb +68 -0
  107. data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -0
  108. data/lib/action_dispatch/middleware/executor.rb +21 -0
  109. data/lib/action_dispatch/middleware/flash.rb +300 -0
  110. data/lib/action_dispatch/middleware/host_authorization.rb +103 -0
  111. data/lib/action_dispatch/middleware/public_exceptions.rb +61 -0
  112. data/lib/action_dispatch/middleware/reloader.rb +12 -0
  113. data/lib/action_dispatch/middleware/remote_ip.rb +181 -0
  114. data/lib/action_dispatch/middleware/request_id.rb +43 -0
  115. data/lib/action_dispatch/middleware/session/abstract_store.rb +92 -0
  116. data/lib/action_dispatch/middleware/session/cache_store.rb +54 -0
  117. data/lib/action_dispatch/middleware/session/cookie_store.rb +113 -0
  118. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +28 -0
  119. data/lib/action_dispatch/middleware/show_exceptions.rb +62 -0
  120. data/lib/action_dispatch/middleware/ssl.rb +150 -0
  121. data/lib/action_dispatch/middleware/stack.rb +148 -0
  122. data/lib/action_dispatch/middleware/static.rb +129 -0
  123. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +24 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +29 -0
  128. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +62 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +7 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +5 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +38 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +15 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +165 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  141. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  142. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  143. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  144. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  145. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  146. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  147. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  148. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  149. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +203 -0
  150. data/lib/action_dispatch/railtie.rb +58 -0
  151. data/lib/action_dispatch/request/session.rb +242 -0
  152. data/lib/action_dispatch/request/utils.rb +78 -0
  153. data/lib/action_dispatch/routing.rb +261 -0
  154. data/lib/action_dispatch/routing/endpoint.rb +17 -0
  155. data/lib/action_dispatch/routing/inspector.rb +274 -0
  156. data/lib/action_dispatch/routing/mapper.rb +2289 -0
  157. data/lib/action_dispatch/routing/polymorphic_routes.rb +351 -0
  158. data/lib/action_dispatch/routing/redirection.rb +201 -0
  159. data/lib/action_dispatch/routing/route_set.rb +887 -0
  160. data/lib/action_dispatch/routing/routes_proxy.rb +69 -0
  161. data/lib/action_dispatch/routing/url_for.rb +237 -0
  162. data/lib/action_dispatch/system_test_case.rb +168 -0
  163. data/lib/action_dispatch/system_testing/browser.rb +80 -0
  164. data/lib/action_dispatch/system_testing/driver.rb +68 -0
  165. data/lib/action_dispatch/system_testing/server.rb +31 -0
  166. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +97 -0
  167. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +33 -0
  168. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
  169. data/lib/action_dispatch/testing/assertion_response.rb +47 -0
  170. data/lib/action_dispatch/testing/assertions.rb +24 -0
  171. data/lib/action_dispatch/testing/assertions/response.rb +106 -0
  172. data/lib/action_dispatch/testing/assertions/routing.rb +234 -0
  173. data/lib/action_dispatch/testing/integration.rb +659 -0
  174. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  175. data/lib/action_dispatch/testing/test_process.rb +50 -0
  176. data/lib/action_dispatch/testing/test_request.rb +71 -0
  177. data/lib/action_dispatch/testing/test_response.rb +25 -0
  178. data/lib/action_pack.rb +26 -0
  179. data/lib/action_pack/gem_version.rb +17 -0
  180. data/lib/action_pack/version.rb +10 -0
  181. metadata +329 -0
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbstractController
4
+ class Error < StandardError #:nodoc:
5
+ end
6
+ end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/dependencies"
4
+
5
+ module AbstractController
6
+ module Helpers
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class_attribute :_helpers, default: Module.new
11
+ class_attribute :_helper_methods, default: Array.new
12
+ end
13
+
14
+ class MissingHelperError < LoadError
15
+ def initialize(error, path)
16
+ @error = error
17
+ @path = "helpers/#{path}.rb"
18
+ set_backtrace error.backtrace
19
+
20
+ if /^#{path}(\.rb)?$/.match?(error.path)
21
+ super("Missing helper file helpers/%s.rb" % path)
22
+ else
23
+ raise error
24
+ end
25
+ end
26
+ end
27
+
28
+ module ClassMethods
29
+ # When a class is inherited, wrap its helper module in a new module.
30
+ # This ensures that the parent class's module can be changed
31
+ # independently of the child class's.
32
+ def inherited(klass)
33
+ helpers = _helpers
34
+ klass._helpers = Module.new { include helpers }
35
+ klass.class_eval { default_helper_module! } unless klass.anonymous?
36
+ super
37
+ end
38
+
39
+ # Declare a controller method as a helper. For example, the following
40
+ # makes the +current_user+ and +logged_in?+ controller methods available
41
+ # to the view:
42
+ # class ApplicationController < ActionController::Base
43
+ # helper_method :current_user, :logged_in?
44
+ #
45
+ # def current_user
46
+ # @current_user ||= User.find_by(id: session[:user])
47
+ # end
48
+ #
49
+ # def logged_in?
50
+ # current_user != nil
51
+ # end
52
+ # end
53
+ #
54
+ # In a view:
55
+ # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
56
+ #
57
+ # ==== Parameters
58
+ # * <tt>method[, method]</tt> - A name or names of a method on the controller
59
+ # to be made available on the view.
60
+ def helper_method(*meths)
61
+ meths.flatten!
62
+ self._helper_methods += meths
63
+
64
+ meths.each do |meth|
65
+ _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
66
+ def #{meth}(*args, &blk) # def current_user(*args, &blk)
67
+ controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk)
68
+ end # end
69
+ ruby_eval
70
+ end
71
+ end
72
+
73
+ # The +helper+ class method can take a series of helper module names, a block, or both.
74
+ #
75
+ # ==== Options
76
+ # * <tt>*args</tt> - Module, Symbol, String
77
+ # * <tt>block</tt> - A block defining helper methods
78
+ #
79
+ # When the argument is a module it will be included directly in the template class.
80
+ # helper FooHelper # => includes FooHelper
81
+ #
82
+ # When the argument is a string or symbol, the method will provide the "_helper" suffix, require the file
83
+ # and include the module in the template class. The second form illustrates how to include custom helpers
84
+ # when working with namespaced controllers, or other cases where the file containing the helper definition is not
85
+ # in one of Rails' standard load paths:
86
+ # helper :foo # => requires 'foo_helper' and includes FooHelper
87
+ # helper 'resources/foo' # => requires 'resources/foo_helper' and includes Resources::FooHelper
88
+ #
89
+ # Additionally, the +helper+ class method can receive and evaluate a block, making the methods defined available
90
+ # to the template.
91
+ #
92
+ # # One line
93
+ # helper { def hello() "Hello, world!" end }
94
+ #
95
+ # # Multi-line
96
+ # helper do
97
+ # def foo(bar)
98
+ # "#{bar} is the very best"
99
+ # end
100
+ # end
101
+ #
102
+ # Finally, all the above styles can be mixed together, and the +helper+ method can be invoked with a mix of
103
+ # +symbols+, +strings+, +modules+ and blocks.
104
+ #
105
+ # helper(:three, BlindHelper) { def mice() 'mice' end }
106
+ #
107
+ def helper(*args, &block)
108
+ modules_for_helpers(args).each do |mod|
109
+ add_template_helper(mod)
110
+ end
111
+
112
+ _helpers.module_eval(&block) if block_given?
113
+ end
114
+
115
+ # Clears up all existing helpers in this class, only keeping the helper
116
+ # with the same name as this class.
117
+ def clear_helpers
118
+ inherited_helper_methods = _helper_methods
119
+ self._helpers = Module.new
120
+ self._helper_methods = Array.new
121
+
122
+ inherited_helper_methods.each { |meth| helper_method meth }
123
+ default_helper_module! unless anonymous?
124
+ end
125
+
126
+ # Returns a list of modules, normalized from the acceptable kinds of
127
+ # helpers with the following behavior:
128
+ #
129
+ # String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper",
130
+ # and "foo_bar_helper.rb" is loaded using require_dependency.
131
+ #
132
+ # Module:: No further processing
133
+ #
134
+ # After loading the appropriate files, the corresponding modules
135
+ # are returned.
136
+ #
137
+ # ==== Parameters
138
+ # * <tt>args</tt> - An array of helpers
139
+ #
140
+ # ==== Returns
141
+ # * <tt>Array</tt> - A normalized list of modules for the list of
142
+ # helpers provided.
143
+ def modules_for_helpers(args)
144
+ args.flatten.map! do |arg|
145
+ case arg
146
+ when String, Symbol
147
+ file_name = "#{arg.to_s.underscore}_helper"
148
+ begin
149
+ require_dependency(file_name)
150
+ rescue LoadError => e
151
+ raise AbstractController::Helpers::MissingHelperError.new(e, file_name)
152
+ end
153
+
154
+ mod_name = file_name.camelize
155
+ begin
156
+ mod_name.constantize
157
+ rescue LoadError
158
+ # dependencies.rb gives a similar error message but its wording is
159
+ # not as clear because it mentions autoloading. To the user all it
160
+ # matters is that a helper module couldn't be loaded, autoloading
161
+ # is an internal mechanism that should not leak.
162
+ raise NameError, "Couldn't find #{mod_name}, expected it to be defined in helpers/#{file_name}.rb"
163
+ end
164
+ when Module
165
+ arg
166
+ else
167
+ raise ArgumentError, "helper must be a String, Symbol, or Module"
168
+ end
169
+ end
170
+ end
171
+
172
+ private
173
+ # Makes all the (instance) methods in the helper module available to templates
174
+ # rendered through this controller.
175
+ #
176
+ # ==== Parameters
177
+ # * <tt>module</tt> - The module to include into the current helper module
178
+ # for the class
179
+ def add_template_helper(mod)
180
+ _helpers.module_eval { include mod }
181
+ end
182
+
183
+ def default_helper_module!
184
+ module_name = name.sub(/Controller$/, "")
185
+ module_path = module_name.underscore
186
+ helper module_path
187
+ rescue LoadError => e
188
+ raise e unless e.is_missing? "helpers/#{module_path}_helper"
189
+ rescue NameError => e
190
+ raise e unless e.missing_name? "#{module_name}Helper"
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/benchmarkable"
4
+
5
+ module AbstractController
6
+ module Logger #:nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ config_accessor :logger
11
+ include ActiveSupport::Benchmarkable
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbstractController
4
+ module Railties
5
+ module RoutesHelpers
6
+ def self.with(routes, include_path_helpers = true)
7
+ Module.new do
8
+ define_method(:inherited) do |klass|
9
+ super(klass)
10
+ if namespace = klass.module_parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
11
+ klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
12
+ else
13
+ klass.include(routes.url_helpers(include_path_helpers))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "abstract_controller/error"
4
+ require "action_view"
5
+ require "action_view/view_paths"
6
+ require "set"
7
+
8
+ module AbstractController
9
+ class DoubleRenderError < Error
10
+ 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\"."
11
+
12
+ def initialize(message = nil)
13
+ super(message || DEFAULT_MESSAGE)
14
+ end
15
+ end
16
+
17
+ module Rendering
18
+ extend ActiveSupport::Concern
19
+ include ActionView::ViewPaths
20
+
21
+ # Normalizes arguments, options and then delegates render_to_body and
22
+ # sticks the result in <tt>self.response_body</tt>.
23
+ def render(*args, &block)
24
+ options = _normalize_render(*args, &block)
25
+ rendered_body = render_to_body(options)
26
+ if options[:html]
27
+ _set_html_content_type
28
+ else
29
+ _set_rendered_content_type rendered_format
30
+ end
31
+ self.response_body = rendered_body
32
+ end
33
+
34
+ # Raw rendering of a template to a string.
35
+ #
36
+ # It is similar to render, except that it does not
37
+ # set the +response_body+ and it should be guaranteed
38
+ # to always return a string.
39
+ #
40
+ # If a component extends the semantics of +response_body+
41
+ # (as ActionController extends it to be anything that
42
+ # responds to the method each), this method needs to be
43
+ # overridden in order to still return a string.
44
+ def render_to_string(*args, &block)
45
+ options = _normalize_render(*args, &block)
46
+ render_to_body(options)
47
+ end
48
+
49
+ # Performs the actual template rendering.
50
+ def render_to_body(options = {})
51
+ end
52
+
53
+ # Returns Content-Type of rendered content.
54
+ def rendered_format
55
+ Mime[:text]
56
+ end
57
+
58
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
59
+ @_action_name @_response_body @_formats @_prefixes
60
+ )
61
+
62
+ # This method should return a hash with assigns.
63
+ # You can overwrite this configuration per controller.
64
+ def view_assigns
65
+ protected_vars = _protected_ivars
66
+ variables = instance_variables
67
+
68
+ variables.reject! { |s| protected_vars.include? s }
69
+ variables.each_with_object({}) { |name, hash|
70
+ hash[name.slice(1, name.length)] = instance_variable_get(name)
71
+ }
72
+ end
73
+
74
+ private
75
+ # Normalize args by converting <tt>render "foo"</tt> to
76
+ # <tt>render :action => "foo"</tt> and <tt>render "foo/bar"</tt> to
77
+ # <tt>render :file => "foo/bar"</tt>.
78
+ def _normalize_args(action = nil, options = {}) # :doc:
79
+ if action.respond_to?(:permitted?)
80
+ if action.permitted?
81
+ action
82
+ else
83
+ raise ArgumentError, "render parameters are not permitted"
84
+ end
85
+ elsif action.is_a?(Hash)
86
+ action
87
+ else
88
+ options
89
+ end
90
+ end
91
+
92
+ # Normalize options.
93
+ def _normalize_options(options) # :doc:
94
+ options
95
+ end
96
+
97
+ # Process extra options.
98
+ def _process_options(options) # :doc:
99
+ options
100
+ end
101
+
102
+ # Process the rendered format.
103
+ def _process_format(format) # :nodoc:
104
+ end
105
+
106
+ def _process_variant(options)
107
+ end
108
+
109
+ def _set_html_content_type # :nodoc:
110
+ end
111
+
112
+ def _set_rendered_content_type(format) # :nodoc:
113
+ end
114
+
115
+ # Normalize args and options.
116
+ def _normalize_render(*args, &block) # :nodoc:
117
+ options = _normalize_args(*args, &block)
118
+ _process_variant(options)
119
+ _normalize_options(options)
120
+ options
121
+ end
122
+
123
+ def _protected_ivars # :nodoc:
124
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbstractController
4
+ module Translation
5
+ # Delegates to <tt>I18n.translate</tt>. Also aliased as <tt>t</tt>.
6
+ #
7
+ # When the given key starts with a period, it will be scoped by the current
8
+ # controller and action. So if you call <tt>translate(".foo")</tt> from
9
+ # <tt>PeopleController#index</tt>, it will convert the call to
10
+ # <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
11
+ # to translate many keys within the same controller / action and gives you a
12
+ # simple framework for scoping them consistently.
13
+ def translate(key, options = {})
14
+ options = options.dup
15
+ if key.to_s.first == "."
16
+ path = controller_path.tr("/", ".")
17
+ defaults = [:"#{path}#{key}"]
18
+ defaults << options[:default] if options[:default]
19
+ options[:default] = defaults.flatten
20
+ key = "#{path}.#{action_name}#{key}"
21
+ end
22
+ I18n.translate(key, options)
23
+ end
24
+ alias :t :translate
25
+
26
+ # Delegates to <tt>I18n.localize</tt>. Also aliased as <tt>l</tt>.
27
+ def localize(*args)
28
+ I18n.localize(*args)
29
+ end
30
+ alias :l :localize
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbstractController
4
+ # Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
5
+ # has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
6
+ # exception will be raised.
7
+ #
8
+ # Note that this module is completely decoupled from HTTP - the only requirement is a valid
9
+ # <tt>_routes</tt> implementation.
10
+ module UrlFor
11
+ extend ActiveSupport::Concern
12
+ include ActionDispatch::Routing::UrlFor
13
+
14
+ def _routes
15
+ raise "In order to use #url_for, you must include routing helpers explicitly. " \
16
+ "For instance, `include Rails.application.routes.url_helpers`."
17
+ end
18
+
19
+ module ClassMethods
20
+ def _routes
21
+ nil
22
+ end
23
+
24
+ def action_methods
25
+ @action_methods ||= begin
26
+ if _routes
27
+ super - _routes.named_routes.helper_names
28
+ else
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/rails"
4
+ require "abstract_controller"
5
+ require "action_dispatch"
6
+ require "action_controller/metal/live"
7
+ require "action_controller/metal/strong_parameters"
8
+
9
+ module ActionController
10
+ extend ActiveSupport::Autoload
11
+
12
+ autoload :API
13
+ autoload :Base
14
+ autoload :Metal
15
+ autoload :Middleware
16
+ autoload :Renderer
17
+ autoload :FormBuilder
18
+
19
+ eager_autoload do
20
+ autoload :Caching
21
+ end
22
+
23
+ autoload_under "metal" do
24
+ autoload :ConditionalGet
25
+ autoload :ContentSecurityPolicy
26
+ autoload :Cookies
27
+ autoload :DataStreaming
28
+ autoload :DefaultHeaders
29
+ autoload :EtagWithTemplateDigest
30
+ autoload :EtagWithFlash
31
+ autoload :Flash
32
+ autoload :ForceSSL
33
+ autoload :Head
34
+ autoload :Helpers
35
+ autoload :HttpAuthentication
36
+ autoload :BasicImplicitRender
37
+ autoload :ImplicitRender
38
+ autoload :Instrumentation
39
+ autoload :MimeResponds
40
+ autoload :ParamsWrapper
41
+ autoload :Redirecting
42
+ autoload :Renderers
43
+ autoload :Rendering
44
+ autoload :RequestForgeryProtection
45
+ autoload :Rescue
46
+ autoload :Streaming
47
+ autoload :StrongParameters
48
+ autoload :ParameterEncoding
49
+ autoload :Testing
50
+ autoload :UrlFor
51
+ end
52
+
53
+ autoload_under "api" do
54
+ autoload :ApiRendering
55
+ end
56
+
57
+ autoload :TestCase, "action_controller/test_case"
58
+ autoload :TemplateAssertions, "action_controller/test_case"
59
+ end
60
+
61
+ # Common Active Support usage in Action Controller
62
+ require "active_support/core_ext/module/attribute_accessors"
63
+ require "active_support/core_ext/load_error"
64
+ require "active_support/core_ext/module/attr_internal"
65
+ require "active_support/core_ext/name_error"
66
+ require "active_support/core_ext/uri"
67
+ require "active_support/inflector"