actionpack 4.0.1 → 4.2.11.1

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 (241) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +402 -1173
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +7 -7
  5. data/lib/abstract_controller/base.rb +39 -7
  6. data/lib/abstract_controller/callbacks.rb +32 -53
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +26 -16
  9. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  10. data/lib/abstract_controller/rendering.rb +57 -127
  11. data/lib/abstract_controller/url_for.rb +1 -1
  12. data/lib/abstract_controller.rb +1 -2
  13. data/lib/action_controller/base.rb +19 -10
  14. data/lib/action_controller/caching/fragments.rb +7 -1
  15. data/lib/action_controller/caching.rb +2 -12
  16. data/lib/action_controller/log_subscriber.rb +29 -20
  17. data/lib/action_controller/metal/conditional_get.rb +37 -12
  18. data/lib/action_controller/metal/data_streaming.rb +1 -1
  19. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  20. data/lib/action_controller/metal/exceptions.rb +1 -1
  21. data/lib/action_controller/metal/flash.rb +17 -0
  22. data/lib/action_controller/metal/force_ssl.rb +2 -2
  23. data/lib/action_controller/metal/head.rb +8 -6
  24. data/lib/action_controller/metal/helpers.rb +6 -2
  25. data/lib/action_controller/metal/http_authentication.rb +45 -23
  26. data/lib/action_controller/metal/instrumentation.rb +9 -6
  27. data/lib/action_controller/metal/live.rb +173 -20
  28. data/lib/action_controller/metal/mime_responds.rb +127 -232
  29. data/lib/action_controller/metal/params_wrapper.rb +16 -9
  30. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  31. data/lib/action_controller/metal/redirecting.rb +34 -26
  32. data/lib/action_controller/metal/renderers.rb +39 -12
  33. data/lib/action_controller/metal/rendering.rb +41 -14
  34. data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
  35. data/lib/action_controller/metal/streaming.rb +19 -21
  36. data/lib/action_controller/metal/strong_parameters.rb +166 -22
  37. data/lib/action_controller/metal/testing.rb +0 -1
  38. data/lib/action_controller/metal/url_for.rb +11 -12
  39. data/lib/action_controller/metal.rb +14 -8
  40. data/lib/action_controller/model_naming.rb +1 -1
  41. data/lib/action_controller/railtie.rb +5 -1
  42. data/lib/action_controller/test_case.rb +160 -94
  43. data/lib/action_controller.rb +2 -18
  44. data/lib/action_dispatch/http/cache.rb +5 -4
  45. data/lib/action_dispatch/http/filter_parameters.rb +2 -2
  46. data/lib/action_dispatch/http/filter_redirect.rb +5 -4
  47. data/lib/action_dispatch/http/headers.rb +46 -10
  48. data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
  49. data/lib/action_dispatch/http/mime_type.rb +25 -26
  50. data/lib/action_dispatch/http/mime_types.rb +1 -0
  51. data/lib/action_dispatch/http/parameter_filter.rb +1 -1
  52. data/lib/action_dispatch/http/parameters.rb +25 -41
  53. data/lib/action_dispatch/http/request.rb +49 -32
  54. data/lib/action_dispatch/http/response.rb +127 -25
  55. data/lib/action_dispatch/http/upload.rb +9 -21
  56. data/lib/action_dispatch/http/url.rb +97 -70
  57. data/lib/action_dispatch/journey/formatter.rb +35 -19
  58. data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
  59. data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
  60. data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
  61. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  62. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  63. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
  64. data/lib/action_dispatch/journey/nodes/node.rb +4 -0
  65. data/lib/action_dispatch/journey/parser.rb +51 -59
  66. data/lib/action_dispatch/journey/parser.y +12 -10
  67. data/lib/action_dispatch/journey/path/pattern.rb +16 -19
  68. data/lib/action_dispatch/journey/route.rb +8 -19
  69. data/lib/action_dispatch/journey/router/strexp.rb +9 -6
  70. data/lib/action_dispatch/journey/router/utils.rb +54 -18
  71. data/lib/action_dispatch/journey/router.rb +53 -75
  72. data/lib/action_dispatch/journey/routes.rb +4 -0
  73. data/lib/action_dispatch/journey/scanner.rb +5 -5
  74. data/lib/action_dispatch/journey/visitors.rb +81 -60
  75. data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
  76. data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
  77. data/lib/action_dispatch/middleware/callbacks.rb +7 -7
  78. data/lib/action_dispatch/middleware/cookies.rb +119 -43
  79. data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
  80. data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
  81. data/lib/action_dispatch/middleware/flash.rb +37 -24
  82. data/lib/action_dispatch/middleware/params_parser.rb +2 -2
  83. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
  84. data/lib/action_dispatch/middleware/reloader.rb +11 -2
  85. data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
  86. data/lib/action_dispatch/middleware/request_id.rb +1 -1
  87. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  88. data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
  89. data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
  90. data/lib/action_dispatch/middleware/ssl.rb +10 -7
  91. data/lib/action_dispatch/middleware/static.rb +79 -23
  92. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  93. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  94. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
  95. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  96. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  97. data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
  98. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  99. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
  100. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  101. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  102. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
  103. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  104. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  105. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  106. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  107. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  108. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
  109. data/lib/action_dispatch/railtie.rb +5 -2
  110. data/lib/action_dispatch/request/session.rb +12 -0
  111. data/lib/action_dispatch/request/utils.rb +35 -0
  112. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  113. data/lib/action_dispatch/routing/inspector.rb +11 -17
  114. data/lib/action_dispatch/routing/mapper.rb +519 -312
  115. data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
  116. data/lib/action_dispatch/routing/redirection.rb +51 -26
  117. data/lib/action_dispatch/routing/route_set.rb +331 -206
  118. data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
  119. data/lib/action_dispatch/routing/url_for.rb +19 -5
  120. data/lib/action_dispatch/routing.rb +9 -6
  121. data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
  122. data/lib/action_dispatch/testing/assertions/response.rb +9 -15
  123. data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
  124. data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
  125. data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
  126. data/lib/action_dispatch/testing/assertions.rb +11 -7
  127. data/lib/action_dispatch/testing/integration.rb +31 -29
  128. data/lib/action_dispatch/testing/test_request.rb +1 -1
  129. data/lib/action_dispatch/testing/test_response.rb +1 -5
  130. data/lib/action_dispatch.rb +5 -8
  131. data/lib/action_pack/gem_version.rb +15 -0
  132. data/lib/action_pack/version.rb +4 -7
  133. data/lib/action_pack.rb +1 -1
  134. metadata +77 -159
  135. data/lib/abstract_controller/layouts.rb +0 -423
  136. data/lib/abstract_controller/view_paths.rb +0 -96
  137. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  138. data/lib/action_controller/deprecated.rb +0 -7
  139. data/lib/action_controller/metal/responder.rb +0 -287
  140. data/lib/action_controller/record_identifier.rb +0 -31
  141. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  142. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
  144. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
  145. data/lib/action_view/base.rb +0 -201
  146. data/lib/action_view/buffers.rb +0 -49
  147. data/lib/action_view/context.rb +0 -36
  148. data/lib/action_view/dependency_tracker.rb +0 -93
  149. data/lib/action_view/digestor.rb +0 -113
  150. data/lib/action_view/flows.rb +0 -76
  151. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  152. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  153. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  154. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  155. data/lib/action_view/helpers/cache_helper.rb +0 -196
  156. data/lib/action_view/helpers/capture_helper.rb +0 -216
  157. data/lib/action_view/helpers/controller_helper.rb +0 -25
  158. data/lib/action_view/helpers/csrf_helper.rb +0 -30
  159. data/lib/action_view/helpers/date_helper.rb +0 -1083
  160. data/lib/action_view/helpers/debug_helper.rb +0 -39
  161. data/lib/action_view/helpers/form_helper.rb +0 -1880
  162. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  163. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  164. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  165. data/lib/action_view/helpers/number_helper.rb +0 -441
  166. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  167. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  168. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  169. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  170. data/lib/action_view/helpers/tag_helper.rb +0 -173
  171. data/lib/action_view/helpers/tags/base.rb +0 -148
  172. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  173. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  174. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
  175. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  176. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  177. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  178. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  179. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  180. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  181. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  182. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  183. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  184. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  185. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  186. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  187. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  188. data/lib/action_view/helpers/tags/label.rb +0 -66
  189. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  190. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  191. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  192. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  193. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  194. data/lib/action_view/helpers/tags/search_field.rb +0 -24
  195. data/lib/action_view/helpers/tags/select.rb +0 -40
  196. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  197. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  198. data/lib/action_view/helpers/tags/text_field.rb +0 -29
  199. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  200. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  201. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  202. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  203. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  204. data/lib/action_view/helpers/tags.rb +0 -39
  205. data/lib/action_view/helpers/text_helper.rb +0 -443
  206. data/lib/action_view/helpers/translation_helper.rb +0 -107
  207. data/lib/action_view/helpers/url_helper.rb +0 -635
  208. data/lib/action_view/helpers.rb +0 -58
  209. data/lib/action_view/locale/en.yml +0 -56
  210. data/lib/action_view/log_subscriber.rb +0 -30
  211. data/lib/action_view/lookup_context.rb +0 -241
  212. data/lib/action_view/model_naming.rb +0 -12
  213. data/lib/action_view/path_set.rb +0 -77
  214. data/lib/action_view/railtie.rb +0 -43
  215. data/lib/action_view/record_identifier.rb +0 -84
  216. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  217. data/lib/action_view/renderer/partial_renderer.rb +0 -492
  218. data/lib/action_view/renderer/renderer.rb +0 -50
  219. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  220. data/lib/action_view/renderer/template_renderer.rb +0 -96
  221. data/lib/action_view/routing_url_for.rb +0 -107
  222. data/lib/action_view/tasks/dependencies.rake +0 -17
  223. data/lib/action_view/template/error.rb +0 -138
  224. data/lib/action_view/template/handlers/builder.rb +0 -26
  225. data/lib/action_view/template/handlers/erb.rb +0 -146
  226. data/lib/action_view/template/handlers/raw.rb +0 -11
  227. data/lib/action_view/template/handlers.rb +0 -53
  228. data/lib/action_view/template/resolver.rb +0 -326
  229. data/lib/action_view/template/text.rb +0 -34
  230. data/lib/action_view/template/types.rb +0 -57
  231. data/lib/action_view/template.rb +0 -339
  232. data/lib/action_view/test_case.rb +0 -270
  233. data/lib/action_view/testing/resolvers.rb +0 -50
  234. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  235. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  236. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  237. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  238. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  239. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
  240. data/lib/action_view/vendor/html-scanner.rb +0 -20
  241. data/lib/action_view.rb +0 -93
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2013 David Heinemeier Hansson
1
+ Copyright (c) 2004-2014 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -17,11 +17,6 @@ It consists of several modules:
17
17
  subclassed to implement filters and actions to handle requests. The result
18
18
  of an action is typically content generated from views.
19
19
 
20
- * Action View, which handles view template lookup and rendering, and provides
21
- view helpers that assist when building HTML forms, Atom feeds and more.
22
- Template formats that Action View handles are ERB (embedded Ruby, typically
23
- used to inline short Ruby snippets inside HTML), and XML Builder.
24
-
25
20
  With the Ruby on Rails framework, users only directly interface with the
26
21
  Action Controller module. Necessary Action Dispatch functionality is activated
27
22
  by default and Action View rendering is implicitly triggered by Action
@@ -37,7 +32,7 @@ The latest version of Action Pack can be installed with RubyGems:
37
32
 
38
33
  Source code can be downloaded as part of the Rails project on GitHub
39
34
 
40
- * https://github.com/rails/rails/tree/4-0-stable/actionpack
35
+ * https://github.com/rails/rails/tree/4-2-stable/actionpack
41
36
 
42
37
 
43
38
  == License
@@ -53,6 +48,11 @@ API documentation is at
53
48
 
54
49
  * http://api.rubyonrails.org
55
50
 
56
- Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
51
+ Bug reports can be filed for the Ruby on Rails project here:
57
52
 
58
53
  * https://github.com/rails/rails/issues
54
+
55
+ Feature requests should be discussed on the rails-core mailing list here:
56
+
57
+ * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
58
+
@@ -8,7 +8,8 @@ module AbstractController
8
8
  class Error < StandardError #:nodoc:
9
9
  end
10
10
 
11
- class ActionNotFound < StandardError #:nodoc:
11
+ # Raised when a non-existing controller action is triggered.
12
+ class ActionNotFound < StandardError
12
13
  end
13
14
 
14
15
  # <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
@@ -120,14 +121,14 @@ module AbstractController
120
121
  #
121
122
  # The actual method that is called is determined by calling
122
123
  # #method_for_action. If no method can handle the action, then an
123
- # ActionNotFound error is raised.
124
+ # AbstractController::ActionNotFound error is raised.
124
125
  #
125
126
  # ==== Returns
126
127
  # * <tt>self</tt>
127
128
  def process(action, *args)
128
- @_action_name = action_name = action.to_s
129
+ @_action_name = action.to_s
129
130
 
130
- unless action_name = method_for_action(action_name)
131
+ unless action_name = _find_action_name(@_action_name)
131
132
  raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
132
133
  end
133
134
 
@@ -160,7 +161,15 @@ module AbstractController
160
161
  # ==== Returns
161
162
  # * <tt>TrueClass</tt>, <tt>FalseClass</tt>
162
163
  def available_action?(action_name)
163
- method_for_action(action_name).present?
164
+ _find_action_name(action_name).present?
165
+ end
166
+
167
+ # Returns true if the given controller is capable of rendering
168
+ # a path. A subclass of +AbstractController::Base+
169
+ # may return false. An Email controller for example does not
170
+ # support paths, only full URLs.
171
+ def self.supports_path?
172
+ true
164
173
  end
165
174
 
166
175
  private
@@ -203,6 +212,24 @@ module AbstractController
203
212
  action_missing(@_action_name, *args)
204
213
  end
205
214
 
215
+ # Takes an action name and returns the name of the method that will
216
+ # handle the action.
217
+ #
218
+ # It checks if the action name is valid and returns false otherwise.
219
+ #
220
+ # See method_for_action for more information.
221
+ #
222
+ # ==== Parameters
223
+ # * <tt>action_name</tt> - An action name to find a method name for
224
+ #
225
+ # ==== Returns
226
+ # * <tt>string</tt> - The name of the method that handles the action
227
+ # * false - No valid method name could be found.
228
+ # Raise AbstractController::ActionNotFound.
229
+ def _find_action_name(action_name)
230
+ _valid_action_name?(action_name) && method_for_action(action_name)
231
+ end
232
+
206
233
  # Takes an action name and returns the name of the method that will
207
234
  # handle the action. In normal cases, this method returns the same
208
235
  # name as it receives. By default, if #method_for_action receives
@@ -218,14 +245,14 @@ module AbstractController
218
245
  # the case.
219
246
  #
220
247
  # If none of these conditions are true, and method_for_action
221
- # returns nil, an ActionNotFound exception will be raised.
248
+ # returns nil, an AbstractController::ActionNotFound exception will be raised.
222
249
  #
223
250
  # ==== Parameters
224
251
  # * <tt>action_name</tt> - An action name to find a method name for
225
252
  #
226
253
  # ==== Returns
227
254
  # * <tt>string</tt> - The name of the method that handles the action
228
- # * <tt>nil</tt> - No method name could be found. Raise ActionNotFound.
255
+ # * <tt>nil</tt> - No method name could be found.
229
256
  def method_for_action(action_name)
230
257
  if action_method?(action_name)
231
258
  action_name
@@ -233,5 +260,10 @@ module AbstractController
233
260
  "_handle_action_missing"
234
261
  end
235
262
  end
263
+
264
+ # Checks if the action name is valid and returns false otherwise.
265
+ def _valid_action_name?(action_name)
266
+ !action_name.to_s.include? File::SEPARATOR
267
+ end
236
268
  end
237
269
  end
@@ -8,7 +8,9 @@ module AbstractController
8
8
  include ActiveSupport::Callbacks
9
9
 
10
10
  included do
11
- define_callbacks :process_action, :terminator => "response_body", :skip_after_callbacks_if_terminated => true
11
+ define_callbacks :process_action,
12
+ terminator: ->(controller,_) { controller.response_body },
13
+ skip_after_callbacks_if_terminated: true
12
14
  end
13
15
 
14
16
  # Override AbstractController::Base's process_action to run the
@@ -40,20 +42,18 @@ module AbstractController
40
42
  end
41
43
  end
42
44
 
43
- # Skip before, after, and around action callbacks matching any of the names
44
- # Aliased as skip_filter.
45
+ # Skip before, after, and around action callbacks matching any of the names.
45
46
  #
46
47
  # ==== Parameters
47
48
  # * <tt>names</tt> - A list of valid names that could be used for
48
49
  # callbacks. Note that skipping uses Ruby equality, so it's
49
50
  # impossible to skip a callback defined using an anonymous proc
50
- # using #skip_filter
51
+ # using #skip_action_callback
51
52
  def skip_action_callback(*names)
52
53
  skip_before_action(*names)
53
54
  skip_after_action(*names)
54
55
  skip_around_action(*names)
55
56
  end
56
-
57
57
  alias_method :skip_filter, :skip_action_callback
58
58
 
59
59
  # Take callback names and an optional callback proc, normalize them,
@@ -69,7 +69,7 @@ module AbstractController
69
69
  # * <tt>name</tt> - The callback to be added
70
70
  # * <tt>options</tt> - A hash of options to be used when adding the callback
71
71
  def _insert_callbacks(callbacks, block = nil)
72
- options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
72
+ options = callbacks.extract_options!
73
73
  _normalize_callback_options(options)
74
74
  callbacks.push(block) if block
75
75
  callbacks.each do |callback|
@@ -83,7 +83,6 @@ module AbstractController
83
83
  # :call-seq: before_action(names, block)
84
84
  #
85
85
  # Append a callback before actions. See _insert_callbacks for parameter details.
86
- # Aliased as before_filter.
87
86
 
88
87
  ##
89
88
  # :method: prepend_before_action
@@ -91,7 +90,6 @@ module AbstractController
91
90
  # :call-seq: prepend_before_action(names, block)
92
91
  #
93
92
  # Prepend a callback before actions. See _insert_callbacks for parameter details.
94
- # Aliased as prepend_before_filter.
95
93
 
96
94
  ##
97
95
  # :method: skip_before_action
@@ -99,7 +97,6 @@ module AbstractController
99
97
  # :call-seq: skip_before_action(names)
100
98
  #
101
99
  # Skip a callback before actions. See _insert_callbacks for parameter details.
102
- # Aliased as skip_before_filter.
103
100
 
104
101
  ##
105
102
  # :method: append_before_action
@@ -107,7 +104,6 @@ module AbstractController
107
104
  # :call-seq: append_before_action(names, block)
108
105
  #
109
106
  # Append a callback before actions. See _insert_callbacks for parameter details.
110
- # Aliased as append_before_filter.
111
107
 
112
108
  ##
113
109
  # :method: after_action
@@ -115,7 +111,6 @@ module AbstractController
115
111
  # :call-seq: after_action(names, block)
116
112
  #
117
113
  # Append a callback after actions. See _insert_callbacks for parameter details.
118
- # Aliased as after_filter.
119
114
 
120
115
  ##
121
116
  # :method: prepend_after_action
@@ -123,7 +118,6 @@ module AbstractController
123
118
  # :call-seq: prepend_after_action(names, block)
124
119
  #
125
120
  # Prepend a callback after actions. See _insert_callbacks for parameter details.
126
- # Aliased as prepend_after_filter.
127
121
 
128
122
  ##
129
123
  # :method: skip_after_action
@@ -131,7 +125,6 @@ module AbstractController
131
125
  # :call-seq: skip_after_action(names)
132
126
  #
133
127
  # Skip a callback after actions. See _insert_callbacks for parameter details.
134
- # Aliased as skip_after_filter.
135
128
 
136
129
  ##
137
130
  # :method: append_after_action
@@ -139,7 +132,6 @@ module AbstractController
139
132
  # :call-seq: append_after_action(names, block)
140
133
  #
141
134
  # Append a callback after actions. See _insert_callbacks for parameter details.
142
- # Aliased as append_after_filter.
143
135
 
144
136
  ##
145
137
  # :method: around_action
@@ -147,7 +139,6 @@ module AbstractController
147
139
  # :call-seq: around_action(names, block)
148
140
  #
149
141
  # Append a callback around actions. See _insert_callbacks for parameter details.
150
- # Aliased as around_filter.
151
142
 
152
143
  ##
153
144
  # :method: prepend_around_action
@@ -155,7 +146,6 @@ module AbstractController
155
146
  # :call-seq: prepend_around_action(names, block)
156
147
  #
157
148
  # Prepend a callback around actions. See _insert_callbacks for parameter details.
158
- # Aliased as prepend_around_filter.
159
149
 
160
150
  ##
161
151
  # :method: skip_around_action
@@ -163,7 +153,6 @@ module AbstractController
163
153
  # :call-seq: skip_around_action(names)
164
154
  #
165
155
  # Skip a callback around actions. See _insert_callbacks for parameter details.
166
- # Aliased as skip_around_filter.
167
156
 
168
157
  ##
169
158
  # :method: append_around_action
@@ -171,46 +160,36 @@ module AbstractController
171
160
  # :call-seq: append_around_action(names, block)
172
161
  #
173
162
  # Append a callback around actions. See _insert_callbacks for parameter details.
174
- # Aliased as append_around_filter.
175
163
 
176
164
  # set up before_action, prepend_before_action, skip_before_action, etc.
177
165
  # for each of before, after, and around.
178
166
  [:before, :after, :around].each do |callback|
179
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
180
- # Append a before, after or around callback. See _insert_callbacks
181
- # for details on the allowed parameters.
182
- def #{callback}_action(*names, &blk) # def before_action(*names, &blk)
183
- _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
184
- set_callback(:process_action, :#{callback}, name, options) # set_callback(:process_action, :before, name, options)
185
- end # end
186
- end # end
187
-
188
- alias_method :#{callback}_filter, :#{callback}_action
189
-
190
- # Prepend a before, after or around callback. See _insert_callbacks
191
- # for details on the allowed parameters.
192
- def prepend_#{callback}_action(*names, &blk) # def prepend_before_action(*names, &blk)
193
- _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
194
- set_callback(:process_action, :#{callback}, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
195
- end # end
196
- end # end
197
-
198
- alias_method :prepend_#{callback}_filter, :prepend_#{callback}_action
199
-
200
- # Skip a before, after or around callback. See _insert_callbacks
201
- # for details on the allowed parameters.
202
- def skip_#{callback}_action(*names) # def skip_before_action(*names)
203
- _insert_callbacks(names) do |name, options| # _insert_callbacks(names) do |name, options|
204
- skip_callback(:process_action, :#{callback}, name, options) # skip_callback(:process_action, :before, name, options)
205
- end # end
206
- end # end
207
-
208
- alias_method :skip_#{callback}_filter, :skip_#{callback}_action
209
-
210
- # *_action is the same as append_*_action
211
- alias_method :append_#{callback}_action, :#{callback}_action # alias_method :append_before_action, :before_action
212
- alias_method :append_#{callback}_filter, :#{callback}_action # alias_method :append_before_filter, :before_action
213
- RUBY_EVAL
167
+ define_method "#{callback}_action" do |*names, &blk|
168
+ _insert_callbacks(names, blk) do |name, options|
169
+ set_callback(:process_action, callback, name, options)
170
+ end
171
+ end
172
+ alias_method :"#{callback}_filter", :"#{callback}_action"
173
+
174
+ define_method "prepend_#{callback}_action" do |*names, &blk|
175
+ _insert_callbacks(names, blk) do |name, options|
176
+ set_callback(:process_action, callback, name, options.merge(:prepend => true))
177
+ end
178
+ end
179
+ alias_method :"prepend_#{callback}_filter", :"prepend_#{callback}_action"
180
+
181
+ # Skip a before, after or around callback. See _insert_callbacks
182
+ # for details on the allowed parameters.
183
+ define_method "skip_#{callback}_action" do |*names|
184
+ _insert_callbacks(names) do |name, options|
185
+ skip_callback(:process_action, callback, name, options)
186
+ end
187
+ end
188
+ alias_method :"skip_#{callback}_filter", :"skip_#{callback}_action"
189
+
190
+ # *_action is the same as append_*_action
191
+ alias_method :"append_#{callback}_action", :"#{callback}_action"
192
+ alias_method :"append_#{callback}_filter", :"#{callback}_action"
214
193
  end
215
194
  end
216
195
  end
@@ -23,7 +23,17 @@ module AbstractController
23
23
  protected
24
24
 
25
25
  def method_missing(symbol, &block)
26
- mime_constant = Mime.const_get(symbol.upcase)
26
+ const_name = symbol.upcase
27
+
28
+ unless Mime.const_defined?(const_name)
29
+ raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
30
+ "http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
31
+ "If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
32
+ "be sure to nest your variant response within a format response: " \
33
+ "format.html { |html| html.tablet { ... } }"
34
+ end
35
+
36
+ mime_constant = Mime.const_get(const_name)
27
37
 
28
38
  if Mime::SET.include?(mime_constant)
29
39
  AbstractController::Collector.generate_method_for_mime(mime_constant)
@@ -12,6 +12,20 @@ module AbstractController
12
12
  self._helper_methods = Array.new
13
13
  end
14
14
 
15
+ class MissingHelperError < LoadError
16
+ def initialize(error, path)
17
+ @error = error
18
+ @path = "helpers/#{path}.rb"
19
+ set_backtrace error.backtrace
20
+
21
+ if error.path =~ /^#{path}(\.rb)?$/
22
+ super("Missing helper file helpers/%s.rb" % path)
23
+ else
24
+ raise error
25
+ end
26
+ end
27
+ end
28
+
15
29
  module ClassMethods
16
30
  # When a class is inherited, wrap its helper module in a new module.
17
31
  # This ensures that the parent class's module can be changed
@@ -134,9 +148,19 @@ module AbstractController
134
148
  begin
135
149
  require_dependency(file_name)
136
150
  rescue LoadError => e
137
- raise MissingHelperError.new(e, file_name)
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"
138
163
  end
139
- file_name.camelize.constantize
140
164
  when Module
141
165
  arg
142
166
  else
@@ -145,20 +169,6 @@ module AbstractController
145
169
  end
146
170
  end
147
171
 
148
- class MissingHelperError < LoadError
149
- def initialize(error, path)
150
- @error = error
151
- @path = "helpers/#{path}.rb"
152
- set_backtrace error.backtrace
153
-
154
- if error.path =~ /^#{path}(\.rb)?$/
155
- super("Missing helper file helpers/%s.rb" % path)
156
- else
157
- raise error
158
- end
159
- end
160
- end
161
-
162
172
  private
163
173
  # Makes all the (instance) methods in the helper module available to templates
164
174
  # rendered through this controller.
@@ -1,14 +1,14 @@
1
1
  module AbstractController
2
2
  module Railties
3
3
  module RoutesHelpers
4
- def self.with(routes)
4
+ def self.with(routes, include_path_helpers = true)
5
5
  Module.new do
6
6
  define_method(:inherited) do |klass|
7
7
  super(klass)
8
8
  if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
9
- klass.send(:include, namespace.railtie_routes_url_helpers)
9
+ klass.send(:include, namespace.railtie_routes_url_helpers(include_path_helpers))
10
10
  else
11
- klass.send(:include, routes.url_helpers)
11
+ klass.send(:include, routes.url_helpers(include_path_helpers))
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,8 @@
1
- require "abstract_controller/base"
2
- require "action_view"
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/class/attribute'
3
+ require 'action_view'
4
+ require 'action_view/view_paths'
5
+ require 'set'
3
6
 
4
7
  module AbstractController
5
8
  class DoubleRenderError < Error
@@ -10,91 +13,18 @@ module AbstractController
10
13
  end
11
14
  end
12
15
 
13
- # This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
14
- # it will trigger the lookup_context and consequently expire the cache.
15
- class I18nProxy < ::I18n::Config #:nodoc:
16
- attr_reader :original_config, :lookup_context
17
-
18
- def initialize(original_config, lookup_context)
19
- original_config = original_config.original_config if original_config.respond_to?(:original_config)
20
- @original_config, @lookup_context = original_config, lookup_context
21
- end
22
-
23
- def locale
24
- @original_config.locale
25
- end
26
-
27
- def locale=(value)
28
- @lookup_context.locale = value
29
- end
30
- end
31
-
32
16
  module Rendering
33
17
  extend ActiveSupport::Concern
34
- include AbstractController::ViewPaths
35
-
36
- included do
37
- class_attribute :protected_instance_variables
38
- self.protected_instance_variables = []
39
- end
40
-
41
- # Overwrite process to setup I18n proxy.
42
- def process(*) #:nodoc:
43
- old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
44
- super
45
- ensure
46
- I18n.config = old_config
47
- end
48
-
49
- module ClassMethods
50
- def view_context_class
51
- @view_context_class ||= begin
52
- routes = respond_to?(:_routes) && _routes
53
- helpers = respond_to?(:_helpers) && _helpers
54
-
55
- Class.new(ActionView::Base) do
56
- if routes
57
- include routes.url_helpers
58
- include routes.mounted_helpers
59
- end
60
-
61
- if helpers
62
- include helpers
63
- end
64
- end
65
- end
66
- end
67
- end
68
-
69
- attr_internal_writer :view_context_class
70
-
71
- def view_context_class
72
- @_view_context_class ||= self.class.view_context_class
73
- end
74
-
75
- # An instance of a view class. The default view class is ActionView::Base
76
- #
77
- # The view class must have the following methods:
78
- # View.new[lookup_context, assigns, controller]
79
- # Create a new ActionView instance for a controller
80
- # View#render[options]
81
- # Returns String with the rendered template
82
- #
83
- # Override this method in a module to change the default behavior.
84
- def view_context
85
- view_context_class.new(view_renderer, view_assigns, self)
86
- end
87
-
88
- # Returns an object that is able to render templates.
89
- def view_renderer
90
- @_view_renderer ||= ActionView::Renderer.new(lookup_context)
91
- end
18
+ include ActionView::ViewPaths
92
19
 
93
20
  # Normalize arguments, options and then delegates render_to_body and
94
21
  # sticks the result in self.response_body.
22
+ # :api: public
95
23
  def render(*args, &block)
96
24
  options = _normalize_render(*args, &block)
97
25
  self.response_body = render_to_body(options)
26
+ _process_format(rendered_format, options) if rendered_format
27
+ self.response_body
98
28
  end
99
29
 
100
30
  # Raw rendering of a template to a string.
@@ -113,84 +43,84 @@ module AbstractController
113
43
  render_to_body(options)
114
44
  end
115
45
 
116
- # Raw rendering of a template.
117
- # :api: plugin
46
+ # Performs the actual template rendering.
47
+ # :api: public
118
48
  def render_to_body(options = {})
119
- _process_options(options)
120
- _render_template(options)
121
49
  end
122
50
 
123
- # Find and renders a template based on the options given.
124
- # :api: private
125
- def _render_template(options) #:nodoc:
126
- lookup_context.rendered_format = nil if options[:formats]
127
- view_renderer.render(view_context, options)
51
+ # Returns Content-Type of rendered content
52
+ # :api: public
53
+ def rendered_format
54
+ Mime::TEXT
128
55
  end
129
56
 
130
- DEFAULT_PROTECTED_INSTANCE_VARIABLES = [
131
- :@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config,
132
- :@_view_context_class, :@_view_renderer, :@_lookup_context
133
- ]
57
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %w(
58
+ @_action_name @_response_body @_formats @_prefixes @_config
59
+ @_view_context_class @_view_renderer @_lookup_context
60
+ @_routes @_db_runtime
61
+ ).map(&:to_sym)
134
62
 
135
63
  # This method should return a hash with assigns.
136
64
  # You can overwrite this configuration per controller.
137
65
  # :api: public
138
66
  def view_assigns
139
- hash = {}
140
- variables = instance_variables
141
- variables -= protected_instance_variables
142
- variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
143
- variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
144
- hash
145
- end
146
-
147
- private
67
+ protected_vars = _protected_ivars
68
+ variables = instance_variables
148
69
 
149
- # Normalize args and options.
150
- # :api: private
151
- def _normalize_render(*args, &block)
152
- options = _normalize_args(*args, &block)
153
- _normalize_options(options)
154
- options
70
+ variables.reject! { |s| protected_vars.include? s }
71
+ variables.each_with_object({}) { |name, hash|
72
+ hash[name.slice(1, name.length)] = instance_variable_get(name)
73
+ }
155
74
  end
156
75
 
157
76
  # Normalize args by converting render "foo" to render :action => "foo" and
158
77
  # render "foo/bar" to render :file => "foo/bar".
159
78
  # :api: plugin
160
79
  def _normalize_args(action=nil, options={})
161
- case action
162
- when NilClass
163
- when Hash
164
- options = action
165
- when String, Symbol
166
- action = action.to_s
167
- key = action.include?(?/) ? :file : :action
168
- options[key] = action
80
+ if action.respond_to?(:permitted?)
81
+ if action.permitted?
82
+ action
83
+ else
84
+ raise ArgumentError, "render parameters are not permitted"
85
+ end
86
+ elsif action.is_a?(Hash)
87
+ action
169
88
  else
170
- options[:partial] = action
89
+ options
171
90
  end
172
-
173
- options
174
91
  end
175
92
 
176
93
  # Normalize options.
177
94
  # :api: plugin
178
95
  def _normalize_options(options)
179
- if options[:partial] == true
180
- options[:partial] = action_name
181
- end
182
-
183
- if (options.keys & [:partial, :file, :template]).empty?
184
- options[:prefixes] ||= _prefixes
185
- end
186
-
187
- options[:template] ||= (options[:action] || action_name).to_s
188
96
  options
189
97
  end
190
98
 
191
99
  # Process extra options.
192
100
  # :api: plugin
193
101
  def _process_options(options)
102
+ options
103
+ end
104
+
105
+ # Process the rendered format.
106
+ # :api: private
107
+ def _process_format(format, options = {})
108
+ end
109
+
110
+ # Normalize args and options.
111
+ # :api: private
112
+ def _normalize_render(*args, &block)
113
+ options = _normalize_args(*args, &block)
114
+ #TODO: remove defined? when we restore AP <=> AV dependency
115
+ if defined?(request) && request && request.variant.present?
116
+ options[:variant] = request.variant
117
+ end
118
+ _normalize_options(options)
119
+ options
120
+ end
121
+
122
+ def _protected_ivars # :nodoc:
123
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES
194
124
  end
195
125
  end
196
126
  end