Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'mainstream/master'

Conflicts:
	actionpack/lib/action_controller.rb
	actionpack/lib/action_controller/base/base.rb
	actionpack/lib/action_view/template/path.rb
	activesupport/lib/active_support/json/encoders/hash.rb
  • Loading branch information...
commit 2fe263bb328c20539f2970057f31e567ec4ab7c8 2 parents bf5ac99 + a4bdc00
Pratik lifo authored
Showing with 4,067 additions and 5,465 deletions.
  1. +3 −2 actionmailer/Rakefile
  2. +3 −10 actionmailer/lib/action_mailer.rb
  3. +5 −1 actionmailer/lib/action_mailer/base.rb
  4. +9 −8 actionmailer/lib/action_mailer/helpers.rb
  5. +3 −3 actionmailer/lib/action_mailer/version.rb
  6. +0 −3  actionmailer/test/abstract_unit.rb
  7. +6 −3 actionpack/Rakefile
  8. +51 −73 actionpack/lib/action_controller.rb
  9. +10 −8 actionpack/lib/action_controller/abstract.rb
  10. +84 −38 actionpack/lib/action_controller/abstract/base.rb
  11. +10 −0 actionpack/lib/action_controller/abstract/benchmarker.rb
  12. +65 −15 actionpack/lib/action_controller/abstract/callbacks.rb
  13. +9 −0 actionpack/lib/action_controller/abstract/exceptions.rb
  14. +34 −18 actionpack/lib/action_controller/abstract/helpers.rb
  15. +88 −32 actionpack/lib/action_controller/abstract/layouts.rb
  16. +12 −4 actionpack/lib/action_controller/abstract/logger.rb
  17. +64 −8 actionpack/lib/action_controller/abstract/renderer.rb
  18. +143 −860 actionpack/lib/action_controller/base/base.rb
  19. +0 −107 actionpack/lib/action_controller/base/chained/benchmarking.rb
  20. +0 −670 actionpack/lib/action_controller/base/chained/filters.rb
  21. +11 −2 actionpack/lib/action_controller/{new_base → base}/compatibility.rb
  22. 0  actionpack/lib/action_controller/{new_base → base}/conditional_get.rb
  23. +58 −0 actionpack/lib/action_controller/base/exceptions.rb
  24. +5 −4 actionpack/lib/action_controller/base/filter_parameter_logging.rb
  25. +21 −53 actionpack/lib/action_controller/base/{chained → }/flash.rb
  26. +117 −160 actionpack/lib/action_controller/base/helpers.rb
  27. +35 −0 actionpack/lib/action_controller/base/hide_actions.rb
  28. +31 −22 actionpack/lib/action_controller/{new_base → base}/http.rb
  29. +3 −1 actionpack/lib/action_controller/base/http_authentication.rb
  30. +192 −0 actionpack/lib/action_controller/base/layouts.rb
  31. +2 −5 actionpack/lib/action_controller/base/mime_responds.rb
  32. +1 −1  actionpack/lib/action_controller/{new_base → base}/rack_convenience.rb
  33. +0 −89 actionpack/lib/action_controller/base/redirect.rb
  34. 0  actionpack/lib/action_controller/{new_base → base}/redirector.rb
  35. +0 −403 actionpack/lib/action_controller/base/render.rb
  36. 0  actionpack/lib/action_controller/{new_base → base}/render_options.rb
  37. 0  actionpack/lib/action_controller/{new_base → base}/renderer.rb
  38. +7 −11 actionpack/lib/action_controller/base/request_forgery_protection.rb
  39. 0  actionpack/lib/action_controller/{new_base → base}/rescuable.rb
  40. +0 −50 actionpack/lib/action_controller/base/rescue.rb
  41. +0 −43 actionpack/lib/action_controller/base/responder.rb
  42. 0  actionpack/lib/action_controller/{new_base → base}/session.rb
  43. +7 −9 actionpack/lib/action_controller/base/streaming.rb
  44. 0  actionpack/lib/action_controller/{new_base → base}/testing.rb
  45. 0  actionpack/lib/action_controller/{new_base → base}/url_for.rb
  46. +1 −4 actionpack/lib/action_controller/base/verification.rb
  47. +5 −21 actionpack/lib/action_controller/caching/actions.rb
  48. +8 −3 actionpack/lib/action_controller/{base → legacy}/layout.rb
  49. +0 −47 actionpack/lib/action_controller/new_base.rb
  50. +0 −173 actionpack/lib/action_controller/new_base/base.rb
  51. +0 −129 actionpack/lib/action_controller/new_base/helpers.rb
  52. +0 −39 actionpack/lib/action_controller/new_base/hide_actions.rb
  53. +0 −34 actionpack/lib/action_controller/new_base/layouts.rb
  54. +84 −0 actionpack/lib/action_controller/old_base.rb
  55. +1 −2  actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb
  56. +2 −2 actionpack/lib/action_controller/routing/resources.rb
  57. +2 −1  actionpack/lib/action_controller/routing/route_set.rb
  58. +4 −49 actionpack/lib/action_controller/routing/routing_ext.rb
  59. +3 −2 actionpack/lib/action_controller/testing/integration.rb
  60. 0  actionpack/lib/action_controller/testing/{performance.rb → performance_test.rb}
  61. +13 −40 actionpack/lib/action_controller/testing/process.rb
  62. +0 −74 actionpack/lib/action_controller/testing/process2.rb
  63. +13 −1 actionpack/lib/action_dispatch/http/mime_type.rb
  64. +4 −6 actionpack/lib/action_dispatch/http/request.rb
  65. +11 −45 actionpack/lib/action_dispatch/http/response.rb
  66. +1 −0  actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
  67. +2 −0  actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  68. +3 −3 actionpack/lib/action_pack/version.rb
  69. +15 −14 actionpack/lib/action_view.rb
  70. +17 −38 actionpack/lib/action_view/base.rb
  71. +1 −1  actionpack/lib/action_view/helpers.rb
  72. +13 −48 actionpack/lib/action_view/helpers/active_record_helper.rb
  73. +119 −16 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  74. +1 −1  actionpack/lib/action_view/helpers/benchmark_helper.rb
  75. +24 −7 actionpack/lib/action_view/helpers/capture_helper.rb
  76. +26 −11 actionpack/lib/action_view/helpers/form_helper.rb
  77. +9 −3 actionpack/lib/action_view/helpers/form_tag_helper.rb
  78. +3 −2 actionpack/lib/action_view/helpers/prototype_helper.rb
  79. +2 −1  actionpack/lib/action_view/helpers/tag_helper.rb
  80. +4 −3 actionpack/lib/action_view/helpers/url_helper.rb
  81. +1 −1  actionpack/lib/action_view/paths.rb
  82. +0 −33 actionpack/lib/action_view/render/partials.rb
  83. +48 −22 actionpack/lib/action_view/render/rendering.rb
  84. +2 −0  actionpack/lib/action_view/template/error.rb
  85. +2 −4 actionpack/lib/action_view/template/handlers/builder.rb
  86. +5 −2 actionpack/lib/action_view/template/handlers/erb.rb
  87. +0 −1  actionpack/lib/action_view/template/handlers/rjs.rb
  88. +0 −152 actionpack/lib/action_view/template/path.rb
  89. +150 −0 actionpack/lib/action_view/template/resolver.rb
  90. +7 −3 actionpack/lib/action_view/template/template.rb
  91. +1 −1  actionpack/lib/action_view/template/text.rb
  92. +13 −18 actionpack/test/abstract_controller/abstract_controller_test.rb
  93. +16 −16 actionpack/test/abstract_controller/callbacks_test.rb
  94. +1 −1  actionpack/test/abstract_controller/helper_test.rb
  95. +18 −27 actionpack/test/abstract_controller/layouts_test.rb
  96. +92 −20 actionpack/test/abstract_unit.rb
  97. +6 −3 actionpack/test/activerecord/polymorphic_routes_test.rb
  98. +1 −0  actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  99. +19 −5 actionpack/test/controller/action_pack_assertions_test.rb
  100. +4 −3 actionpack/test/controller/base_test.rb
  101. +2 −2 actionpack/test/controller/content_type_test.rb
  102. +2 −1  actionpack/test/controller/filter_params_test.rb
  103. +30 −36 actionpack/test/controller/filters_test.rb
  104. +4 −4 actionpack/test/controller/helper_test.rb
  105. +14 −0 actionpack/test/controller/http_digest_authentication_test.rb
  106. +3 −28 actionpack/test/controller/layout_test.rb
  107. +10 −27 actionpack/test/controller/mime_responds_test.rb
  108. +2 −0  actionpack/test/controller/record_identifier_test.rb
  109. +1 −0  actionpack/test/controller/redirect_test.rb
  110. +7 −14 actionpack/test/controller/render_test.rb
  111. +25 −4 actionpack/test/controller/routing_test.rb
  112. +7 −9 actionpack/test/controller/send_file_test.rb
  113. +2 −2 actionpack/test/dispatch/mime_type_test.rb
  114. +1 −1  actionpack/test/fixtures/layouts/builder.builder
  115. +1 −1  actionpack/test/fixtures/layouts/standard.html.erb
  116. +2 −2 actionpack/test/fixtures/layouts/talk_from_action.erb
  117. +1 −0  actionpack/test/fixtures/public/.gitignore
  118. +1 −0  actionpack/test/fixtures/public/elsewhere/cools.js
  119. +1 −0  actionpack/test/fixtures/public/elsewhere/file.css
  120. +1 −0  actionpack/test/fixtures/public/javascripts/common.javascript
  121. +1 −0  actionpack/test/fixtures/public/stylesheets/random.styles
  122. +1 −1  actionpack/test/fixtures/test/_local_inspector.html.erb
  123. +1 −0  actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb
  124. +0 −1  actionpack/test/fixtures/test/utf8.html.erb
  125. +5 −0 actionpack/test/fixtures/test/utf8_magic.html.erb
  126. +6 −0 actionpack/test/lib/controller/fake_models.rb
  127. +5 −42 actionpack/test/lib/fixture_template.rb
  128. +0 −166 actionpack/test/new_base/abstract_unit.rb
  129. +1 −1  actionpack/test/new_base/content_type_test.rb
  130. +1 −1  actionpack/test/new_base/etag_test.rb
  131. +4 −4 actionpack/test/new_base/render_action_test.rb
  132. +1 −1  actionpack/test/new_base/render_implicit_action_test.rb
  133. +3 −3 actionpack/test/new_base/render_layout_test.rb
  134. +1 −1  actionpack/test/new_base/render_partial_test.rb
  135. +46 −0 actionpack/test/new_base/render_rjs_test.rb
  136. +3 −3 actionpack/test/new_base/render_template_test.rb
  137. +1 −1  actionpack/test/new_base/render_test.rb
  138. +3 −5 actionpack/test/new_base/render_text_test.rb
  139. +1 −1  actionpack/test/new_base/render_xml_test.rb
  140. +1 −11 actionpack/test/new_base/test_helper.rb
  141. +43 −0 actionpack/test/old_base/abstract_unit.rb
  142. +8 −8 actionpack/test/template/active_record_helper_test.rb
  143. +175 −32 actionpack/test/template/asset_tag_helper_test.rb
  144. +1 −0  actionpack/test/template/atom_feed_helper_test.rb
  145. +5 −8 actionpack/test/template/body_parts_test.rb
  146. +15 −0 actionpack/test/template/capture_helper_test.rb
  147. +1 −1  actionpack/test/template/compiled_templates_test.rb
  148. +1 −1  actionpack/test/template/erb_util_test.rb
  149. +118 −7 actionpack/test/template/form_helper_test.rb
  150. +20 −3 actionpack/test/template/form_tag_helper_test.rb
  151. +29 −13 actionpack/test/template/number_helper_test.rb
  152. +6 −3 actionpack/test/template/prototype_helper_test.rb
  153. +1 −0  actionpack/test/template/record_tag_helper_test.rb
  154. +25 −31 actionpack/test/template/render_test.rb
  155. +1 −0  actionpack/test/template/test_test.rb
  156. +2 −0  actionpack/test/template/url_helper_test.rb
  157. +13 −7 activemodel/lib/active_model.rb
  158. +17 −0 activemodel/lib/active_model/attributes.rb
  159. +2 −2 activemodel/lib/active_model/deprecated_error_methods.rb
  160. +13 −10 activemodel/lib/active_model/errors.rb
  161. +25 −0 activemodel/lib/active_model/naming.rb
  162. +70 −46 activemodel/lib/active_model/observing.rb
  163. +38 −0 activemodel/lib/active_model/serializers/json.rb
  164. +7 −9 activemodel/lib/active_model/validations.rb
  165. +2 −2 activemodel/lib/active_model/validations/acceptance.rb
  166. +2 −2 activemodel/lib/active_model/validations/confirmation.rb
  167. +2 −2 activemodel/lib/active_model/validations/exclusion.rb
  168. +2 −2 activemodel/lib/active_model/validations/format.rb
  169. +2 −2 activemodel/lib/active_model/validations/inclusion.rb
  170. +2 −2 activemodel/lib/active_model/validations/length.rb
  171. +2 −2 activemodel/lib/active_model/validations/numericality.rb
  172. +4 −2 activemodel/lib/active_model/validations/presence.rb
  173. +30 −0 activemodel/test/cases/attributes_test.rb
  174. +0 −2  activemodel/test/cases/helper.rb
  175. +64 −0 activemodel/test/cases/json_serialization_test.rb
  176. +11 −4 activesupport/test/core_ext/module/model_naming_test.rb → activemodel/test/cases/naming_test.rb
  177. +20 −12 activemodel/test/cases/observing_test.rb
  178. +9 −9 activemodel/test/cases/validations/presence_validation_test.rb
  179. +1 −1  activerecord/Rakefile
  180. +1 −1  activerecord/lib/active_record.rb
  181. +2 −7 activerecord/lib/active_record/associations.rb
  182. +13 −1 activerecord/lib/active_record/associations/association_collection.rb
  183. +1 −9 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
  184. +1 −9 activerecord/lib/active_record/associations/has_many_association.rb
  185. +6 −159 activerecord/lib/active_record/associations/has_many_through_association.rb
  186. +5 −5 activerecord/lib/active_record/associations/has_one_association.rb
  187. +12 −10 activerecord/lib/active_record/associations/has_one_through_association.rb
  188. +154 −0 activerecord/lib/active_record/associations/through_association_scope.rb
  189. +41 −13 activerecord/lib/active_record/base.rb
  190. +0 −5 activerecord/lib/active_record/callbacks.rb
  191. +1 −1  activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  192. +6 −1 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  193. +13 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  194. +25 −2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  195. +11 −1 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  196. +3 −2 activerecord/lib/active_record/migration.rb
  197. +2 −1  activerecord/lib/active_record/named_scope.rb
  198. +4 −91 activerecord/lib/active_record/observer.rb
  199. +3 −2 activerecord/lib/active_record/serialization.rb
  200. +7 −25 activerecord/lib/active_record/serializers/json_serializer.rb
  201. +1 −4 activerecord/lib/active_record/validations.rb
  202. +3 −3 activerecord/lib/active_record/version.rb
  203. +15 −0 activerecord/test/cases/adapter_test.rb
  204. +7 −0 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  205. +5 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  206. +6 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
  207. +48 −33 activerecord/test/cases/base_test.rb
  208. +2 −2 activerecord/test/cases/calculations_test.rb
  209. +2 −2 activerecord/test/cases/finder_test.rb
  210. +0 −2  activerecord/test/cases/helper.rb
  211. +2 −2 activerecord/test/cases/inheritance_test.rb
  212. +4 −4 activerecord/test/cases/json_serialization_test.rb
  213. +33 −0 activerecord/test/cases/migration_test.rb
  214. +9 −3 activerecord/test/cases/reflection_test.rb
  215. +8 −0 activerecord/test/fixtures/companies.yml
  216. +4 −0 activerecord/test/models/company.rb
  217. +2 −0  activerecord/test/models/post.rb
  218. +6 −0 activerecord/test/models/project.rb
  219. +19 −0 activerecord/test/schema/oracle_specific_schema.rb
  220. +1 −0  activerecord/test/schema/schema.rb
  221. +1 −1  activeresource/Rakefile
  222. +0 −1  activeresource/examples/simple.rb
  223. +8 −11 activeresource/lib/active_resource.rb
  224. +10 −14 activeresource/lib/active_resource/base.rb
  225. +0 −2  activeresource/lib/active_resource/connection.rb
  226. +33 −40 activeresource/lib/active_resource/custom_methods.rb
  227. +2 −2 activeresource/lib/active_resource/formats/json_format.rb
  228. +0 −1  activeresource/lib/active_resource/http_mock.rb
  229. +4 −9 activeresource/lib/active_resource/validations.rb
  230. +3 −3 activeresource/lib/active_resource/version.rb
  231. +1 −4 activeresource/test/abstract_unit.rb
  232. +6 −0 activesupport/CHANGELOG
  233. +10 −0 activesupport/Rakefile
  234. +26 −4 activesupport/lib/active_support/cache.rb
  235. +13 −1 activesupport/lib/active_support/cache/file_store.rb
  236. +0 −4 activesupport/lib/active_support/cache/mem_cache_store.rb
  237. +1 −1  activesupport/lib/active_support/cache/memory_store.rb
  238. +1 −0  activesupport/lib/active_support/core_ext/boolean.rb
  239. +11 −0 activesupport/lib/active_support/core_ext/boolean/conversions.rb
  240. +4 −2 activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
  241. +4 −2 activesupport/lib/active_support/core_ext/kernel/debugger.rb
  242. +0 −1  activesupport/lib/active_support/core_ext/module.rb
  243. +12 −5 activesupport/lib/active_support/core_ext/module/delegation.rb
  244. +0 −23 activesupport/lib/active_support/core_ext/module/model_naming.rb
  245. +1 −0  activesupport/lib/active_support/core_ext/nil.rb
  246. +5 −0 activesupport/lib/active_support/core_ext/nil/conversions.rb
  247. +15 −8 activesupport/lib/active_support/core_ext/numeric/bytes.rb
  248. +3 −1 activesupport/lib/active_support/core_ext/proc.rb
  249. +25 −0 activesupport/lib/active_support/core_ext/regexp.rb
  250. +6 −2 activesupport/lib/active_support/core_ext/string/conversions.rb
  251. +10 −5 activesupport/lib/active_support/dependencies.rb
  252. +4 −2 activesupport/lib/active_support/duration.rb
  253. +1 −1  activesupport/lib/active_support/inflector.rb
  254. +1 −86 activesupport/lib/active_support/json.rb
  255. +34 −0 activesupport/lib/active_support/json/decoding.rb
  256. +0 −22 activesupport/lib/active_support/json/encoders/date.rb
  257. +0 −22 activesupport/lib/active_support/json/encoders/date_time.rb
  258. +0 −13 activesupport/lib/active_support/json/encoders/enumerable.rb
  259. +0 −6 activesupport/lib/active_support/json/encoders/false_class.rb
  260. +0 −51 activesupport/lib/active_support/json/encoders/hash.rb
  261. +0 −6 activesupport/lib/active_support/json/encoders/nil_class.rb
  262. +0 −6 activesupport/lib/active_support/json/encoders/numeric.rb
  263. +0 −13 activesupport/lib/active_support/json/encoders/object.rb
  264. +0 −6 activesupport/lib/active_support/json/encoders/regexp.rb
  265. +0 −6 activesupport/lib/active_support/json/encoders/string.rb
  266. +0 −6 activesupport/lib/active_support/json/encoders/symbol.rb
  267. +0 −24 activesupport/lib/active_support/json/encoders/time.rb
  268. +0 −6 activesupport/lib/active_support/json/encoders/true_class.rb
  269. +215 −24 activesupport/lib/active_support/json/encoding.rb
  270. +96 −126 activesupport/lib/active_support/new_callbacks.rb
  271. +18 −4 activesupport/lib/active_support/ordered_hash.rb
  272. +9 −8 activesupport/lib/active_support/test_case.rb
  273. +0 −6 activesupport/lib/active_support/testing/declarative.rb
  274. +103 −0 activesupport/lib/active_support/testing/isolation.rb
  275. +0 −2  activesupport/lib/active_support/testing/setup_and_teardown.rb
  276. +21 −20 activesupport/lib/active_support/time_with_zone.rb
  277. +1 −1  activesupport/lib/active_support/values/time_zone.rb
  278. +2 −2 activesupport/lib/active_support/vendor.rb
  279. +0 −1  activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb
  280. +0 −1  activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb
  281. +0 −1  activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb
  282. 0  activesupport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo.rb
  283. 0  activesupport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/data_timezone.rb
  284. 0  activesupport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/data_timezone_info.rb
  285. 0  ...support/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Algiers.rb
  286. 0  ...vesupport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Cairo.rb
  287. +2 −0  ...port/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Casablanca.rb
  288. 0  ...esupport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Harare.rb
  289. 0  ...rt/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Johannesburg.rb
  290. 0  ...upport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Monrovia.rb
  291. 0  ...support/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/Africa/Nairobi.rb
  292. 0  ...ve_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Argentina/Buenos_Aires.rb
  293. 0  ...active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Argentina/San_Juan.rb
  294. 0  ...support/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Bogota.rb
  295. 0  ...upport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Caracas.rb
  296. 0  ...upport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Chicago.rb
  297. 0  ...port/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Chihuahua.rb
  298. 0  ...support/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Denver.rb
  299. 0  ...upport/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Godthab.rb
  300. 0  ...port/lib/active_support/vendor/{tzinfo-0.3.12 → tzinfo-0.3.13}/tzinfo/definitions/America/Guatemala.rb
Sorry, we could not display the entire diff because too many files (603) changed.
5 actionmailer/Rakefile
View
@@ -4,7 +4,6 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/packagetask'
require 'rake/gempackagetask'
-require 'rake/contrib/sshpublisher'
require File.join(File.dirname(__FILE__), 'lib', 'action_mailer', 'version')
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
@@ -61,7 +60,7 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = "actionmailer"
s.homepage = "http://www.rubyonrails.org"
- s.add_dependency('actionpack', '= 2.3.2' + PKG_BUILD)
+ s.add_dependency('actionpack', '= 3.0.pre' + PKG_BUILD)
s.has_rdoc = true
s.requirements << 'none'
@@ -82,12 +81,14 @@ end
desc "Publish the API documentation"
task :pgem => [:package] do
+ require 'rake/contrib/sshpublisher'
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
end
desc "Publish the API documentation"
task :pdoc => [:rdoc] do
+ require 'rake/contrib/sshpublisher'
Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/am", "doc").upload
end
13 actionmailer/lib/action_mailer.rb
View
@@ -21,16 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-begin
- require 'action_controller'
-rescue LoadError
- actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
- if File.directory?(actionpack_path)
- $:.unshift actionpack_path
- require 'action_controller'
- end
-end
-
+actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
+$:.unshift(actionpack_path) if File.directory?(actionpack_path)
+require 'action_controller'
require 'action_view'
module ActionMailer
6 actionmailer/lib/action_mailer/base.rb
View
@@ -1,3 +1,7 @@
+require "active_support/core_ext/class"
+# Use the old layouts until actionmailer gets refactored
+require "action_controller/legacy/layout"
+
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
#
@@ -697,7 +701,7 @@ def create_mail
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
- sender = (mail['return-path'] && mail['return-path'].spec) || mail.from
+ sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
17 actionmailer/lib/action_mailer/helpers.rb
View
@@ -48,13 +48,14 @@ def helper(*args, &block)
file_name = arg.to_s.underscore + '_helper'
class_name = file_name.camelize
- begin
- require_dependency(file_name)
- rescue LoadError => load_error
- requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
- msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}"
- raise LoadError.new(msg).copy_blame!(load_error)
- end
+ require_dependency(file_name, "Missing helper file helpers/%s.rb")
+ # begin
+ # require_dependency(file_name)
+ # rescue LoadError => load_error
+ # requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
+ # msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}"
+ # raise LoadError.new(msg).copy_blame!(load_error)
+ # end
add_template_helper(class_name.constantize)
else
@@ -97,7 +98,7 @@ def inherited_with_helper(child)
child.master_helper_module.__send__(:include, master_helper_module)
child.helper child.name.to_s.underscore
rescue MissingSourceFile => e
- raise unless e.is_missing?("helpers/#{child.name.to_s.underscore}_helper")
+ raise unless e.is_missing?("#{child.name.to_s.underscore}_helper")
end
end
end
6 actionmailer/lib/action_mailer/version.rb
View
@@ -1,8 +1,8 @@
module ActionMailer
module VERSION #:nodoc:
- MAJOR = 2
- MINOR = 3
- TINY = 2
+ MAJOR = 3
+ MINOR = 0
+ TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end
3  actionmailer/test/abstract_unit.rb
View
@@ -1,9 +1,6 @@
require 'rubygems'
require 'test/unit'
-gem 'mocha', '>= 0.9.5'
-require 'mocha'
-
$:.unshift "#{File.dirname(__FILE__)}/../lib"
$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
$:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"
9 actionpack/Rakefile
View
@@ -22,9 +22,11 @@ task :default => [ :test ]
# Run the unit tests
desc "Run all unit tests"
-task :test => [:test_action_pack, :test_active_record_integration, :test_new_base, :test_new_base_on_old_tests]
+task :test => [:test_action_pack, :test_active_record_integration, :test_new_base]
-test_lib_dirs = [ENV["NEW"] ? "test/new_base" : "test", "test/lib"]
+test_lib_dirs = ENV["NEW"] ? ["test/new_base"] : []
+test_lib_dirs.push "test", "test/lib"
+# test_lib_dirs = [ENV["NEW"] ? "test/new_base" : "test", "test/lib"]
Rake::TestTask.new(:test_action_pack) do |t|
t.libs.concat test_lib_dirs
@@ -35,6 +37,7 @@ Rake::TestTask.new(:test_action_pack) do |t|
t.verbose = true
#t.warning = true
end
+
task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir.glob("test/{controller,dispatch,template}/**/*_test.rb").all? do |file|
@@ -112,7 +115,7 @@ spec = Gem::Specification.new do |s|
s.has_rdoc = true
s.requirements << 'none'
- s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
+ s.add_dependency('activesupport', '= 3.0.pre' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'action_controller'
124 actionpack/lib/action_controller.rb
View
@@ -1,84 +1,62 @@
-#--
-# Copyright (c) 2004-2009 David Heinemeier Hansson
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
-$:.unshift activesupport_path if File.directory?(activesupport_path)
-require 'active_support'
-
-require File.join(File.dirname(__FILE__), "action_pack")
-
module ActionController
- # TODO: Review explicit to see if they will automatically be handled by
- # the initializer if they are really needed.
- def self.load_all!
- [Base, Request, Response, UrlRewriter, UrlWriter]
- [ActionDispatch::Http::Headers]
- end
+ autoload :Base, "action_controller/base/base"
+ autoload :ConditionalGet, "action_controller/base/conditional_get"
+ autoload :HideActions, "action_controller/base/hide_actions"
+ autoload :Http, "action_controller/base/http"
+ autoload :Layouts, "action_controller/base/layouts"
+ autoload :RackConvenience, "action_controller/base/rack_convenience"
+ autoload :Rails2Compatibility, "action_controller/base/compatibility"
+ autoload :Redirector, "action_controller/base/redirector"
+ autoload :Renderer, "action_controller/base/renderer"
+ autoload :RenderOptions, "action_controller/base/render_options"
+ autoload :Renderers, "action_controller/base/render_options"
+ autoload :Rescue, "action_controller/base/rescuable"
+ autoload :Testing, "action_controller/base/testing"
+ autoload :UrlFor, "action_controller/base/url_for"
+ autoload :Session, "action_controller/base/session"
+ autoload :Helpers, "action_controller/base/helpers"
- autoload :Base, 'action_controller/base/base'
- autoload :Benchmarking, 'action_controller/base/chained/benchmarking'
- autoload :Caching, 'action_controller/caching'
- autoload :Cookies, 'action_controller/base/cookies'
- autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
- autoload :Filters, 'action_controller/base/chained/filters'
- autoload :Flash, 'action_controller/base/chained/flash'
- autoload :Helpers, 'action_controller/base/helpers'
- autoload :HttpAuthentication, 'action_controller/base/http_authentication'
- autoload :Integration, 'action_controller/testing/integration'
- autoload :IntegrationTest, 'action_controller/testing/integration'
- autoload :Layout, 'action_controller/base/layout'
- autoload :MimeResponds, 'action_controller/base/mime_responds'
+ # Ported modules
+ # require 'action_controller/routing'
+ autoload :Caching, 'action_controller/caching'
+ autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
+ autoload :Integration, 'action_controller/testing/integration'
+ autoload :MimeResponds, 'action_controller/base/mime_responds'
autoload :PolymorphicRoutes, 'action_controller/routing/generation/polymorphic_routes'
- autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Redirector, 'action_controller/base/redirect'
- autoload :Renderer, 'action_controller/base/render'
- autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
- autoload :Rescue, 'action_controller/base/rescue'
- autoload :Resources, 'action_controller/routing/resources'
- autoload :Responder, 'action_controller/base/responder'
- autoload :Routing, 'action_controller/routing'
+ autoload :RecordIdentifier, 'action_controller/record_identifier'
+ autoload :Resources, 'action_controller/routing/resources'
autoload :SessionManagement, 'action_controller/base/session_management'
- autoload :Streaming, 'action_controller/base/streaming'
- autoload :TestCase, 'action_controller/testing/test_case'
- autoload :TestProcess, 'action_controller/testing/process'
- autoload :Translation, 'action_controller/translation'
- autoload :UrlEncodedPairParser, 'action_controller/dispatch/url_encoded_pair_parser'
- autoload :UrlRewriter, 'action_controller/routing/generation/url_rewriter'
- autoload :UrlWriter, 'action_controller/routing/generation/url_rewriter'
- autoload :Verification, 'action_controller/base/verification'
- autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
+ autoload :TestCase, 'action_controller/testing/test_case'
+ autoload :TestProcess, 'action_controller/testing/process'
+ autoload :UrlRewriter, 'action_controller/routing/generation/url_rewriter'
+ autoload :UrlWriter, 'action_controller/routing/generation/url_rewriter'
+
+ autoload :Verification, 'action_controller/base/verification'
+ autoload :Flash, 'action_controller/base/flash'
+ autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
+ autoload :Streaming, 'action_controller/base/streaming'
+ autoload :HttpAuthentication, 'action_controller/base/http_authentication'
+ autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
+ autoload :Translation, 'action_controller/translation'
+ autoload :Cookies, 'action_controller/base/cookies'
+
+ autoload :ActionControllerError, 'action_controller/base/exceptions'
+ autoload :SessionRestoreError, 'action_controller/base/exceptions'
+ autoload :RenderError, 'action_controller/base/exceptions'
+ autoload :RoutingError, 'action_controller/base/exceptions'
+ autoload :MethodNotAllowed, 'action_controller/base/exceptions'
+ autoload :NotImplemented, 'action_controller/base/exceptions'
+ autoload :UnknownController, 'action_controller/base/exceptions'
+ autoload :MissingFile, 'action_controller/base/exceptions'
+ autoload :RenderError, 'action_controller/base/exceptions'
+ autoload :SessionOverflowError, 'action_controller/base/exceptions'
+ autoload :UnknownHttpMethod, 'action_controller/base/exceptions'
- module Assertions
- autoload :DomAssertions, 'action_controller/testing/assertions/dom'
- autoload :ModelAssertions, 'action_controller/testing/assertions/model'
- autoload :ResponseAssertions, 'action_controller/testing/assertions/response'
- autoload :RoutingAssertions, 'action_controller/testing/assertions/routing'
- autoload :SelectorAssertions, 'action_controller/testing/assertions/selector'
- autoload :TagAssertions, 'action_controller/testing/assertions/tag'
- end
+ require 'action_controller/routing'
end
autoload :HTML, 'action_controller/vendor/html-scanner'
+autoload :AbstractController, 'action_controller/abstract'
require 'action_dispatch'
require 'action_view'
18 actionpack/lib/action_controller/abstract.rb
View
@@ -2,13 +2,15 @@
require "active_support/core_ext/module/delegation"
module AbstractController
- autoload :Base, "action_controller/abstract/base"
- autoload :Benchmarker, "action_controller/abstract/benchmarker"
- autoload :Callbacks, "action_controller/abstract/callbacks"
- autoload :Helpers, "action_controller/abstract/helpers"
- autoload :Layouts, "action_controller/abstract/layouts"
- autoload :Logger, "action_controller/abstract/logger"
- autoload :Renderer, "action_controller/abstract/renderer"
+ autoload :Base, "action_controller/abstract/base"
+ autoload :Benchmarker, "action_controller/abstract/benchmarker"
+ autoload :Callbacks, "action_controller/abstract/callbacks"
+ autoload :Helpers, "action_controller/abstract/helpers"
+ autoload :Layouts, "action_controller/abstract/layouts"
+ autoload :Logger, "action_controller/abstract/logger"
+ autoload :Renderer, "action_controller/abstract/renderer"
# === Exceptions
- autoload :ActionNotFound, "action_controller/abstract/exceptions"
+ autoload :ActionNotFound, "action_controller/abstract/exceptions"
+ autoload :DoubleRenderError, "action_controller/abstract/exceptions"
+ autoload :Error, "action_controller/abstract/exceptions"
end
122 actionpack/lib/action_controller/abstract/base.rb
View
@@ -1,53 +1,65 @@
require 'active_support/core_ext/module/attr_internal'
module AbstractController
- class Error < StandardError; end
-
- class DoubleRenderError < Error
- DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
-
- def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
- end
- end
class Base
attr_internal :response_body
- attr_internal :response_obj
attr_internal :action_name
class << self
attr_reader :abstract
+ alias_method :abstract?, :abstract
+ # Define a controller as abstract. See internal_methods for more
+ # details.
def abstract!
@abstract = true
end
- alias_method :abstract?, :abstract
-
def inherited(klass)
- ::AbstractController::Base.subclasses << klass.to_s
+ ::AbstractController::Base.descendants << klass.to_s
super
end
- def subclasses
- @subclasses ||= []
+ # A list of all descendents of AbstractController::Base. This is
+ # useful for initializers which need to add behavior to all controllers.
+ def descendants
+ @descendants ||= []
end
+ # A list of all internal methods for a controller. This finds the first
+ # abstract superclass of a controller, and gets a list of all public
+ # instance methods on that abstract class. Public instance methods of
+ # a controller would normally be considered action methods, so we
+ # are removing those methods on classes declared as abstract
+ # (ActionController::Http and ActionController::Base are defined
+ # as abstract)
def internal_methods
controller = self
controller = controller.superclass until controller.abstract?
controller.public_instance_methods(true)
end
- def process(action)
- new.process(action.to_s)
- end
-
+ # The list of hidden actions to an empty Array. Defaults to an
+ # empty Array. This can be modified by other modules or subclasses
+ # to specify particular actions as hidden.
+ #
+ # ==== Returns
+ # Array[String]:: An array of method names that should not be
+ # considered actions.
def hidden_actions
[]
end
+ # A list of method names that should be considered actions. This
+ # includes all public instance methods on a controller, less
+ # any internal methods (see #internal_methods), adding back in
+ # any methods that are internal, but still exist on the class
+ # itself. Finally, #hidden_actions are removed.
+ #
+ # ==== Returns
+ # Array[String]:: A list of all methods that should be considered
+ # actions.
def action_methods
@action_methods ||=
# All public instance methods of this class, including ancestors
@@ -63,10 +75,14 @@ def action_methods
abstract!
- def initialize
- self.response_obj = {}
- end
-
+ # Calls the action going through the entire action dispatch stack.
+ #
+ # The actual method that is called is determined by calling
+ # #method_for_action. If no method can handle the action, then an
+ # ActionNotFound error is raised.
+ #
+ # ==== Returns
+ # self
def process(action)
@_action_name = action_name = action.to_s
@@ -79,33 +95,63 @@ def process(action)
end
private
- def action_methods
- self.class.action_methods
- end
-
- def action_method?(action)
- action_methods.include?(action)
+ # Returns true if the name can be considered an action. This can
+ # be overridden in subclasses to modify the semantics of what
+ # can be considered an action.
+ #
+ # ==== Parameters
+ # name<String>:: The name of an action to be tested
+ #
+ # ==== Returns
+ # TrueClass, FalseClass
+ def action_method?(name)
+ self.class.action_methods.include?(name)
end
- # It is possible for respond_to?(action_name) to be false and
- # respond_to?(:action_missing) to be false if respond_to_action?
- # is overridden in a subclass. For instance, ActionController::Base
- # overrides it to include the case where a template matching the
- # action_name is found.
+ # Call the action. Override this in a subclass to modify the
+ # behavior around processing an action. This, and not #process,
+ # is the intended way to override action dispatching.
def process_action(method_name)
send_action(method_name)
end
+ # Actually call the method associated with the action. Override
+ # this method if you wish to change how action methods are called,
+ # not to add additional behavior around it. For example, you would
+ # override #send_action if you want to inject arguments into the
+ # method.
alias send_action send
+ # If the action name was not found, but a method called "action_missing"
+ # was found, #method_for_action will return "_handle_action_missing".
+ # This method calls #action_missing with the current action name.
def _handle_action_missing
action_missing(@_action_name)
end
- # Override this to change the conditions that will raise an
- # ActionNotFound error. If you accept a difference case,
- # you must handle it by also overriding process_action and
- # handling the case.
+ # Takes an action name and returns the name of the method that will
+ # handle the action. In normal cases, this method returns the same
+ # name as it receives. By default, if #method_for_action receives
+ # a name that is not an action, it will look for an #action_missing
+ # method and return "_handle_action_missing" if one is found.
+ #
+ # Subclasses may override this method to add additional conditions
+ # that should be considered an action. For instance, an HTTP controller
+ # with a template matching the action name is considered to exist.
+ #
+ # If you override this method to handle additional cases, you may
+ # also provide a method (like _handle_method_missing) to handle
+ # the case.
+ #
+ # If none of these conditions are true, and method_for_action
+ # returns nil, an ActionNotFound exception will be raised.
+ #
+ # ==== Parameters
+ # action_name<String>:: An action name to find a method name for
+ #
+ # ==== Returns
+ # String:: The name of the method that handles the action
+ # nil:: No method name could be found. Raise ActionNotFound.
def method_for_action(action_name)
if action_method?(action_name) then action_name
elsif respond_to?(:action_missing, true) then "_handle_action_missing"
10 actionpack/lib/action_controller/abstract/benchmarker.rb
View
@@ -5,6 +5,16 @@ module Benchmarker
include Logger
module ClassMethods
+ # Execute the passed in block, timing the duration of the block in ms.
+ #
+ # ==== Parameters
+ # title<#to_s>:: The title of block to benchmark
+ # log_level<Integer>:: A valid log level. Defaults to Logger::DEBUG
+ # use_silence<TrueClass, FalseClass>:: Whether or not to silence the
+ # logger for the duration of the block.
+ #
+ # ==== Returns
+ # Object:: The result of the block
def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true)
if logger && logger.level >= log_level
result = nil
80 actionpack/lib/action_controller/abstract/callbacks.rb
View
@@ -2,12 +2,17 @@ module AbstractController
module Callbacks
extend ActiveSupport::Concern
+ # Uses ActiveSupport::NewCallbacks as the base functionality. For
+ # more details on the whole callback system, read the documentation
+ # for ActiveSupport::NewCallbacks.
include ActiveSupport::NewCallbacks
included do
define_callbacks :process_action, "response_body"
end
+ # Override AbstractController::Base's process_action to run the
+ # process_action callbacks around the normal behavior.
def process_action(method_name)
_run_process_action_callbacks(method_name) do
super
@@ -15,6 +20,17 @@ def process_action(method_name)
end
module ClassMethods
+ # If :only or :accept are used, convert the options into the
+ # primitive form (:per_key) used by ActiveSupport::Callbacks.
+ # The basic idea is that :only => :index gets converted to
+ # :if => proc {|c| c.action_name == "index" }, but that the
+ # proc is only evaluated once per action for the lifetime of
+ # a Rails process.
+ #
+ # ==== Options
+ # :only<#to_s>:: The callback should be run only for this action
+ # :except<#to_s>:: The callback should be run for all actions
+ # except this action
def _normalize_callback_options(options)
if only = options[:only]
only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
@@ -26,35 +42,69 @@ def _normalize_callback_options(options)
end
end
+ # Skip before, after, and around filters matching any of the names
+ #
+ # ==== Parameters
+ # *names<Object>:: A list of valid names that could be used for
+ # callbacks. Note that skipping uses Ruby equality, so it's
+ # impossible to skip a callback defined using an anonymous proc
+ # using #skip_filter
+ def skip_filter(*names, &blk)
+ skip_before_filter(*names)
+ skip_after_filter(*names)
+ skip_around_filter(*names)
+ end
+
+ # Take callback names and an optional callback proc, normalize them,
+ # then call the block with each callback. This allows us to abstract
+ # the normalization across several methods that use it.
+ #
+ # ==== Parameters
+ # callbacks<Array[*Object, Hash]>:: A list of callbacks, with an optional
+ # options hash as the last parameter.
+ # block<Proc>:: A proc that should be added to the callbacks.
+ #
+ # ==== Block Parameters
+ # name<Symbol>:: The callback to be added
+ # options<Hash>:: A list of options to be used when adding the callback
+ def _insert_callbacks(callbacks, block)
+ options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
+ _normalize_callback_options(options)
+ callbacks.push(block) if block
+ callbacks.each do |callback|
+ yield callback, options
+ end
+ end
+
+ # set up before_filter, prepend_before_filter, skip_before_filter, etc.
+ # for each of before, after, and around.
[:before, :after, :around].each do |filter|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ # Append a before, after or around filter. See _insert_callbacks
+ # for details on the allowed parameters.
def #{filter}_filter(*names, &blk)
- options = names.last.is_a?(Hash) ? names.pop : {}
- _normalize_callback_options(options)
- names.push(blk) if block_given?
- names.each do |name|
- process_action_callback(:#{filter}, name, options)
+ _insert_callbacks(names, blk) do |name, options|
+ set_callback(:process_action, :#{filter}, name, options)
end
end
+ # Prepend a before, after or around filter. See _insert_callbacks
+ # for details on the allowed parameters.
def prepend_#{filter}_filter(*names, &blk)
- options = names.last.is_a?(Hash) ? names.pop : {}
- _normalize_callback_options(options)
- names.push(blk) if block_given?
- names.each do |name|
- process_action_callback(:#{filter}, name, options.merge(:prepend => true))
+ _insert_callbacks(names, blk) do |name, options|
+ set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true))
end
end
+ # Skip a before, after or around filter. See _insert_callbacks
+ # for details on the allowed parameters.
def skip_#{filter}_filter(*names, &blk)
- options = names.last.is_a?(Hash) ? names.pop : {}
- _normalize_callback_options(options)
- names.push(blk) if block_given?
- names.each do |name|
- skip_process_action_callback(:#{filter}, name, options)
+ _insert_callbacks(names, blk) do |name, options|
+ skip_callback(:process_action, :#{filter}, name, options)
end
end
+ # *_filter is the same as append_*_filter
alias_method :append_#{filter}_filter, :#{filter}_filter
RUBY_EVAL
end
9 actionpack/lib/action_controller/abstract/exceptions.rb
View
@@ -1,3 +1,12 @@
module AbstractController
+ class Error < StandardError; end
class ActionNotFound < StandardError; end
+
+ class DoubleRenderError < Error
+ DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
+
+ def initialize(message = nil)
+ super(message || DEFAULT_MESSAGE)
+ end
+ end
end
52 actionpack/lib/action_controller/abstract/helpers.rb
View
@@ -5,33 +5,26 @@ module Helpers
include Renderer
included do
- extlib_inheritable_accessor :master_helper_module
- self.master_helper_module = Module.new
+ extlib_inheritable_accessor(:_helpers) { Module.new }
end
+ # Override AbstractController::Renderer's _action_view to include the
+ # helper module for this class into its helpers module.
def _action_view
- @_action_view ||= begin
- av = super
- av.helpers.send(:include, master_helper_module)
- av
- end
+ @_action_view ||= super.tap { |av| av.helpers.include(_helpers) }
end
module ClassMethods
+ # When a class is inherited, wrap its helper module in a new module.
+ # This ensures that the parent class's module can be changed
+ # independently of the child class's.
def inherited(klass)
- klass.master_helper_module = Module.new
- klass.master_helper_module.__send__ :include, master_helper_module
+ helpers = _helpers
+ klass._helpers = Module.new { include helpers }
super
end
- # Makes all the (instance) methods in the helper module available to templates rendered through this controller.
- # See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules
- # available to the templates.
- def add_template_helper(mod)
- master_helper_module.module_eval { include mod }
- end
-
# Declare a controller method as a helper. For example, the following
# makes the +current_user+ controller method available to the view:
# class ApplicationController < ActionController::Base
@@ -48,9 +41,13 @@ def add_template_helper(mod)
#
# In a view:
# <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
+ #
+ # ==== Parameters
+ # meths<Array[#to_s]>:: The name of a method on the controller
+ # to be made available on the view.
def helper_method(*meths)
meths.flatten.each do |meth|
- master_helper_module.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
+ _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
def #{meth}(*args, &blk)
controller.send(%(#{meth}), *args, &blk)
end
@@ -58,6 +55,14 @@ def #{meth}(*args, &blk)
end
end
+ # Make a number of helper modules part of this class' default
+ # helpers.
+ #
+ # ==== Parameters
+ # *args<Array[Module]>:: Modules to be included
+ # block<Block>:: Evalulate the block in the context
+ # of the helper module. Any methods defined in the block
+ # will be helpers.
def helper(*args, &block)
args.flatten.each do |arg|
case arg
@@ -65,7 +70,18 @@ def helper(*args, &block)
add_template_helper(arg)
end
end
- master_helper_module.module_eval(&block) if block_given?
+ _helpers.module_eval(&block) if block_given?
+ end
+
+ private
+ # Makes all the (instance) methods in the helper module available to templates
+ # rendered through this controller.
+ #
+ # ==== Parameters
+ # mod<Module>:: The module to include into the current helper module
+ # for the class
+ def add_template_helper(mod)
+ _helpers.module_eval { include mod }
end
end
end
120 actionpack/lib/action_controller/abstract/layouts.rb
View
@@ -5,16 +5,31 @@ module Layouts
include Renderer
included do
- extlib_inheritable_accessor :_layout_conditions
- self._layout_conditions = {}
+ extlib_inheritable_accessor(:_layout_conditions) { Hash.new }
end
module ClassMethods
- def layout(layout, conditions = {})
- unless [String, Symbol, FalseClass, NilClass].include?(layout.class)
- raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
- end
+ def inherited(klass)
+ super
+ klass._write_layout_method
+ end
+ # Specify the layout to use for this class.
+ #
+ # If the specified layout is a:
+ # String:: the String is the template name
+ # Symbol:: call the method specified by the symbol, which will return
+ # the template name
+ # false:: There is no layout
+ # true:: raise an ArgumentError
+ #
+ # ==== Parameters
+ # layout<String, Symbol, false)>:: The layout to use.
+ #
+ # ==== Options (conditions)
+ # :only<#to_s, Array[#to_s]>:: A list of actions to apply this layout to.
+ # :except<#to_s, Array[#to_s]>:: Apply this layout to all actions but this one
+ def layout(layout, conditions = {})
conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
self._layout_conditions = conditions
@@ -22,6 +37,11 @@ def layout(layout, conditions = {})
_write_layout_method
end
+ # If no layout is supplied, look for a template named the return
+ # value of this method.
+ #
+ # ==== Returns
+ # String:: A template name
def _implied_layout_name
name.underscore
end
@@ -29,23 +49,31 @@ def _implied_layout_name
# Takes the specified layout and creates a _layout method to be called
# by _default_layout
#
- # If the specified layout is a:
- # String:: return the string
- # Symbol:: call the method specified by the symbol
- # false:: return nil
- # none:: If a layout is found in the view paths with the controller's
- # name, return that string. Otherwise, use the superclass'
- # layout (which might also be implied)
+ # If there is no explicit layout specified:
+ # If a layout is found in the view paths with the controller's
+ # name, return that string. Otherwise, use the superclass'
+ # layout (which might also be implied)
def _write_layout_method
case @_layout
when String
self.class_eval %{def _layout(details) #{@_layout.inspect} end}
when Symbol
- self.class_eval %{def _layout(details) #{@_layout} end}
+ self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
+ def _layout(details)
+ #{@_layout}.tap do |layout|
+ unless layout.is_a?(String) || !layout
+ raise ArgumentError, "Your layout method :#{@_layout} returned \#{layout}. It " \
+ "should have returned a String, false, or nil"
+ end
+ end
+ end
+ ruby_eval
when false
self.class_eval %{def _layout(details) end}
- else
- self.class_eval %{
+ when true
+ raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
+ when nil
+ self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
def _layout(details)
if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts")
"#{_implied_layout_name}"
@@ -53,33 +81,55 @@ def _layout(details)
super
end
end
- }
+ ruby_eval
end
+ self.class_eval { private :_layout }
end
end
private
- # This will be overwritten
- def _layout(details)
- end
+ # This will be overwritten by _write_layout_method
+ def _layout(details) end
- # :api: plugin
- # ====
- # Override this to mutate the inbound layout name
+ # Determine the layout for a given name and details.
+ #
+ # ==== Parameters
+ # name<String>:: The name of the template
+ # details<Hash{Symbol => Object}>:: A list of details to restrict
+ # the lookup to. By default, layout lookup is limited to the
+ # formats specified for the current request.
def _layout_for_name(name, details = {:formats => formats})
- unless [String, FalseClass, NilClass].include?(name.class)
- raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
- end
-
- name && view_paths.find_by_parts(name, details, _layout_prefix(name))
+ name && _find_by_parts(name, details)
end
- # TODO: Decide if this is the best hook point for the feature
- def _layout_prefix(name)
- "layouts"
+ # Take in the name and details and find a Template.
+ #
+ # ==== Parameters
+ # name<String>:: The name of the template to retrieve
+ # details<Hash>:: A list of details to restrict the search by. This
+ # might include details like the format or locale of the template.
+ #
+ # ==== Returns
+ # Template:: A template object matching the name and details
+ def _find_by_parts(name, details)
+ # TODO: Make prefix actually part of details in ViewPath#find_by_parts
+ prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts"
+ view_paths.find_by_parts(name, details, prefix)
end
- def _default_layout(require_layout = false, details = {:formats => formats})
+ # Returns the default layout for this controller and a given set of details.
+ # Optionally raises an exception if the layout could not be found.
+ #
+ # ==== Parameters
+ # details<Hash>:: A list of details to restrict the search by. This
+ # might include details like the format or locale of the template.
+ # require_layout<Boolean>:: If this is true, raise an ArgumentError
+ # with details about the fact that the exception could not be
+ # found (defaults to false)
+ #
+ # ==== Returns
+ # Template:: The template object for the default layout (or nil)
+ def _default_layout(details, require_layout = false)
if require_layout && _action_has_layout? && !_layout(details)
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
@@ -93,6 +143,12 @@ def _default_layout(require_layout = false, details = {:formats => formats})
end
end
+ # Determines whether the current action has a layout by checking the
+ # action name against the :only and :except conditions set on the
+ # layout.
+ #
+ # ==== Returns
+ # Boolean:: True if the action has a layout, false otherwise.
def _action_has_layout?
conditions = _layout_conditions
if only = conditions[:only]
16 actionpack/lib/action_controller/abstract/logger.rb
View
@@ -5,6 +5,13 @@ module AbstractController
module Logger
extend ActiveSupport::Concern
+ # A class that allows you to defer expensive processing
+ # until the logger actually tries to log. Otherwise, you are
+ # forced to do the processing in advance, and send the
+ # entire processed String to the logger, which might
+ # just discard the String if the log level is too low.
+ #
+ # TODO: Require that Rails loggers accept a block.
class DelayedLog
def initialize(&blk)
@blk = blk
@@ -20,8 +27,10 @@ def to_s
cattr_accessor :logger
end
- def process(action)
- ret = super
+ # Override process_action in the AbstractController::Base
+ # to log details about the method.
+ def process_action(action)
+ super
if logger
log = DelayedLog.new do
@@ -32,10 +41,9 @@ def process(action)
logger.info(log)
end
-
- ret
end
+ private
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
72 actionpack/lib/action_controller/abstract/renderer.rb
View
@@ -14,10 +14,32 @@ module Renderer
self._view_paths ||= ActionView::PathSet.new
end
+ # An instance of a view class. The default view class is ActionView::Base
+ #
+ # The view class must have the following methods:
+ # initialize[paths, assigns_for_first_render, controller]
+ # paths<Array[ViewPath]>:: A list of resolvers to look for templates in
+ # controller<AbstractController::Base> A controller
+ # _render_partial_from_controller[options]
+ # options<Hash>:: see _render_partial in ActionView::Base
+ # _render_template_from_controller[template, layout, options, partial]
+ # template<ActionView::Template>:: The template to render
+ # layout<ActionView::Template>:: The layout to render around the template
+ # options<Hash>:: See _render_template_with_layout in ActionView::Base
+ # partial<Boolean>:: Whether or not the template to render is a partial
+ # _partial:: If a partial, rather than a template, was rendered, return
+ # the partial.
+ # helpers:: A module containing the helpers to be used in the view. This
+ # module should respond_to include.
+ # controller:: The controller that initialized the ActionView
+ #
+ # Override this method in a to change the default behavior.
def _action_view
@_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
end
+ # Mostly abstracts the fact that calling render twice is a DoubleRenderError.
+ # Delegates render_to_body and sticks the result in self.response_body.
def render(*args)
if response_body
raise AbstractController::DoubleRenderError, "OMG"
@@ -27,9 +49,10 @@ def render(*args)
end
# Raw rendering of a template to a Rack-compatible body.
- # ====
- # @option _prefix<String> The template's path prefix
- # @option _layout<String> The relative path to the layout template to use
+ #
+ # ==== Options
+ # _partial_object<Object>:: The object that is being rendered. If this
+ # exists, we are in the special case of rendering an object as a partial.
#
# :api: plugin
def render_to_body(options = {})
@@ -42,21 +65,27 @@ def render_to_body(options = {})
end
end
- # Raw rendering of a template to a string.
- # ====
- # @option _prefix<String> The template's path prefix
- # @option _layout<String> The relative path to the layout template to use
+ # Raw rendering of a template to a string. Just convert the results of
+ # render_to_body into a String.
#
# :api: plugin
def render_to_string(options = {})
AbstractController::Renderer.body_to_s(render_to_body(options))
end
+ # Renders the template from an object.
+ #
+ # ==== Options
+ # _template<ActionView::Template>:: The template to render
+ # _layout<ActionView::Template>:: The layout to wrap the template in (optional)
+ # _partial<TrueClass, FalseClass>:: Whether or not the template to be rendered is a partial
def _render_template(options)
_action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial])
end
- def view_paths()
+ # The list of view paths for this controller. See ActionView::ViewPathSet for
+ # more details about writing custom view paths.
+ def view_paths
_view_paths
end
@@ -73,6 +102,15 @@ def self.body_to_s(body)
end
private
+ # Take in a set of options and determine the template to render
+ #
+ # ==== Options
+ # _template<ActionView::Template>:: If this is provided, the search is over
+ # _template_name<#to_s>:: The name of the template to look up. Otherwise,
+ # use the current action name.
+ # _prefix<String>:: The prefix to look inside of. In a file system, this corresponds
+ # to a directory.
+ # _partial<TrueClass, FalseClass>:: Whether or not the file to look up is a partial
def _determine_template(options)
name = (options[:_template_name] || action_name).to_s
@@ -82,18 +120,36 @@ def _determine_template(options)
end
module ClassMethods
+ # Append a path to the list of view paths for this controller.
+ #
+ # ==== Parameters
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
+ # the default view path. You may also provide a custom view path
+ # (see ActionView::ViewPathSet for more information)
def append_view_path(path)
self.view_paths << path
end
+ # Prepend a path to the list of view paths for this controller.
+ #
+ # ==== Parameters
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
+ # the default view path. You may also provide a custom view path
+ # (see ActionView::ViewPathSet for more information)
def prepend_view_path(path)
self.view_paths.unshift(path)
end
+ # A list of all of the default view paths for this controller.
def view_paths
self._view_paths
end
+ # Set the view paths.
+ #
+ # ==== Parameters
+ # paths<ViewPathSet, Object>:: If a ViewPathSet is provided, use that;
+ # otherwise, process the parameter into a ViewPathSet.
def view_paths=(paths)
self._view_paths = paths.is_a?(ActionView::PathSet) ?
paths : ActionView::Base.process_view_paths(paths)
1,003 actionpack/lib/action_controller/base/base.rb
View
@@ -1,884 +1,167 @@
-require 'action_controller/deprecated'
-require 'set'
-require 'active_support/core_ext/class/inheritable_attributes'
-require 'active_support/core_ext/module/attr_internal'
-
-module ActionController #:nodoc:
- class ActionControllerError < StandardError #:nodoc:
- end
-
- class SessionRestoreError < ActionControllerError #:nodoc:
- end
-
- class RenderError < ActionControllerError #:nodoc:
- end
-
- class RoutingError < ActionControllerError #:nodoc:
- attr_reader :failures
- def initialize(message, failures=[])
- super(message)
- @failures = failures
- end
- end
-
- class MethodNotAllowed < ActionControllerError #:nodoc:
- attr_reader :allowed_methods
-
- def initialize(*allowed_methods)
- super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
- @allowed_methods = allowed_methods
- end
-
- def allowed_methods_header
- allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
- end
- end
-
- class NotImplemented < MethodNotAllowed #:nodoc:
- end
-
- class UnknownController < ActionControllerError #:nodoc:
- end
-
- class UnknownAction < ActionControllerError #:nodoc:
- end
-
- class MissingFile < ActionControllerError #:nodoc:
- end
-
- class RenderError < ActionControllerError #:nodoc:
- end
-
- class SessionOverflowError < ActionControllerError #:nodoc:
- DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.'
-
- def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
- end
- end
-
- class UnknownHttpMethod < ActionControllerError #:nodoc:
- end
-
- # Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed
- # on request and then either render a template or redirect to another action. An action is defined as a public method
- # on the controller, which will automatically be made accessible to the web-server through Rails Routes.
- #
- # A sample controller could look like this:
- #
- # class GuestBookController < ActionController::Base
- # def index
- # @entries = Entry.find(:all)
- # end
- #
- # def sign
- # Entry.create(params[:entry])
- # redirect_to :action => "index"
- # end
- # end
- #
- # Actions, by default, render a template in the <tt>app/views</tt> directory corresponding to the name of the controller and action
- # after executing code in the action. For example, the +index+ action of the GuestBookController would render the
- # template <tt>app/views/guestbook/index.erb</tt> by default after populating the <tt>@entries</tt> instance variable.
- #
- # Unlike index, the sign action will not render a template. After performing its main purpose (creating a
- # new entry in the guest book), it initiates a redirect instead. This redirect works by returning an external
- # "302 Moved" HTTP response that takes the user to the index action.
- #
- # The index and sign represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
- # Most actions are variations of these themes.
- #
- # == Requests
- #
- # Requests are processed by the Action Controller framework by extracting the value of the "action" key in the request parameters.
- # This value should hold the name of the action to be performed. Once the action has been identified, the remaining
- # request parameters, the session (if one is available), and the full request with all the HTTP headers are made available to
- # the action through instance variables. Then the action is performed.
- #
- # The full request object is available with the request accessor and is primarily used to query for HTTP headers. These queries
- # are made by accessing the environment hash, like this:
- #
- # def server_ip
- # location = request.env["SERVER_ADDR"]
- # render :text => "This server hosted at #{location}"
- # end
- #
- # == Parameters
- #
- # All request parameters, whether they come from a GET or POST request, or from the URL, are available through the params method
- # which returns a hash. For example, an action that was performed through <tt>/weblog/list?category=All&limit=5</tt> will include
- # <tt>{ "category" => "All", "limit" => 5 }</tt> in params.
- #
- # It's also possible to construct multi-dimensional parameter hashes by specifying keys using brackets, such as:
- #
- # <input type="text" name="post[name]" value="david">
- # <input type="text" name="post[address]" value="hyacintvej">
- #
- # A request stemming from a form holding these inputs will include <tt>{ "post" => { "name" => "david", "address" => "hyacintvej" } }</tt>.
- # If the address input had been named "post[address][street]", the params would have included
- # <tt>{ "post" => { "address" => { "street" => "hyacintvej" } } }</tt>. There's no limit to the depth of the nesting.
- #
- # == Sessions
- #
- # Sessions allows you to store objects in between requests. This is useful for objects that are not yet ready to be persisted,
- # such as a Signup object constructed in a multi-paged process, or objects that don't change much and are needed all the time, such
- # as a User object for a system that requires login. The session should not be used, however, as a cache for objects where it's likely
- # they could be changed unknowingly. It's usually too much work to keep it all synchronized -- something databases already excel at.
- #
- # You can place objects in the session by using the <tt>session</tt> method, which accesses a hash:
- #
- # session[:person] = Person.authenticate(user_name, password)
- #
- # And retrieved again through the same hash:
- #
- # Hello #{session[:person]}
- #
- # For removing objects from the session, you can either assign a single key to +nil+:
- #
- # # removes :person from session
- # session[:person] = nil
- #
- # or you can remove the entire session with +reset_session+.
- #
- # Sessions are stored by default in a browser cookie that's cryptographically signed, but unencrypted.
- # This prevents the user from tampering with the session but also allows him to see its contents.
- #
- # Do not put secret information in cookie-based sessions!
- #
- # Other options for session storage are:
- #
- # * ActiveRecord::SessionStore - Sessions are stored in your database, which works better than PStore with multiple app servers and,
- # unlike CookieStore, hides your session contents from the user. To use ActiveRecord::SessionStore, set
- #
- # config.action_controller.session_store = :active_record_store
- #
- # in your <tt>config/environment.rb</tt> and run <tt>rake db:sessions:create</tt>.
- #
- # * MemCacheStore - Sessions are stored as entries in your memcached cache.
- # Set the session store type in <tt>config/environment.rb</tt>:
- #
- # config.action_controller.session_store = :mem_cache_store
- #
- # This assumes that memcached has been installed and configured properly.
- # See the MemCacheStore docs for more information.
- #
- # == Responses
- #
- # Each action results in a response, which holds the headers and document to be sent to the user's browser. The actual response
- # object is generated automatically through the use of renders and redirects and requires no user intervention.
- #
- # == Renders
- #
- # Action Controller sends content to the user by using one of five rendering methods. The most versatile and common is the rendering
- # of a template. Included in the Action Pack is the Action View, which enables rendering of ERb templates. It's automatically configured.
- # The controller passes objects to the view by assigning instance variables:
- #
- # def show
- # @post = Post.find(params[:id])
- # end
- #
- # Which are then automatically available to the view:
- #
- # Title: <%= @post.title %>
- #
- # You don't have to rely on the automated rendering. Especially actions that could result in the rendering of different templates will use
- # the manual rendering methods:
- #
- # def search
- # @results = Search.find(params[:query])
- # case @results
- # when 0 then render :action => "no_results"
- # when 1 then render :action => "show"
- # when 2..10 then render :action => "show_many"
- # end
- # end
- #
- # Read more about writing ERb and Builder templates in link:classes/ActionView/Base.html.
- #
- # == Redirects
- #
- # Redirects are used to move from one action to another. For example, after a <tt>create</tt> action, which stores a blog entry to a database,
- # we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're going to reuse (and redirect to)
- # a <tt>show</tt> action that we'll assume has already been created. The code might look like this:
- #
- # def create
- # @entry = Entry.new(params[:entry])
- # if @entry.save
- # # The entry was saved correctly, redirect to show
- # redirect_to :action => 'show', :id => @entry.id
- # else
- # # things didn't go so well, do something else
- # end
- # end
- #
- # In this case, after saving our new entry to the database, the user is redirected to the <tt>show</tt> method which is then executed.
- #
- # == Calling multiple redirects or renders
- #
- # An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError:
- #
- # def do_something
- # redirect_to :action => "elsewhere"
- # render :action => "overthere" # raises DoubleRenderError
- # end
- #
- # If you need to redirect on the condition of something, then be sure to add "and return" to halt execution.
- #
- # def do_something
- # redirect_to(:action => "elsewhere") and return if monkeys.nil?
- # render :action => "overthere" # won't be called if monkeys is nil
- # end
- #
- class Base
-
+module ActionController
+ class Base < Http
+ abstract!
+
+ include AbstractController::Benchmarker
+ include AbstractController::Callbacks
+ include AbstractController::Logger
+
+ include ActionController::Helpers
+ include ActionController::HideActions
+ include ActionController::UrlFor
+ include ActionController::Redirector
+ include ActionController::Renderer
+ include ActionController::Renderers::All
+ include ActionController::Layouts
+ include ActionController::ConditionalGet
+ include ActionController::RackConvenience
+
+ # Legacy modules
+ include SessionManagement
include ActionDispatch::StatusCodes
-
- cattr_reader :protected_instance_variables
- # Controller specific instance variables which will not be accessible inside views.
- @@protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
- @action_name @before_filter_chain_aborted @action_cache_path @_headers @_params
- @_flash @_response)
-
- # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
- # and images to a dedicated asset server away from the main web server. Example:
- # ActionController::Base.asset_host = "http://assets.example.com"
- cattr_accessor :asset_host
-
- # All requests are considered local by default, so everyone will be exposed to detailed debugging screens on errors.
- # When the application is ready to go public, this should be set to false, and the protected method <tt>local_request?</tt>
- # should instead be implemented in the controller to determine when debugging screens should be shown.
- @@consider_all_requests_local = true
- cattr_accessor :consider_all_requests_local
-
- # Indicates whether to allow concurrent action processing. Your
- # controller actions and any other code they call must also behave well
- # when called from concurrent threads. Turned off by default.
- @@allow_concurrency = false
- cattr_accessor :allow_concurrency
-
- # Modern REST web services often need to submit complex data to the web application.
- # The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
- # <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
- #
- # By default <tt>application/xml</tt> is enabled. A XmlSimple class with the same param name as the root will be instantiated
- # in the <tt>params</tt>. This allows XML requests to mask themselves as regular form submissions, so you can have one
- # action serve both regular forms and web service requests.
- #
- # Example of doing your own parser for a custom content type:
- #
- # ActionController::Base.param_parsers[Mime::Type.lookup('application/atom+xml')] = Proc.new do |data|
- # node = REXML::Document.new(post)
- # { node.root.name => node.root }
- # end
- #
- # Note: Up until release 1.1 of Rails, Action Controller would default to using XmlSimple configured to discard the
- # root node for such requests. The new default is to keep the root, such that "<r><name>David</name></r>" results
- # in <tt>params[:r][:name]</tt> for "David" instead of <tt>params[:name]</tt>. To get the old behavior, you can
- # re-register XmlSimple as application/xml handler ike this:
- #
- # ActionController::Base.param_parsers[Mime::XML] =
- # Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
- #
- # A YAML parser is also available and can be turned on with:
- #
- # ActionController::Base.param_parsers[Mime::YAML] = :yaml
- @@param_parsers = { Mime::MULTIPART_FORM => :multipart_form,
- Mime::URL_ENCODED_FORM => :url_encoded_form,
- Mime::XML => :xml_simple,
- Mime::JSON => :json }
- cattr_accessor :param_parsers
-
- # Controls the default charset for all renders.
- @@default_charset = "utf-8"
- cattr_accessor :default_charset
-
- # The logger is used for generating information on the action run-time (including benchmarking) if available.
- # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
- cattr_accessor :logger
-
- # Controls the resource action separator
- @@resource_action_separator = "/"
- cattr_accessor :resource_action_separator
-
- # Allow to override path names for default resources' actions
- @@resources_path_names = { :new => 'new', :edit => 'edit' }
- cattr_accessor :resources_path_names
-
- # Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
- # sets it to <tt>:authenticity_token</tt> by default.
- cattr_accessor :request_forgery_protection_token
-
- # Controls the IP Spoofing check when determining the remote IP.
- @@ip_spoofing_check = true
- cattr_accessor :ip_spoofing_check
-
- # Indicates whether or not optimise the generated named
- # route helper methods
- cattr_accessor :optimise_named_routes
- self.optimise_named_routes = true
-
- # Indicates whether the response format should be determined by examining the Accept HTTP header,
- # or by using the simpler params + ajax rules.
- #
- # If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept
- # header into account. If it is set to false then the request format will be determined solely
- # by examining params[:format]. If params format is missing, the format will be either HTML or
- # Javascript depending on whether the request is an AJAX request.
- cattr_accessor :use_accept_header
- self.use_accept_header = true
-
- # Controls whether request forgery protection is turned on or not. Turned off by default only in test mode.
- class_inheritable_accessor :allow_forgery_protection
- self.allow_forgery_protection = true
-
- # If you are deploying to a subdirectory, you will need to set
- # <tt>config.action_controller.relative_url_root</tt>
- # This defaults to ENV['RAILS_RELATIVE_URL_ROOT']
- cattr_accessor :relative_url_root
- self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
-
- # Holds the request object that's primarily used to get environment variables through access like
- # <tt>request.env["REQUEST_URI"]</tt>.
- attr_internal :request
-
- # Holds a hash of all the GET, POST, and Url parameters passed to the action. Accessed like <tt>params["post_id"]</tt>
- # to get the post_id. No type casts are made, so all values are returned as strings.
- attr_internal :params
-
- # Holds the response object that's primarily used to set additional HTTP headers through access like
- # <tt>response.headers["Cache-Control"] = "no-cache"</tt>. Can also be used to access the final body HTML after a template
- # has been rendered through response.body -- useful for <tt>after_filter</tt>s that wants to manipulate the output,
- # such as a OutputCompressionFilter.
- attr_internal :response
-
- # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person"
- # key. The session will hold any type of object as values, but the key should be a string or symbol.
- def session
- request.session
- end
-
- # Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control
- # directive. Values should always be specified as strings.
- attr_internal :headers
-
- # Returns the name of the action this controller is processing.
- attr_accessor :action_name
-
- attr_reader :template
-
- def action(name, env)
- request = ActionDispatch::Request.new(env)
- response = ActionDispatch::Response.new
- self.action_name = name && name.to_s
- process(request, response).to_a
- end
-
-
- class << self
- def action(name = nil)
- @actions ||= {}
- @actions[name] ||= proc do |env|
- new.action(name, env)
- end
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController".
- def controller_class_name
- @controller_class_name ||= name.demodulize
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "neat".
- def controller_name
- @controller_name ||= controller_class_name.sub(/Controller$/, '').underscore
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat".
- def controller_path
- @controller_path ||= name.gsub(/Controller$/, '').underscore
- end
-
- # Return an array containing the names of public methods that have been marked hidden from the action processor.
- # By default, all methods defined in ActionController::Base and included modules are hidden.
- # More methods can be hidden using <tt>hide_action</tt>.
- def hidden_actions
- read_inheritable_attribute(:hidden_actions) || write_inheritable_attribute(:hidden_actions, [])
- end
-
- # Hide each of the given methods from being callable as actions.
- def hide_action(*names)
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.map { |name| name.to_s })
- end
-
- # View load paths determine the bases from which template references can be made. So a call to
- # render("test/template") will be looked up in the view load paths array and the closest match will be
- # returned.
- def view_paths
- if defined? @view_paths
- @view_paths
- else
- superclass.view_paths
- end
- end
-
- def view_paths=(value)
- @view_paths = ActionView::Base.process_view_paths(value) if value
- end
-
- # Adds a view_path to the front of the view_paths array.
- # If the current class has no view paths, copy them from
- # the superclass. This change will be visible for all future requests.
- #
- # ArticleController.prepend_view_path("views/default")
- # ArticleController.prepend_view_path(["views/default", "views/custom"])
- #
- def prepend_view_path(path)
- @view_paths = superclass.view_paths.dup if !defined?(@view_paths) || @view_paths.nil?
- @view_paths.unshift(*path)
+ include ActionController::Caching
+ include ActionController::MimeResponds
+
+ # Rails 2.x compatibility
+ include ActionController::Rails2Compatibility
+
+ include ActionController::Cookies
+ include ActionController::Session
+ include ActionController::Flash
+ include ActionController::Verification
+ include ActionController::RequestForgeryProtection
+ include ActionController::Streaming
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
+ include ActionController::HttpAuthentication::Digest::ControllerMethods
+ include ActionController::FilterParameterLogging
+ include ActionController::Translation
+
+ # TODO: Extract into its own module
+ # This should be moved together with other normalizing behavior
+ module ImplicitRender
+ def send_action(*)
+ ret = super
+ default_render unless performed?
+ ret
+ end
+
+ def default_render
+ render
end
- # Adds a view_path to the end of the view_paths array.
- # If the current class has no view paths, copy them from
- # the superclass. This change will be visible for all future requests.
- #
- # ArticleController.append_view_path("views/default")
- # ArticleController.append_view_path(["views/default", "views/custom"])
- #
- def append_view_path(path)
- @view_paths = superclass.view_paths.dup if @view_paths.nil?
- @view_paths.push(*path)
- end
-
- @@exempt_from_layout = [ActionView::TemplateHandlers::RJS]
-
- def exempt_from_layout(*types)
- types.each do |type|
- @@exempt_from_layout <<
- ActionView::Template.handler_class_for_extension(type)
+ def method_for_action(action_name)
+ super || begin
+ if view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
+ "default_render"
+ end
end
-
- @@exempt_from_layout
end
-
end
- public
- def call(env)
- request = ActionDispatch::Request.new(env)
- response = ActionDispatch::Response.new
- process(request, response).to_a
- end
-
- # Extracts the action_name from the request parameters and performs that action.
- def process(request, response, method = :perform_action, *arguments) #:nodoc:
- response.request = request
+ include ImplicitRender
- assign_shortcuts(request, response)
- initialize_template_class(response)
- initialize_current_url
+ include ActionController::Rescue
- log_processing
- send(method, *arguments)
-
- send_response
- ensure
- process_cleanup
- end
-
- def send_response
- response.prepare!
- response
- end
-
- # Returns a URL that has been rewritten according to the options hash and the defined routes.
- # (For doing a complete redirect, use +redirect_to+).
- #
- # <tt>url_for</tt> is used to:
- #
- # All keys given to +url_for+ are forwarded to the Route module, save for the following:
- # * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path. For example,
- # <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
- # will produce "/posts/show/10#comments".
- # * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>false</tt> by default).
- # * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
- # is currently not recommended since it breaks caching.
- # * <tt>:host</tt> - Overrides the default (current) host if provided.
- # * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
- # * <tt>:port</tt> - Optionally specify the port to connect to.
- # * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
- # * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
- # * <tt>:skip_relative_url_root</tt> - If true, the url is not constructed using the +relative_url_root+
- # of the request so the path will include the web server relative installation directory.
- #
- # The URL is generated from the remaining keys in the hash. A URL contains two key parts: the <base> and a query string.
- # Routes composes a query string as the key/value pairs not included in the <base>.
- #
- # The default Routes setup supports a typical Rails path of "controller/action/id" where action and id are optional, with
- # action defaulting to 'index' when not given. Here are some typical url_for statements and their corresponding URLs:
- #
- # url_for :controller => 'posts', :action => 'recent' # => 'proto://host.com/posts/recent'
- # url_for :controller => 'posts', :action => 'index' # => 'proto://host.com/posts'
- # url_for :controller => 'posts', :action => 'index', :port=>'8033' # => 'proto://host.com:8033/posts'
- # url_for :controller => 'posts', :action => 'show', :id => 10 # => 'proto://host.com/posts/show/10'
- # url_for :controller => 'posts', :user => 'd', :password => '123' # => 'proto://d:123@host.com/posts'
- #
- # When generating a new URL, missing values may be filled in from the current request's parameters. For example,
- # <tt>url_for :action => 'some_action'</tt> will retain the current controller, as expected. This behavior extends to
- # other parameters, including <tt>:controller</tt>, <tt>:id</tt>, and any other parameters that are placed into a Route's
- # path.
- #  
- # The URL helpers such as <tt>url_for</tt> have a limited form of memory: when generating a new URL, they can look for
- # missing values in the current request's parameters. Routes attempts to guess when a value should and should not be
- # taken from the defaults. There are a few simple rules on how this is performed:
- #
- # * If the controller name begins with a slash no defaults are used:
- #
- # url_for :controller => '/home'
- #
- # In particular, a leading slash ensures no namespace is assumed. Thus,
- # while <tt>url_for :controller => 'users'</tt> may resolve to
- # <tt>Admin::UsersController</tt> if the current controller lives under
- # that module, <tt>url_for :controller => '/users'</tt> ensures you link
- # to <tt>::UsersController</tt> no matter what.
- # * If the controller changes, the action will default to index unless provided
- #
- # The final rule is applied while the URL is being generated and is best illustrated by an example. Let us consider the
- # route given by <tt>map.connect 'people/:last/:first/:action', :action => 'bio', :controller => 'people'</tt>.
- #
- # Suppose that the current URL is "people/hh/david/contacts". Let's consider a few different cases of URLs which are generated
- # from this page.
- #
- # * <tt>url_for :action => 'bio'</tt> -- During the generation of this URL, default values will be used for the first and
- # last components, and the action shall change. The generated URL will be, "people/hh/david/bio".
- # * <tt>url_for :first => 'davids-little-brother'</tt> This generates the URL 'people/hh/davids-little-brother' -- note
- # that this URL leaves out the assumed action of 'bio'.
- #
- # However, you might ask why the action from the current request, 'contacts', isn't carried over into the new URL. The
- # answer has to do with the order in which the parameters appear in the generated path. In a nutshell, since the
- # value that appears in the slot for <tt>:first</tt> is not equal to default value for <tt>:first</tt> we stop using
- # defaults. On its own, this rule can account for much of the typical Rails URL behavior.
- #  
- # Although a convenience, defaults can occasionally get in your way. In some cases a default persists longer than desired.
- # The default may be cleared by adding <tt>:name => nil</tt> to <tt>url_for</tt>'s options.
- # This is often required when writing form helpers, since the defaults in play may vary greatly depending upon where the
- # helper is used from. The following line will redirect to PostController's default action, regardless of the page it is
- # displayed on:
- #
- # url_for :controller => 'posts', :action => nil
- #
- # If you explicitly want to create a URL that's almost the same as the current URL, you can do so using the
- # <tt>:overwrite_params</tt> options. Say for your posts you have different views for showing and printing them.
- # Then, in the show view, you get the URL for the print view like this
- #
- # url_for :overwrite_params => { :action => 'print' }
- #
- # This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action => 'print'</tt>
- # would have slashed-off the path components after the changed action.
- def url_for(options = {})
- options ||= {}
- case options
- when String
- options
- when Hash
- @url.rewrite(rewrite_options(options))
- else
- polymorphic_url(options)
- end
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController".
- def controller_class_name
- self.class.controller_class_name
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "neat".
- def controller_name
- self.class.controller_name
- end
-
- # Converts the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat".
- def controller_path
- self.class.controller_path
- end
-
- def session_enabled?
- ActiveSupport::Deprecation.warn("Sessions are now lazy loaded. So if you don't access them, consider them disabled.", caller)
- end
-
- self.view_paths = []
-
- # View load paths for controller.
- def view_paths
- @template.view_paths
- end
-
- def view_paths=(value)
- @template.view_paths = ActionView::Base.process_view_paths(value)
- end
-
- # Adds a view_path to the front of the view_paths array.
- # This change affects the current request only.
- #
- # self.prepend_view_path("views/default")
- # self.prepend_view_path(["views/default", "views/custom"])
- #
- def prepend_view_path(path)
- @template.view_paths.unshift(*path)
- end
-
- # Adds a view_path to the end of the view_paths array.
- # This change affects the current request only.
- #
- # self.append_view_path("views/default")
- # self.append_view_path(["views/default", "views/custom"])
- #
- def append_view_path(path)
- @template.view_paths.push(*path)
- end
-
- def rewrite_options(options) #:nodoc:
- if defaults = default_url_options(options)
- defaults.merge(options)
- else
- options
- end
- end
-
- # Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in
- # the form of a hash, just like the one you would use for url_for directly. Example:
- #
- # def default_url_options(options)
- # { :project => @project.active? ? @project.url_name : "unknown" }
- # end
- #
- # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
- # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
- # by this method.
- def default_url_options(options = nil)
- end
-
- # Sets the etag and/or last_modified on the response and checks it against
- # the client request. If the request doesn't match the options provided, the
- # request is considered stale and should be generated from scratch. Otherwise,
- # it's fresh and we don't need to generate anything and a reply of "304 Not Modified" is sent.
- #
- # Parameters:
- # * <tt>:etag</tt>
- # * <tt>:last_modified</tt>
- # * <tt>:public</tt> By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches).
- #
- # Example:
- #
- # def show
- # @article = Article.find(params[:id])
- #
- # if stale?(:etag => @article, :last_modified => @article.created_at.utc)