actionpack 3.2.22.5 → 5.2.4

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 (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +279 -603
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +13 -297
  5. data/lib/abstract_controller/asset_paths.rb +4 -2
  6. data/lib/abstract_controller/base.rb +82 -52
  7. data/lib/abstract_controller/caching/fragments.rb +166 -0
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +117 -103
  10. data/lib/abstract_controller/collector.rb +18 -7
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +65 -38
  13. data/lib/abstract_controller/logger.rb +3 -2
  14. data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
  15. data/lib/abstract_controller/rendering.rb +77 -129
  16. data/lib/abstract_controller/translation.rb +21 -3
  17. data/lib/abstract_controller/url_for.rb +9 -7
  18. data/lib/abstract_controller.rb +12 -13
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +149 -0
  21. data/lib/action_controller/base.rb +81 -40
  22. data/lib/action_controller/caching.rb +22 -62
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +30 -18
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +190 -47
  27. data/lib/action_controller/metal/content_security_policy.rb +52 -0
  28. data/lib/action_controller/metal/cookies.rb +3 -3
  29. data/lib/action_controller/metal/data_streaming.rb +40 -65
  30. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  31. data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
  32. data/lib/action_controller/metal/exceptions.rb +19 -12
  33. data/lib/action_controller/metal/flash.rb +42 -9
  34. data/lib/action_controller/metal/force_ssl.rb +79 -19
  35. data/lib/action_controller/metal/head.rb +35 -10
  36. data/lib/action_controller/metal/helpers.rb +31 -21
  37. data/lib/action_controller/metal/http_authentication.rb +182 -134
  38. data/lib/action_controller/metal/implicit_render.rb +62 -8
  39. data/lib/action_controller/metal/instrumentation.rb +28 -26
  40. data/lib/action_controller/metal/live.rb +312 -0
  41. data/lib/action_controller/metal/mime_responds.rb +159 -163
  42. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  43. data/lib/action_controller/metal/params_wrapper.rb +146 -93
  44. data/lib/action_controller/metal/redirecting.rb +80 -56
  45. data/lib/action_controller/metal/renderers.rb +119 -47
  46. data/lib/action_controller/metal/rendering.rb +89 -32
  47. data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
  48. data/lib/action_controller/metal/rescue.rb +9 -16
  49. data/lib/action_controller/metal/streaming.rb +39 -45
  50. data/lib/action_controller/metal/strong_parameters.rb +1086 -0
  51. data/lib/action_controller/metal/testing.rb +8 -29
  52. data/lib/action_controller/metal/url_for.rb +43 -32
  53. data/lib/action_controller/metal.rb +112 -106
  54. data/lib/action_controller/railtie.rb +56 -18
  55. data/lib/action_controller/railties/helpers.rb +24 -0
  56. data/lib/action_controller/renderer.rb +117 -0
  57. data/lib/action_controller/template_assertions.rb +11 -0
  58. data/lib/action_controller/test_case.rb +402 -347
  59. data/lib/action_controller.rb +31 -30
  60. data/lib/action_dispatch/http/cache.rb +133 -34
  61. data/lib/action_dispatch/http/content_security_policy.rb +272 -0
  62. data/lib/action_dispatch/http/filter_parameters.rb +40 -24
  63. data/lib/action_dispatch/http/filter_redirect.rb +37 -0
  64. data/lib/action_dispatch/http/headers.rb +117 -16
  65. data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
  66. data/lib/action_dispatch/http/mime_type.rb +198 -146
  67. data/lib/action_dispatch/http/mime_types.rb +22 -7
  68. data/lib/action_dispatch/http/parameter_filter.rb +61 -49
  69. data/lib/action_dispatch/http/parameters.rb +94 -51
  70. data/lib/action_dispatch/http/rack_cache.rb +4 -3
  71. data/lib/action_dispatch/http/request.rb +262 -117
  72. data/lib/action_dispatch/http/response.rb +400 -86
  73. data/lib/action_dispatch/http/upload.rb +66 -29
  74. data/lib/action_dispatch/http/url.rb +232 -60
  75. data/lib/action_dispatch/journey/formatter.rb +189 -0
  76. data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
  77. data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
  78. data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
  79. data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
  80. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  81. data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
  82. data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
  83. data/lib/action_dispatch/journey/nodes/node.rb +140 -0
  84. data/lib/action_dispatch/journey/parser.rb +199 -0
  85. data/lib/action_dispatch/journey/parser.y +50 -0
  86. data/lib/action_dispatch/journey/parser_extras.rb +31 -0
  87. data/lib/action_dispatch/journey/path/pattern.rb +199 -0
  88. data/lib/action_dispatch/journey/route.rb +203 -0
  89. data/lib/action_dispatch/journey/router/utils.rb +102 -0
  90. data/lib/action_dispatch/journey/router.rb +156 -0
  91. data/lib/action_dispatch/journey/routes.rb +82 -0
  92. data/lib/action_dispatch/journey/scanner.rb +64 -0
  93. data/lib/action_dispatch/journey/visitors.rb +268 -0
  94. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  95. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  96. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  97. data/lib/action_dispatch/journey.rb +7 -0
  98. data/lib/action_dispatch/middleware/callbacks.rb +17 -13
  99. data/lib/action_dispatch/middleware/cookies.rb +494 -162
  100. data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
  101. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  102. data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
  103. data/lib/action_dispatch/middleware/executor.rb +21 -0
  104. data/lib/action_dispatch/middleware/flash.rb +128 -91
  105. data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
  106. data/lib/action_dispatch/middleware/reloader.rb +6 -83
  107. data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
  108. data/lib/action_dispatch/middleware/request_id.rb +19 -15
  109. data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
  110. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
  111. data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
  112. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
  113. data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
  114. data/lib/action_dispatch/middleware/ssl.rb +150 -0
  115. data/lib/action_dispatch/middleware/stack.rb +33 -41
  116. data/lib/action_dispatch/middleware/static.rb +92 -48
  117. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  123. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
  128. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  136. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  137. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  138. data/lib/action_dispatch/railtie.rb +29 -8
  139. data/lib/action_dispatch/request/session.rb +234 -0
  140. data/lib/action_dispatch/request/utils.rb +78 -0
  141. data/lib/action_dispatch/routing/endpoint.rb +17 -0
  142. data/lib/action_dispatch/routing/inspector.rb +225 -0
  143. data/lib/action_dispatch/routing/mapper.rb +1329 -582
  144. data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
  145. data/lib/action_dispatch/routing/redirection.rb +120 -50
  146. data/lib/action_dispatch/routing/route_set.rb +545 -322
  147. data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
  148. data/lib/action_dispatch/routing/url_for.rb +103 -34
  149. data/lib/action_dispatch/routing.rb +66 -99
  150. data/lib/action_dispatch/system_test_case.rb +147 -0
  151. data/lib/action_dispatch/system_testing/browser.rb +49 -0
  152. data/lib/action_dispatch/system_testing/driver.rb +59 -0
  153. data/lib/action_dispatch/system_testing/server.rb +31 -0
  154. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
  156. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +47 -0
  158. data/lib/action_dispatch/testing/assertions/response.rb +53 -42
  159. data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
  160. data/lib/action_dispatch/testing/assertions.rb +15 -9
  161. data/lib/action_dispatch/testing/integration.rb +361 -207
  162. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  163. data/lib/action_dispatch/testing/test_process.rb +28 -19
  164. data/lib/action_dispatch/testing/test_request.rb +30 -33
  165. data/lib/action_dispatch/testing/test_response.rb +35 -11
  166. data/lib/action_dispatch.rb +42 -32
  167. data/lib/action_pack/gem_version.rb +17 -0
  168. data/lib/action_pack/version.rb +7 -7
  169. data/lib/action_pack.rb +4 -2
  170. metadata +116 -175
  171. data/lib/abstract_controller/layouts.rb +0 -423
  172. data/lib/abstract_controller/view_paths.rb +0 -96
  173. data/lib/action_controller/caching/actions.rb +0 -185
  174. data/lib/action_controller/caching/fragments.rb +0 -127
  175. data/lib/action_controller/caching/pages.rb +0 -187
  176. data/lib/action_controller/caching/sweeping.rb +0 -97
  177. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  178. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  179. data/lib/action_controller/deprecated.rb +0 -3
  180. data/lib/action_controller/metal/compatibility.rb +0 -65
  181. data/lib/action_controller/metal/hide_actions.rb +0 -41
  182. data/lib/action_controller/metal/rack_delegation.rb +0 -26
  183. data/lib/action_controller/metal/responder.rb +0 -286
  184. data/lib/action_controller/metal/session_management.rb +0 -14
  185. data/lib/action_controller/middleware.rb +0 -39
  186. data/lib/action_controller/railties/paths.rb +0 -25
  187. data/lib/action_controller/record_identifier.rb +0 -85
  188. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  189. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  190. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  191. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  192. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  193. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  194. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  195. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  196. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  197. data/lib/action_dispatch/middleware/head.rb +0 -18
  198. data/lib/action_dispatch/middleware/params_parser.rb +0 -75
  199. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  200. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  201. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  202. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  203. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  204. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  205. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  206. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  207. data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
  208. data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
  209. data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
  210. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  211. data/lib/action_view/asset_paths.rb +0 -142
  212. data/lib/action_view/base.rb +0 -220
  213. data/lib/action_view/buffers.rb +0 -43
  214. data/lib/action_view/context.rb +0 -36
  215. data/lib/action_view/flows.rb +0 -79
  216. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  217. data/lib/action_view/helpers/asset_paths.rb +0 -7
  218. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  219. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  220. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  221. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  222. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  223. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  224. data/lib/action_view/helpers/cache_helper.rb +0 -64
  225. data/lib/action_view/helpers/capture_helper.rb +0 -203
  226. data/lib/action_view/helpers/controller_helper.rb +0 -25
  227. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  228. data/lib/action_view/helpers/date_helper.rb +0 -1062
  229. data/lib/action_view/helpers/debug_helper.rb +0 -40
  230. data/lib/action_view/helpers/form_helper.rb +0 -1486
  231. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  232. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  233. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  234. data/lib/action_view/helpers/number_helper.rb +0 -622
  235. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  236. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  237. data/lib/action_view/helpers/rendering_helper.rb +0 -92
  238. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  239. data/lib/action_view/helpers/tag_helper.rb +0 -167
  240. data/lib/action_view/helpers/text_helper.rb +0 -426
  241. data/lib/action_view/helpers/translation_helper.rb +0 -91
  242. data/lib/action_view/helpers/url_helper.rb +0 -693
  243. data/lib/action_view/helpers.rb +0 -60
  244. data/lib/action_view/locale/en.yml +0 -160
  245. data/lib/action_view/log_subscriber.rb +0 -28
  246. data/lib/action_view/lookup_context.rb +0 -258
  247. data/lib/action_view/path_set.rb +0 -101
  248. data/lib/action_view/railtie.rb +0 -55
  249. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  250. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  251. data/lib/action_view/renderer/renderer.rb +0 -61
  252. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  253. data/lib/action_view/renderer/template_renderer.rb +0 -95
  254. data/lib/action_view/template/error.rb +0 -128
  255. data/lib/action_view/template/handlers/builder.rb +0 -26
  256. data/lib/action_view/template/handlers/erb.rb +0 -125
  257. data/lib/action_view/template/handlers.rb +0 -50
  258. data/lib/action_view/template/resolver.rb +0 -298
  259. data/lib/action_view/template/text.rb +0 -30
  260. data/lib/action_view/template.rb +0 -337
  261. data/lib/action_view/test_case.rb +0 -246
  262. data/lib/action_view/testing/resolvers.rb +0 -49
  263. data/lib/action_view.rb +0 -84
  264. data/lib/sprockets/assets.rake +0 -99
  265. data/lib/sprockets/bootstrap.rb +0 -37
  266. data/lib/sprockets/compressors.rb +0 -83
  267. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  268. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  269. data/lib/sprockets/helpers.rb +0 -6
  270. data/lib/sprockets/railtie.rb +0 -62
  271. data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,127 +0,0 @@
1
- module ActionController #:nodoc:
2
- module Caching
3
- # Fragment caching is used for caching various blocks within
4
- # views without caching the entire action as a whole. This is
5
- # useful when certain elements of an action change frequently or
6
- # depend on complicated state while other parts rarely change or
7
- # can be shared amongst multiple parties. The caching is done using
8
- # the <tt>cache</tt> helper available in the Action View. A
9
- # template with fragment caching might look like:
10
- #
11
- # <b>Hello <%= @name %></b>
12
- #
13
- # <% cache do %>
14
- # All the topics in the system:
15
- # <%= render :partial => "topic", :collection => Topic.all %>
16
- # <% end %>
17
- #
18
- # This cache will bind the name of the action that called it, so if
19
- # this code was part of the view for the topics/list action, you
20
- # would be able to invalidate it using:
21
- #
22
- # expire_fragment(:controller => "topics", :action => "list")
23
- #
24
- # This default behavior is limited if you need to cache multiple
25
- # fragments per action or if the action itself is cached using
26
- # <tt>caches_action</tt>. To remedy this, there is an option to
27
- # qualify the name of the cached fragment by using the
28
- # <tt>:action_suffix</tt> option:
29
- #
30
- # <% cache(:action => "list", :action_suffix => "all_topics") do %>
31
- #
32
- # That would result in a name such as
33
- # <tt>/topics/list/all_topics</tt>, avoiding conflicts with the
34
- # action cache and with any fragments that use a different suffix.
35
- # Note that the URL doesn't have to really exist or be callable
36
- # - the url_for system is just used to generate unique cache names
37
- # that we can refer to when we need to expire the cache.
38
- #
39
- # The expiration call for this example is:
40
- #
41
- # expire_fragment(:controller => "topics",
42
- # :action => "list",
43
- # :action_suffix => "all_topics")
44
- module Fragments
45
- # Given a key (as described in <tt>expire_fragment</tt>), returns
46
- # a key suitable for use in reading, writing, or expiring a
47
- # cached fragment. If the key is a hash, the generated key is the
48
- # return value of url_for on that hash (without the protocol).
49
- # All keys are prefixed with <tt>views/</tt> and uses
50
- # ActiveSupport::Cache.expand_cache_key for the expansion.
51
- def fragment_cache_key(key)
52
- ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
53
- end
54
-
55
- # Writes <tt>content</tt> to the location signified by
56
- # <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats).
57
- def write_fragment(key, content, options = nil)
58
- return content unless cache_configured?
59
-
60
- key = fragment_cache_key(key)
61
- instrument_fragment_cache :write_fragment, key do
62
- content = content.to_str
63
- cache_store.write(key, content, options)
64
- end
65
- content
66
- end
67
-
68
- # Reads a cached fragment from the location signified by <tt>key</tt>
69
- # (see <tt>expire_fragment</tt> for acceptable formats).
70
- def read_fragment(key, options = nil)
71
- return unless cache_configured?
72
-
73
- key = fragment_cache_key(key)
74
- instrument_fragment_cache :read_fragment, key do
75
- result = cache_store.read(key, options)
76
- result.respond_to?(:html_safe) ? result.html_safe : result
77
- end
78
- end
79
-
80
- # Check if a cached fragment from the location signified by
81
- # <tt>key</tt> exists (see <tt>expire_fragment</tt> for acceptable formats)
82
- def fragment_exist?(key, options = nil)
83
- return unless cache_configured?
84
- key = fragment_cache_key(key)
85
-
86
- instrument_fragment_cache :exist_fragment?, key do
87
- cache_store.exist?(key, options)
88
- end
89
- end
90
-
91
- # Removes fragments from the cache.
92
- #
93
- # +key+ can take one of three forms:
94
- #
95
- # * String - This would normally take the form of a path, like
96
- # <tt>pages/45/notes</tt>.
97
- # * Hash - Treated as an implicit call to +url_for+, like
98
- # <tt>{:controller => "pages", :action => "notes", :id => 45}</tt>
99
- # * Regexp - Will remove any fragment that matches, so
100
- # <tt>%r{pages/\d*/notes}</tt> might remove all notes. Make sure you
101
- # don't use anchors in the regex (<tt>^</tt> or <tt>$</tt>) because
102
- # the actual filename matched looks like
103
- # <tt>./cache/filename/path.cache</tt>. Note: Regexp expiration is
104
- # only supported on caches that can iterate over all keys (unlike
105
- # memcached).
106
- #
107
- # +options+ is passed through to the cache store's <tt>delete</tt>
108
- # method (or <tt>delete_matched</tt>, for Regexp keys.)
109
- def expire_fragment(key, options = nil)
110
- return unless cache_configured?
111
- key = fragment_cache_key(key) unless key.is_a?(Regexp)
112
-
113
- instrument_fragment_cache :expire_fragment, key do
114
- if key.is_a?(Regexp)
115
- cache_store.delete_matched(key, options)
116
- else
117
- cache_store.delete(key, options)
118
- end
119
- end
120
- end
121
-
122
- def instrument_fragment_cache(name, key)
123
- ActiveSupport::Notifications.instrument("#{name}.action_controller", :key => key){ yield }
124
- end
125
- end
126
- end
127
- end
@@ -1,187 +0,0 @@
1
- require 'fileutils'
2
- require 'active_support/core_ext/class/attribute_accessors'
3
-
4
- module ActionController #:nodoc:
5
- module Caching
6
- # Page caching is an approach to caching where the entire action output of is stored as a HTML file that the web server
7
- # can serve without going through Action Pack. This is the fastest way to cache your content as opposed to going dynamically
8
- # through the process of generating the content. Unfortunately, this incredible speed-up is only available to stateless pages
9
- # where all visitors are treated the same. Content management systems -- including weblogs and wikis -- have many pages that are
10
- # a great fit for this approach, but account-based systems where people log in and manipulate their own data are often less
11
- # likely candidates.
12
- #
13
- # Specifying which actions to cache is done through the <tt>caches_page</tt> class method:
14
- #
15
- # class WeblogController < ActionController::Base
16
- # caches_page :show, :new
17
- # end
18
- #
19
- # This will generate cache files such as <tt>weblog/show/5.html</tt> and <tt>weblog/new.html</tt>, which match the URLs used
20
- # that would normally trigger dynamic page generation. Page caching works by configuring a web server to first check for the
21
- # existence of files on disk, and to serve them directly when found, without passing the request through to Action Pack.
22
- # This is much faster than handling the full dynamic request in the usual way.
23
- #
24
- # Expiration of the cache is handled by deleting the cached file, which results in a lazy regeneration approach where the cache
25
- # is not restored before another hit is made against it. The API for doing so mimics the options from +url_for+ and friends:
26
- #
27
- # class WeblogController < ActionController::Base
28
- # def update
29
- # List.update(params[:list][:id], params[:list])
30
- # expire_page :action => "show", :id => params[:list][:id]
31
- # redirect_to :action => "show", :id => params[:list][:id]
32
- # end
33
- # end
34
- #
35
- # Additionally, you can expire caches using Sweepers that act on changes in the model to determine when a cache is supposed to be
36
- # expired.
37
- module Pages
38
- extend ActiveSupport::Concern
39
-
40
- included do
41
- # The cache directory should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>.
42
- # For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing
43
- # this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
44
- # web server to look in the new location for cached files.
45
- class_attribute :page_cache_directory
46
- self.page_cache_directory ||= ''
47
-
48
- # Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
49
- # order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
50
- # If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
51
- # extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
52
- class_attribute :page_cache_extension
53
- self.page_cache_extension ||= '.html'
54
-
55
- # The compression used for gzip. If false (default), the page is not compressed.
56
- # If can be a symbol showing the ZLib compression method, for example, :best_compression
57
- # or :best_speed or an integer configuring the compression level.
58
- class_attribute :page_cache_compression
59
- self.page_cache_compression ||= false
60
- end
61
-
62
- module ClassMethods
63
- # Expires the page that was cached with the +path+ as a key. Example:
64
- # expire_page "/lists/show"
65
- def expire_page(path)
66
- return unless perform_caching
67
- path = page_cache_path(path)
68
-
69
- instrument_page_cache :expire_page, path do
70
- File.delete(path) if File.exist?(path)
71
- File.delete(path + '.gz') if File.exist?(path + '.gz')
72
- end
73
- end
74
-
75
- # Manually cache the +content+ in the key determined by +path+. Example:
76
- # cache_page "I'm the cached content", "/lists/show"
77
- def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
78
- return unless perform_caching
79
- path = page_cache_path(path, extension)
80
-
81
- instrument_page_cache :write_page, path do
82
- FileUtils.makedirs(File.dirname(path))
83
- File.open(path, "wb+") { |f| f.write(content) }
84
- if gzip
85
- Zlib::GzipWriter.open(path + '.gz', gzip) { |f| f.write(content) }
86
- end
87
- end
88
- end
89
-
90
- # Caches the +actions+ using the page-caching approach that'll store
91
- # the cache in a path within the page_cache_directory that
92
- # matches the triggering url.
93
- #
94
- # You can also pass a :gzip option to override the class configuration one.
95
- #
96
- # Usage:
97
- #
98
- # # cache the index action
99
- # caches_page :index
100
- #
101
- # # cache the index action except for JSON requests
102
- # caches_page :index, :if => Proc.new { |c| !c.request.format.json? }
103
- #
104
- # # don't gzip images
105
- # caches_page :image, :gzip => false
106
- def caches_page(*actions)
107
- return unless perform_caching
108
- options = actions.extract_options!
109
-
110
- gzip_level = options.fetch(:gzip, page_cache_compression)
111
- gzip_level = case gzip_level
112
- when Symbol
113
- Zlib.const_get(gzip_level.to_s.upcase)
114
- when Fixnum
115
- gzip_level
116
- when false
117
- nil
118
- else
119
- Zlib::BEST_COMPRESSION
120
- end
121
-
122
- after_filter({:only => actions}.merge(options)) do |c|
123
- c.cache_page(nil, nil, gzip_level)
124
- end
125
- end
126
-
127
- private
128
- def page_cache_file(path, extension)
129
- name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/'))
130
- unless (name.split('/').last || name).include? '.'
131
- name << (extension || self.page_cache_extension)
132
- end
133
- return name
134
- end
135
-
136
- def page_cache_path(path, extension = nil)
137
- page_cache_directory.to_s + page_cache_file(path, extension)
138
- end
139
-
140
- def instrument_page_cache(name, path)
141
- ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield }
142
- end
143
- end
144
-
145
- # Expires the page that was cached with the +options+ as a key. Example:
146
- # expire_page :controller => "lists", :action => "show"
147
- def expire_page(options = {})
148
- return unless self.class.perform_caching
149
-
150
- if options.is_a?(Hash)
151
- if options[:action].is_a?(Array)
152
- options[:action].each do |action|
153
- self.class.expire_page(url_for(options.merge(:only_path => true, :action => action)))
154
- end
155
- else
156
- self.class.expire_page(url_for(options.merge(:only_path => true)))
157
- end
158
- else
159
- self.class.expire_page(options)
160
- end
161
- end
162
-
163
- # Manually cache the +content+ in the key determined by +options+. If no content is provided, the contents of response.body is used.
164
- # If no options are provided, the url of the current request being handled is used. Example:
165
- # cache_page "I'm the cached content", :controller => "lists", :action => "show"
166
- def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
167
- return unless self.class.perform_caching && caching_allowed?
168
-
169
- path = case options
170
- when Hash
171
- url_for(options.merge(:only_path => true, :format => params[:format]))
172
- when String
173
- options
174
- else
175
- request.path
176
- end
177
-
178
- if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present?
179
- extension = ".#{type_symbol}"
180
- end
181
-
182
- self.class.cache_page(content || response.body, path, extension, gzip)
183
- end
184
-
185
- end
186
- end
187
- end
@@ -1,97 +0,0 @@
1
- module ActionController #:nodoc:
2
- module Caching
3
- # Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change.
4
- # They do this by being half-observers, half-filters and implementing callbacks for both roles. A Sweeper example:
5
- #
6
- # class ListSweeper < ActionController::Caching::Sweeper
7
- # observe List, Item
8
- #
9
- # def after_save(record)
10
- # list = record.is_a?(List) ? record : record.list
11
- # expire_page(:controller => "lists", :action => %w( show public feed ), :id => list.id)
12
- # expire_action(:controller => "lists", :action => "all")
13
- # list.shares.each { |share| expire_page(:controller => "lists", :action => "show", :id => share.url_key) }
14
- # end
15
- # end
16
- #
17
- # The sweeper is assigned in the controllers that wish to have its job performed using the <tt>cache_sweeper</tt> class method:
18
- #
19
- # class ListsController < ApplicationController
20
- # caches_action :index, :show, :public, :feed
21
- # cache_sweeper :list_sweeper, :only => [ :edit, :destroy, :share ]
22
- # end
23
- #
24
- # In the example above, four actions are cached and three actions are responsible for expiring those caches.
25
- #
26
- # You can also name an explicit class in the declaration of a sweeper, which is needed if the sweeper is in a module:
27
- #
28
- # class ListsController < ApplicationController
29
- # caches_action :index, :show, :public, :feed
30
- # cache_sweeper OpenBar::Sweeper, :only => [ :edit, :destroy, :share ]
31
- # end
32
- module Sweeping
33
- extend ActiveSupport::Concern
34
-
35
- module ClassMethods #:nodoc:
36
- def cache_sweeper(*sweepers)
37
- configuration = sweepers.extract_options!
38
-
39
- sweepers.each do |sweeper|
40
- ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
41
- sweeper_instance = (sweeper.is_a?(Symbol) ? Object.const_get(sweeper.to_s.classify) : sweeper).instance
42
-
43
- if sweeper_instance.is_a?(Sweeper)
44
- around_filter(sweeper_instance, :only => configuration[:only])
45
- else
46
- after_filter(sweeper_instance, :only => configuration[:only])
47
- end
48
- end
49
- end
50
- end
51
- end
52
-
53
- if defined?(ActiveRecord) and defined?(ActiveRecord::Observer)
54
- class Sweeper < ActiveRecord::Observer #:nodoc:
55
- attr_accessor :controller
56
-
57
- def before(controller)
58
- self.controller = controller
59
- callback(:before) if controller.perform_caching
60
- true # before method from sweeper should always return true
61
- end
62
-
63
- def after(controller)
64
- self.controller = controller
65
- callback(:after) if controller.perform_caching
66
- # Clean up, so that the controller can be collected after this request
67
- self.controller = nil
68
- end
69
-
70
- protected
71
- # gets the action cache path for the given options.
72
- def action_path_for(options)
73
- Actions::ActionCachePath.new(controller, options).path
74
- end
75
-
76
- # Retrieve instance variables set in the controller.
77
- def assigns(key)
78
- controller.instance_variable_get("@#{key}")
79
- end
80
-
81
- private
82
- def callback(timing)
83
- controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
84
- action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
85
-
86
- __send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
87
- __send__(action_callback_method_name) if respond_to?(action_callback_method_name, true)
88
- end
89
-
90
- def method_missing(method, *arguments, &block)
91
- return unless @controller
92
- @controller.__send__(method, *arguments, &block)
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,2 +0,0 @@
1
- ActionController::Integration = ActionDispatch::Integration
2
- ActionController::IntegrationTest = ActionDispatch::IntegrationTest
@@ -1 +0,0 @@
1
- ActionController::PerformanceTest = ActionDispatch::PerformanceTest
@@ -1,3 +0,0 @@
1
- ActionController::AbstractRequest = ActionController::Request = ActionDispatch::Request
2
- ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response
3
- ActionController::Routing = ActionDispatch::Routing
@@ -1,65 +0,0 @@
1
- require 'active_support/deprecation'
2
-
3
- module ActionController
4
- module Compatibility
5
- extend ActiveSupport::Concern
6
-
7
- # Temporary hax
8
- included do
9
- ::ActionController::UnknownAction = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActionController::UnknownAction', '::AbstractController::ActionNotFound')
10
- ::ActionController::DoubleRenderError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActionController::DoubleRenderError', '::AbstractController::DoubleRenderError')
11
-
12
- # ROUTES TODO: This should be handled by a middleware and route generation
13
- # should be able to handle SCRIPT_NAME
14
- self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
15
-
16
- def self.default_charset=(new_charset)
17
- ActiveSupport::Deprecation.warn "Setting default charset at controller level" \
18
- " is deprecated, please use `config.action_dispatch.default_charset` instead", caller
19
- ActionDispatch::Response.default_charset = new_charset
20
- end
21
-
22
- self.protected_instance_variables = %w(
23
- @_status @_headers @_params @_env @_response @_request
24
- @_view_runtime @_stream @_url_options @_action_has_layout
25
- )
26
-
27
- def rescue_action(env)
28
- ActiveSupport::Deprecation.warn "Calling `rescue_action` is deprecated and will be removed in Rails 4.0.", caller
29
- raise env["action_dispatch.rescue.exception"]
30
- end
31
- end
32
-
33
- # For old tests
34
- def initialize_template_class(*)
35
- ActiveSupport::Deprecation.warn "Calling `initialize_template_class` is deprecated and has no effect anymore.", caller
36
- end
37
-
38
- def assign_shortcuts(*)
39
- ActiveSupport::Deprecation.warn "Calling `assign_shortcuts` is deprecated and has no effect anymore.", caller
40
- end
41
-
42
- def _normalize_options(options)
43
- options[:text] = nil if options.delete(:nothing) == true
44
- options[:text] = " " if options.key?(:text) && options[:text].nil?
45
- super
46
- end
47
-
48
- def render_to_body(options)
49
- options[:template].sub!(/^\//, '') if options.key?(:template)
50
- super || " "
51
- end
52
-
53
- def _handle_method_missing
54
- ActiveSupport::Deprecation.warn "Using `method_missing` to handle non" \
55
- " existing actions is deprecated and will be removed in Rails 4.0, " \
56
- " please use `action_missing` instead.", caller
57
- method_missing(@_action_name.to_sym)
58
- end
59
-
60
- def method_for_action(action_name)
61
- super || ((self.class.public_method_defined?(:method_missing) ||
62
- self.class.protected_method_defined?(:method_missing)) && "_handle_method_missing")
63
- end
64
- end
65
- end
@@ -1,41 +0,0 @@
1
- require 'active_support/core_ext/class/attribute'
2
-
3
- module ActionController
4
- # Adds the ability to prevent public methods on a controller to be called as actions.
5
- module HideActions
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- class_attribute :hidden_actions
10
- self.hidden_actions = Set.new.freeze
11
- end
12
-
13
- private
14
-
15
- # Overrides AbstractController::Base#action_method? to return false if the
16
- # action name is in the list of hidden actions.
17
- def method_for_action(action_name)
18
- self.class.visible_action?(action_name) && super
19
- end
20
-
21
- module ClassMethods
22
- # Sets all of the actions passed in as hidden actions.
23
- #
24
- # ==== Parameters
25
- # * <tt>args</tt> - A list of actions
26
- def hide_action(*args)
27
- self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze
28
- end
29
-
30
- def visible_action?(action_name)
31
- not hidden_actions.include?(action_name)
32
- end
33
-
34
- # Overrides AbstractController::Base#action_methods to remove any methods
35
- # that are listed as hidden methods.
36
- def action_methods
37
- @action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) }).freeze
38
- end
39
- end
40
- end
41
- end
@@ -1,26 +0,0 @@
1
- require 'action_dispatch/http/request'
2
- require 'action_dispatch/http/response'
3
-
4
- module ActionController
5
- module RackDelegation
6
- extend ActiveSupport::Concern
7
-
8
- delegate :headers, :status=, :location=, :content_type=,
9
- :status, :location, :content_type, :to => "@_response"
10
-
11
- def dispatch(action, request, response = ActionDispatch::Response.new)
12
- @_response ||= response
13
- @_response.request ||= request
14
- super(action, request)
15
- end
16
-
17
- def response_body=(body)
18
- response.body = body if response
19
- super
20
- end
21
-
22
- def reset_session
23
- @_request.reset_session
24
- end
25
- end
26
- end