merb 0.5.3 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. data/LICENSE +0 -20
  2. data/README +0 -277
  3. data/Rakefile +80 -199
  4. data/TODO +0 -3
  5. metadata +19 -438
  6. data/SVN_REVISION +0 -1
  7. data/app_generators/merb/USAGE +0 -5
  8. data/app_generators/merb/merb_generator.rb +0 -108
  9. data/app_generators/merb/templates/Rakefile +0 -124
  10. data/app_generators/merb/templates/app/controllers/application.rb +0 -3
  11. data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
  12. data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
  13. data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
  14. data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
  15. data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
  16. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
  17. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
  18. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
  19. data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
  20. data/app_generators/merb/templates/config/boot.rb +0 -11
  21. data/app_generators/merb/templates/config/dependencies.rb +0 -41
  22. data/app_generators/merb/templates/config/environments/development.rb +0 -1
  23. data/app_generators/merb/templates/config/environments/production.rb +0 -1
  24. data/app_generators/merb/templates/config/environments/test.rb +0 -1
  25. data/app_generators/merb/templates/config/merb.yml +0 -82
  26. data/app_generators/merb/templates/config/merb_init.rb +0 -17
  27. data/app_generators/merb/templates/config/plugins.yml +0 -1
  28. data/app_generators/merb/templates/config/router.rb +0 -35
  29. data/app_generators/merb/templates/config/upload.conf +0 -0
  30. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  31. data/app_generators/merb/templates/public/merb.fcgi +0 -6
  32. data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
  33. data/app_generators/merb/templates/script/destroy +0 -32
  34. data/app_generators/merb/templates/script/generate +0 -32
  35. data/app_generators/merb/templates/script/stop_merb +0 -13
  36. data/app_generators/merb/templates/script/win_script.cmd +0 -1
  37. data/app_generators/merb/templates/spec/spec.opts +0 -6
  38. data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
  39. data/app_generators/merb/templates/test/test_helper.rb +0 -14
  40. data/app_generators/merb_plugin/USAGE +0 -5
  41. data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
  42. data/app_generators/merb_plugin/templates/LICENSE +0 -20
  43. data/app_generators/merb_plugin/templates/README +0 -4
  44. data/app_generators/merb_plugin/templates/Rakefile +0 -35
  45. data/app_generators/merb_plugin/templates/TODO +0 -5
  46. data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
  47. data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
  48. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
  49. data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
  50. data/bin/merb +0 -4
  51. data/lib/autotest/discover.rb +0 -3
  52. data/lib/autotest/merb_rspec.rb +0 -80
  53. data/lib/merb.rb +0 -188
  54. data/lib/merb/abstract_controller.rb +0 -399
  55. data/lib/merb/assets.rb +0 -160
  56. data/lib/merb/assets.rb.orig +0 -119
  57. data/lib/merb/boot_loader.rb +0 -286
  58. data/lib/merb/boot_loader.rb.orig +0 -235
  59. data/lib/merb/caching.rb +0 -5
  60. data/lib/merb/caching/action_cache.rb +0 -92
  61. data/lib/merb/caching/fragment_cache.rb +0 -39
  62. data/lib/merb/caching/store/file_cache.rb +0 -90
  63. data/lib/merb/caching/store/memory_cache.rb +0 -85
  64. data/lib/merb/config.rb +0 -290
  65. data/lib/merb/constants.rb +0 -50
  66. data/lib/merb/controller.rb +0 -220
  67. data/lib/merb/cookies.rb +0 -95
  68. data/lib/merb/core_ext.rb +0 -15
  69. data/lib/merb/core_ext/array.rb +0 -0
  70. data/lib/merb/core_ext/class.rb +0 -180
  71. data/lib/merb/core_ext/enumerable.rb +0 -49
  72. data/lib/merb/core_ext/get_args.rb +0 -76
  73. data/lib/merb/core_ext/hash.rb +0 -306
  74. data/lib/merb/core_ext/inflections.rb +0 -112
  75. data/lib/merb/core_ext/inflector.rb +0 -275
  76. data/lib/merb/core_ext/kernel.rb +0 -242
  77. data/lib/merb/core_ext/mash.rb +0 -88
  78. data/lib/merb/core_ext/module.rb +0 -67
  79. data/lib/merb/core_ext/numeric.rb +0 -72
  80. data/lib/merb/core_ext/object.rb +0 -183
  81. data/lib/merb/core_ext/string.rb +0 -53
  82. data/lib/merb/core_ext/symbol.rb +0 -6
  83. data/lib/merb/dispatcher.rb +0 -109
  84. data/lib/merb/drb_server.rb +0 -19
  85. data/lib/merb/erubis_ext.rb +0 -10
  86. data/lib/merb/exceptions.rb +0 -192
  87. data/lib/merb/generators/merb_app/merb_app.rb +0 -22
  88. data/lib/merb/generators/merb_generator_helpers.rb +0 -318
  89. data/lib/merb/generators/merb_plugin.rb +0 -22
  90. data/lib/merb/logger.rb +0 -78
  91. data/lib/merb/mail_controller.rb +0 -268
  92. data/lib/merb/mailer.rb +0 -87
  93. data/lib/merb/mixins/basic_authentication.rb +0 -35
  94. data/lib/merb/mixins/controller.rb +0 -160
  95. data/lib/merb/mixins/erubis_capture.rb +0 -68
  96. data/lib/merb/mixins/general_controller.rb +0 -253
  97. data/lib/merb/mixins/inline_partial.rb +0 -32
  98. data/lib/merb/mixins/render.rb +0 -465
  99. data/lib/merb/mixins/responder.rb +0 -449
  100. data/lib/merb/mixins/view_context.rb +0 -558
  101. data/lib/merb/mixins/web_controller.rb +0 -36
  102. data/lib/merb/mongrel_handler.rb +0 -168
  103. data/lib/merb/part_controller.rb +0 -29
  104. data/lib/merb/plugins.rb +0 -16
  105. data/lib/merb/rack_adapter.rb +0 -37
  106. data/lib/merb/request.rb +0 -465
  107. data/lib/merb/router.rb +0 -646
  108. data/lib/merb/server.rb +0 -169
  109. data/lib/merb/session.rb +0 -23
  110. data/lib/merb/session/cookie_store.rb +0 -118
  111. data/lib/merb/session/mem_cache_session.rb +0 -131
  112. data/lib/merb/session/memory_session.rb +0 -176
  113. data/lib/merb/template.rb +0 -37
  114. data/lib/merb/template/erubis.rb +0 -68
  115. data/lib/merb/template/haml.rb +0 -87
  116. data/lib/merb/template/markaby.rb +0 -59
  117. data/lib/merb/template/xml_builder.rb +0 -50
  118. data/lib/merb/test/fake_request.rb +0 -74
  119. data/lib/merb/test/helper.rb +0 -260
  120. data/lib/merb/test/hpricot.rb +0 -136
  121. data/lib/merb/test/multipart.rb +0 -66
  122. data/lib/merb/test/rspec.rb +0 -18
  123. data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
  124. data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
  125. data/lib/merb/upload_handler.rb +0 -80
  126. data/lib/merb/upload_progress.rb +0 -48
  127. data/lib/merb/version.rb +0 -49
  128. data/lib/merb/view_context.rb +0 -79
  129. data/lib/tasks.rb +0 -7
  130. data/lib/tasks/merb.rake +0 -54
  131. data/merb_default_generators/model/USAGE +0 -0
  132. data/merb_default_generators/model/model_generator.rb +0 -16
  133. data/merb_default_generators/model/templates/new_model_template.erb +0 -5
  134. data/merb_default_generators/resource_controller/USAGE +0 -0
  135. data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
  136. data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
  137. data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
  138. data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
  139. data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
  140. data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
  141. data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
  142. data/merb_generators/controller/USAGE +0 -5
  143. data/merb_generators/controller/controller_generator.rb +0 -16
  144. data/merb_generators/controller/templates/controller.rb +0 -8
  145. data/merb_generators/controller/templates/helper.rb +0 -5
  146. data/merb_generators/controller/templates/index.html.erb +0 -3
  147. data/merb_generators/part_controller/USAGE +0 -5
  148. data/merb_generators/part_controller/part_controller_generator.rb +0 -27
  149. data/merb_generators/part_controller/templates/controller.rb +0 -8
  150. data/merb_generators/part_controller/templates/helper.rb +0 -5
  151. data/merb_generators/part_controller/templates/index.html.erb +0 -3
  152. data/merb_generators/resource/USAGE +0 -0
  153. data/merb_generators/resource/resource_generator.rb +0 -67
  154. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
  155. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
  156. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
  157. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
  158. data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
  159. data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
  160. data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
  161. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
  162. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
  163. data/script/destroy +0 -14
  164. data/script/generate +0 -14
  165. data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
  166. data/spec/fixtures/config/merb.yml +0 -18
  167. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
  168. data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
  169. data/spec/fixtures/foo.rb +0 -3
  170. data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
  171. data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
  172. data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
  173. data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
  174. data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
  175. data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
  176. data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
  177. data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
  178. data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
  179. data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
  180. data/spec/fixtures/models/router_spec_models.rb +0 -30
  181. data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
  182. data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
  183. data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
  184. data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
  185. data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
  186. data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
  187. data/spec/fixtures/sample.txt +0 -1
  188. data/spec/fixtures/views/erubis.html.erb +0 -1
  189. data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
  190. data/spec/fixtures/views/examples/_haml.html.haml +0 -1
  191. data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
  192. data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
  193. data/spec/fixtures/views/examples/hello.xml.builder +0 -1
  194. data/spec/fixtures/views/examples/js.js.erb +0 -1
  195. data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
  196. data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
  197. data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
  198. data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
  199. data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
  200. data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
  201. data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
  202. data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
  203. data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
  204. data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
  205. data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
  206. data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
  207. data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
  208. data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
  209. data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
  210. data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
  211. data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
  212. data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
  213. data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
  214. data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
  215. data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
  216. data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
  217. data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
  218. data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
  219. data/spec/fixtures/views/haml.html.haml +0 -1
  220. data/spec/fixtures/views/haml.xml.haml +0 -2
  221. data/spec/fixtures/views/layout/application.html.erb +0 -1
  222. data/spec/fixtures/views/layout/application.xml.erb +0 -1
  223. data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
  224. data/spec/fixtures/views/markaby.html.mab +0 -1
  225. data/spec/fixtures/views/nested/example/test.html.erb +0 -1
  226. data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
  227. data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
  228. data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
  229. data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
  230. data/spec/fixtures/views/partials/_haml.html.haml +0 -1
  231. data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
  232. data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
  233. data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
  234. data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
  235. data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
  236. data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
  237. data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
  238. data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
  239. data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
  240. data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
  241. data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
  242. data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
  243. data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
  244. data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
  245. data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
  246. data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
  247. data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
  248. data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
  249. data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
  250. data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
  251. data/spec/merb/abstract_controller_spec.rb +0 -38
  252. data/spec/merb/assets_spec.rb +0 -207
  253. data/spec/merb/caching_spec.rb +0 -102
  254. data/spec/merb/config_spec.rb +0 -29
  255. data/spec/merb/controller_filters_spec.rb +0 -253
  256. data/spec/merb/controller_spec.rb +0 -126
  257. data/spec/merb/cookie_store_spec.rb +0 -72
  258. data/spec/merb/cookies_spec.rb +0 -96
  259. data/spec/merb/core_ext/class_spec.rb +0 -97
  260. data/spec/merb/core_ext/enumerable_spec.rb +0 -27
  261. data/spec/merb/core_ext/hash_spec.rb +0 -251
  262. data/spec/merb/core_ext/inflector_spec.rb +0 -34
  263. data/spec/merb/core_ext/kernel_spec.rb +0 -25
  264. data/spec/merb/core_ext/numeric_spec.rb +0 -26
  265. data/spec/merb/core_ext/object_spec.rb +0 -47
  266. data/spec/merb/core_ext/string_spec.rb +0 -22
  267. data/spec/merb/core_ext/symbol_spec.rb +0 -7
  268. data/spec/merb/dependency_spec.rb +0 -22
  269. data/spec/merb/dispatch_spec.rb +0 -528
  270. data/spec/merb/fake_request_spec.rb +0 -80
  271. data/spec/merb/generator_spec.rb +0 -248
  272. data/spec/merb/handler_spec.rb +0 -169
  273. data/spec/merb/mail_controller_spec.rb +0 -177
  274. data/spec/merb/mailer_spec.rb +0 -87
  275. data/spec/merb/multipart_spec.rb +0 -50
  276. data/spec/merb/part_controller_spec.rb +0 -124
  277. data/spec/merb/plugins_spec.rb +0 -80
  278. data/spec/merb/render_spec.rb +0 -469
  279. data/spec/merb/request_spec.rb +0 -287
  280. data/spec/merb/responder_spec.rb +0 -562
  281. data/spec/merb/router_spec.rb +0 -900
  282. data/spec/merb/server_spec.rb +0 -19
  283. data/spec/merb/template_spec.rb +0 -41
  284. data/spec/merb/upload_handler_spec.rb +0 -108
  285. data/spec/merb/version_spec.rb +0 -33
  286. data/spec/merb/view_context_spec.rb +0 -366
  287. data/spec/spec_generator_helper.rb +0 -34
  288. data/spec/spec_helper.rb +0 -101
  289. data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
  290. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
  291. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
  292. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
  293. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
  294. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
@@ -1,275 +0,0 @@
1
- require 'singleton'
2
-
3
- # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
4
- # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
5
- # in inflections.rb.
6
- module Inflector
7
- # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
8
- # inflection rules. Examples:
9
- #
10
- # Inflector.inflections do |inflect|
11
- # inflect.plural /^(ox)$/i, '\1\2en'
12
- # inflect.singular /^(ox)en/i, '\1'
13
- #
14
- # inflect.irregular 'octopus', 'octopi'
15
- #
16
- # inflect.uncountable "equipment"
17
- # end
18
- #
19
- # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
20
- # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
21
- # already have been loaded.
22
- class Inflections
23
- include Singleton
24
-
25
- attr_reader :plurals, :singulars, :uncountables
26
-
27
- def initialize
28
- @plurals, @singulars, @uncountables = [], [], []
29
- end
30
-
31
- # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
32
- # The replacement should always be a string that may include references to the matched data from the rule.
33
- def plural(rule, replacement)
34
- @plurals.insert(0, [rule, replacement])
35
- end
36
-
37
- # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
38
- # The replacement should always be a string that may include references to the matched data from the rule.
39
- def singular(rule, replacement)
40
- @singulars.insert(0, [rule, replacement])
41
- end
42
-
43
- # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
44
- # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
45
- #
46
- # Examples:
47
- # irregular 'octopus', 'octopi'
48
- # irregular 'person', 'people'
49
- def irregular(singular, plural)
50
- plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
51
- singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
52
- end
53
-
54
- # Add uncountable words that shouldn't be attempted inflected.
55
- #
56
- # Examples:
57
- # uncountable "money"
58
- # uncountable "money", "information"
59
- # uncountable %w( money information rice )
60
- def uncountable(*words)
61
- (@uncountables << words).flatten!
62
- end
63
-
64
- # Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type,
65
- # the options are: :plurals, :singulars, :uncountables
66
- #
67
- # Examples:
68
- # clear :all
69
- # clear :plurals
70
- def clear(scope = :all)
71
- case scope
72
- when :all
73
- @plurals, @singulars, @uncountables = [], [], []
74
- else
75
- instance_variable_set "@#{scope}", []
76
- end
77
- end
78
- end
79
-
80
- extend self
81
-
82
- def inflections
83
- if block_given?
84
- yield Inflections.instance
85
- else
86
- Inflections.instance
87
- end
88
- end
89
-
90
- # Returns the plural form of the word in the string.
91
- #
92
- # Examples
93
- # "post".pluralize #=> "posts"
94
- # "octopus".pluralize #=> "octopi"
95
- # "sheep".pluralize #=> "sheep"
96
- # "words".pluralize #=> "words"
97
- # "the blue mailman".pluralize #=> "the blue mailmen"
98
- # "CamelOctopus".pluralize #=> "CamelOctopi"
99
- def pluralize(word)
100
- result = word.to_s.dup
101
-
102
- if inflections.uncountables.include?(result.downcase)
103
- result
104
- else
105
- inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
106
- result
107
- end
108
- end
109
-
110
- # The reverse of pluralize, returns the singular form of a word in a string.
111
- #
112
- # Examples
113
- # "posts".singularize #=> "post"
114
- # "octopi".singularize #=> "octopus"
115
- # "sheep".singluarize #=> "sheep"
116
- # "word".singluarize #=> "word"
117
- # "the blue mailmen".singularize #=> "the blue mailman"
118
- # "CamelOctopi".singularize #=> "CamelOctopus"
119
- def singularize(word)
120
- result = word.to_s.dup
121
-
122
- if inflections.uncountables.include?(result.downcase)
123
- result
124
- else
125
- inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
126
- result
127
- end
128
- end
129
-
130
- # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
131
- # is set to ":lower" then camelize produces lowerCamelCase.
132
- #
133
- # camelize will also convert '/' to '::' which is useful for converting paths to namespaces
134
- #
135
- # Examples
136
- # "active_record".camelize #=> "ActiveRecord"
137
- # "active_record".camelize(:lower) #=> "activeRecord"
138
- # "active_record/errors".camelize #=> "ActiveRecord::Errors"
139
- # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
140
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
141
- if first_letter_in_uppercase
142
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
143
- else
144
- lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
145
- end
146
- end
147
-
148
- # Capitalizes all the words and replaces some characters in the string to create
149
- # a nicer looking title. Titleize is meant for creating pretty output. It is not
150
- # used in the Rails internals.
151
- #
152
- # titleize is also aliased as as titlecase
153
- #
154
- # Examples
155
- # "man from the boondocks".titleize #=> "Man From The Boondocks"
156
- # "x-men: the last stand".titleize #=> "X Men: The Last Stand"
157
- def titleize(word)
158
- humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
159
- end
160
-
161
- # The reverse of +camelize+. Makes an underscored form from the expression in the string.
162
- #
163
- # Changes '::' to '/' to convert namespaces to paths.
164
- #
165
- # Examples
166
- # "ActiveRecord".underscore #=> "active_record"
167
- # "ActiveRecord::Errors".underscore #=> active_record/errors
168
- def underscore(camel_cased_word)
169
- camel_cased_word.to_s.gsub(/::/, '/').
170
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
171
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
172
- tr("-", "_").
173
- downcase
174
- end
175
-
176
- # Replaces underscores with dashes in the string.
177
- #
178
- # Example
179
- # "puni_puni" #=> "puni-puni"
180
- def dasherize(underscored_word)
181
- underscored_word.gsub(/_/, '-')
182
- end
183
-
184
- # Capitalizes the first word and turns underscores into spaces and strips _id.
185
- # Like titleize, this is meant for creating pretty output.
186
- #
187
- # Examples
188
- # "employee_salary" #=> "Employee salary"
189
- # "author_id" #=> "Author"
190
- def humanize(lower_case_and_underscored_word)
191
- lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
192
- end
193
-
194
- # Removes the module part from the expression in the string
195
- #
196
- # Examples
197
- # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
198
- # "Inflections".demodulize #=> "Inflections"
199
- def demodulize(class_name_in_module)
200
- class_name_in_module.to_s.gsub(/^.*::/, '')
201
- end
202
-
203
- # Create the name of a table like Rails does for models to table names. This method
204
- # uses the pluralize method on the last word in the string.
205
- #
206
- # Examples
207
- # "RawScaledScorer".tableize #=> "raw_scaled_scorers"
208
- # "egg_and_ham".tableize #=> "egg_and_hams"
209
- # "fancyCategory".tableize #=> "fancy_categories"
210
- def tableize(class_name)
211
- pluralize(underscore(class_name))
212
- end
213
-
214
- # Create a class name from a table name like Rails does for table names to models.
215
- # Note that this returns a string and not a Class. (To convert to an actual class
216
- # follow classify with constantize.)
217
- #
218
- # Examples
219
- # "egg_and_hams".classify #=> "EggAndHam"
220
- # "post".classify #=> "Post"
221
- def classify(table_name)
222
- # strip out any leading schema name
223
- camelize(singularize(table_name.to_s.sub(/.*\./, '')))
224
- end
225
-
226
- # Creates a foreign key name from a class name.
227
- # +separate_class_name_and_id_with_underscore+ sets whether
228
- # the method should put '_' between the name and 'id'.
229
- #
230
- # Examples
231
- # "Message".foreign_key #=> "message_id"
232
- # "Message".foreign_key(false) #=> "messageid"
233
- # "Admin::Post".foreign_key #=> "post_id"
234
- def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
235
- underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
236
- end
237
-
238
- # Constantize tries to find a declared constant with the name specified
239
- # in the string. It raises a NameError when the name is not in CamelCase
240
- # or is not initialized.
241
- #
242
- # Examples
243
- # "Module".constantize #=> Module
244
- # "Class".constantize #=> Class
245
- def constantize(camel_cased_word)
246
- unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
247
- raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
248
- end
249
-
250
- Object.module_eval("::#{$1}", __FILE__, __LINE__)
251
- end
252
-
253
- # Ordinalize turns a number into an ordinal string used to denote the
254
- # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
255
- #
256
- # Examples
257
- # ordinalize(1) # => "1st"
258
- # ordinalize(2) # => "2nd"
259
- # ordinalize(1002) # => "1002nd"
260
- # ordinalize(1003) # => "1003rd"
261
- def ordinalize(number)
262
- if (11..13).include?(number.to_i % 100)
263
- "#{number}th"
264
- else
265
- case number.to_i % 10
266
- when 1: "#{number}st"
267
- when 2: "#{number}nd"
268
- when 3: "#{number}rd"
269
- else "#{number}th"
270
- end
271
- end
272
- end
273
- end
274
-
275
- require File.dirname(__FILE__) + '/inflections'
@@ -1,242 +0,0 @@
1
- module Kernel
2
- # Loads the given string as a gem.
3
- # An optional second parameter of a version string can be specified and is passed to rubygems.
4
- # If rubygems cannot find the gem it requires the string as a library.
5
-
6
- # Note that this new version tries to load the file via ROOT/gems first before moving off to
7
- # the system gems (so if you have a lower version of a gem in ROOT/gems, it'll still get loaded)
8
-
9
- def dependency(name, *ver)
10
- begin
11
- # If it's not in ROOT/gems, skip to the next attempt
12
- raise LoadError unless File.directory?(Merb.root / "gems")
13
-
14
- # cache the gem path
15
- begin
16
- # Clear out the paths and reset them to Merb
17
- Gem.use_paths(Merb.root / "gems", [Merb.root / "gems"])
18
-
19
- # Try activating the gem (Failure will raise a LoadError)
20
- Gem.activate(name, true, *ver)
21
- Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
22
- ensure
23
- # Either way, set the gem path back to normal
24
- Gem.clear_paths
25
- end
26
-
27
- # If we couldn't load the gem or there was no ROOT/gems, try again, now with the full gem path
28
- rescue LoadError
29
- begin
30
- # Try activating again
31
- Gem.activate(name, true, *ver)
32
- Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")
33
- rescue LoadError
34
- # Failed requiring as a gem, let's try loading with a normal require.
35
- require name
36
- end
37
- end
38
- end
39
-
40
- # Loads both gem and library dependencies that are passed in as arguments.
41
- # Each argument can be:
42
- # String - single dependency
43
- # Hash - name => version
44
- # Array - string dependencies
45
-
46
- def dependencies(*args)
47
- args.each do |arg|
48
- case arg
49
- when String : dependency(arg)
50
- when Hash : arg.each { |r,v| dependency(r, v) }
51
- when Array : arg.each { |r| dependency(r) }
52
- end
53
- end
54
- end
55
-
56
- # Requires the library string passed in.
57
- # If the library fails to load then it will display a helpful message.
58
-
59
- def requires(library)
60
- # TODO: Extract messages out into a messages file. This will also be the first step towards internationalization.
61
- # TODO: adjust this message once logging refactor is complete.
62
- require(library)
63
- message = "#{Time.now.httpdate}: loading library '#{library}' from #{__app_file_trace__.first} ..."
64
- puts(message)
65
- Merb.logger.info(message)
66
- rescue LoadError
67
- # TODO: adjust the two messages below to use merb's logger.error/info once logging refactor is complete.
68
- message = "#{Time.now.httpdate}: <e> Could not find '#{library}' as either a library or gem, loaded from #{__app_file_trace__.first}.\n"
69
- puts(message)
70
- Merb.logger.error(message)
71
-
72
- # Print a helpful message
73
- message = "#{Time.now.httpdate}: <i> Please be sure that if '#{library}': \n"
74
- message << "#{Time.now.httpdate}: <i> * is a normal ruby library (file), be sure that the path of the library it is present in the $LOAD_PATH via $LOAD_PATH.unshift(\"/path/to/#{library}\") \n"
75
- message << "#{Time.now.httpdate}: <i> * is included within a gem, be sure that you are specifying the gem as a dependency \n"
76
- puts(message)
77
- Merb.logger.error(message)
78
- exit() # Missing library/gem must be addressed.
79
- end
80
-
81
- # does a basic require, and prints the message passed as an optional
82
- # second parameter if an error occurs.
83
-
84
- def rescue_require(sym, message = nil)
85
- require sym
86
- rescue LoadError, RuntimeError
87
- puts message if message
88
- end
89
-
90
- # Used in Merb.root/dependencies.yml
91
- # Tells merb which ORM (Object Relational Mapper) you wish to use.
92
- # Currently merb has plugins to support ActiveRecord, DataMapper, and Sequel.
93
- #
94
- # Example
95
- # $ sudo gem install merb_datamapper # or merb_activerecord or merb_sequel
96
- # use_orm :datamapper # this line goes in dependencies.yml
97
- # $ ruby script/generate model MyModel # will use the appropriate generator for your ORM
98
-
99
- def use_orm(orm)
100
- raise "Don't call use_orm more than once" unless
101
- Merb::GENERATOR_SCOPE.delete(:merb_default)
102
- orm = orm.to_sym
103
- orm_plugin = orm.to_s.match(/^merb_/) ? orm.to_s : "merb_#{orm}"
104
- Merb::GENERATOR_SCOPE.unshift(orm) unless
105
- Merb::GENERATOR_SCOPE.include?(orm)
106
- Kernel.dependency(orm_plugin)
107
- end
108
-
109
- # Used in Merb.root/dependencies.yml
110
- # Tells merb which testing framework to use.
111
- # Currently merb supports rspec and test_unit for testing
112
- #
113
- # Example
114
- # $ sudo gem install rspec
115
- # use_test :rspec # this line goes in dependencies.yml (or use_test :test_unit)
116
- # $ ruby script/generate controller MyController # will use the appropriate generator for tests
117
-
118
- def use_test(test_framework)
119
- test_framework = test_framework.to_sym
120
- raise "use_test only supports :rspec and :test_unit currently" unless
121
- [:rspec, :test_unit].include?(test_framework)
122
- Merb::GENERATOR_SCOPE.delete(:rspec)
123
- Merb::GENERATOR_SCOPE.delete(:test_unit)
124
- Merb::GENERATOR_SCOPE.push(test_framework)
125
- end
126
-
127
- # Returns an array with a stack trace of the application's files.
128
-
129
- def __app_file_trace__
130
- caller.select do |call|
131
- call.include?(Merb.root) && !call.include?(Merb.root + "/framework")
132
- end.map do |call|
133
- file, line = call.scan(Regexp.new("#{Merb.root}/(.*):(.*)")).first
134
- "#{file}:#{line}"
135
- end
136
- end
137
-
138
- # Gives you back the file, line and method of the caller number i
139
- #
140
- # Example
141
- # __caller_info__(1) # -> ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']
142
-
143
- def __caller_info__(i = 1)
144
- file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
145
- end
146
-
147
- # Gives you some context around a specific line in a file.
148
- # the size argument works in both directions + the actual line,
149
- # size = 2 gives you 5 lines of source, the returned array has the
150
- # following format.
151
- # [
152
- # line = [
153
- # lineno = Integer,
154
- # line = String,
155
- # is_searched_line = (lineno == initial_lineno)
156
- # ],
157
- # ...,
158
- # ...
159
- # ]
160
- # Example
161
- # __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # ->
162
- # [
163
- # [ 120, " def check_suspend", false ],
164
- # [ 121, " return if Thread.critical", false ],
165
- # [ 122, " while (Thread.critical = true; @suspend_next)", true ],
166
- # [ 123, " DEBUGGER__.waiting.push Thread.current", false ],
167
- # [ 124, " @suspend_next = false", false ]
168
- # ]
169
-
170
- def __caller_lines__(file, line, size = 4)
171
- return [['Template Error!', "problem while rendering", false]] if file =~ /\(erubis\)/
172
- lines = File.readlines(file)
173
- current = line.to_i - 1
174
-
175
- first = current - size
176
- first = first < 0 ? 0 : first
177
-
178
- last = current + size
179
- last = last > lines.size ? lines.size : last
180
-
181
- log = lines[first..last]
182
-
183
- area = []
184
-
185
- log.each_with_index do |line, index|
186
- index = index + first + 1
187
- area << [index, line.chomp, index == current + 1]
188
- end
189
-
190
- area
191
- end
192
-
193
- # Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)
194
- # Takes a block and profiles the results of running the block 100 times.
195
- # The resulting profile is written out to Merb.root/log/#{name}.html.
196
- # <tt>min</tt> specifies the minimum percentage of the total time a method must take for it to be included in the result.
197
- #
198
- # Example
199
- # __profile__("MyProfile", 5) do
200
- # 30.times { rand(10)**rand(10) }
201
- # puts "Profile run"
202
- # end
203
- # Assuming that the total time taken for #puts calls was less than 5% of the total time to run, #puts won't appear
204
- # in the profilel report.
205
-
206
- def __profile__(name, min=1)
207
- require 'ruby-prof' unless defined?(RubyProf)
208
- return_result = ''
209
- result = RubyProf.profile do
210
- 100.times{return_result = yield}
211
- end
212
- printer = RubyProf::GraphHtmlPrinter.new(result)
213
- path = File.join(Merb.root, 'log', "#{name}.html")
214
- File.open(path, 'w') do |file|
215
- printer.print(file, {:min_percent => min,
216
- :print_file => true})
217
- end
218
- return_result
219
- end
220
-
221
- # Extracts an options hash if it is the last item in the args array
222
- # Used internally in methods that take *args
223
- #
224
- # Example
225
- # def render(*args,&blk)
226
- # opts = extract_options_from_args!(args) || {}
227
-
228
- def extract_options_from_args!(args)
229
- args.pop if Hash === args.last
230
- end
231
-
232
- unless Kernel.respond_to?(:debugger)
233
- # define debugger method so that code even works if debugger was not
234
- # requested
235
- # Drops a not to the logs that Debugger was not available
236
- def debugger
237
- Merb.logger.info "\n***** Debugger requested, but was not " +
238
- "available: Start server with --debugger " +
239
- "to enable *****\n"
240
- end
241
- end
242
- end