thorero-core 0.9.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +352 -0
- data/TODO +0 -0
- data/bin/merb +12 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +58 -0
- data/docs/documentation_standards +40 -0
- data/docs/merb-core-call-stack-diagram.mmap +0 -0
- data/docs/merb-core-call-stack-diagram.pdf +0 -0
- data/docs/merb-core-call-stack-diagram.png +0 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +603 -0
- data/lib/merb-core/autoload.rb +32 -0
- data/lib/merb-core/bootloader.rb +708 -0
- data/lib/merb-core/config.rb +303 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +578 -0
- data/lib/merb-core/controller/exceptions.rb +302 -0
- data/lib/merb-core/controller/merb_controller.rb +256 -0
- data/lib/merb-core/controller/mime.rb +106 -0
- data/lib/merb-core/controller/mixins/authentication.rb +87 -0
- data/lib/merb-core/controller/mixins/controller.rb +290 -0
- data/lib/merb-core/controller/mixins/render.rb +481 -0
- data/lib/merb-core/controller/mixins/responder.rb +472 -0
- data/lib/merb-core/controller/template.rb +254 -0
- data/lib/merb-core/core_ext.rb +8 -0
- data/lib/merb-core/core_ext/kernel.rb +319 -0
- data/lib/merb-core/dispatch/cookies.rb +91 -0
- data/lib/merb-core/dispatch/dispatcher.rb +278 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +303 -0
- data/lib/merb-core/dispatch/request.rb +603 -0
- data/lib/merb-core/dispatch/router.rb +179 -0
- data/lib/merb-core/dispatch/router/behavior.rb +867 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +321 -0
- data/lib/merb-core/dispatch/session.rb +78 -0
- data/lib/merb-core/dispatch/session/cookie.rb +168 -0
- data/lib/merb-core/dispatch/session/memcached.rb +184 -0
- data/lib/merb-core/dispatch/session/memory.rb +241 -0
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +77 -0
- data/lib/merb-core/logger.rb +202 -0
- data/lib/merb-core/plugins.rb +59 -0
- data/lib/merb-core/rack.rb +21 -0
- data/lib/merb-core/rack/adapter.rb +44 -0
- data/lib/merb-core/rack/adapter/ebb.rb +25 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
- data/lib/merb-core/rack/adapter/irb.rb +118 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/runner.rb +28 -0
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +39 -0
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/adapter/webrick.rb +36 -0
- data/lib/merb-core/rack/application.rb +18 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/rack/middleware.rb +26 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
- data/lib/merb-core/rack/middleware/profiler.rb +19 -0
- data/lib/merb-core/rack/middleware/static.rb +45 -0
- data/lib/merb-core/server.rb +252 -0
- data/lib/merb-core/tasks/audit.rake +68 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
- data/lib/merb-core/test.rb +11 -0
- data/lib/merb-core/test/helpers.rb +9 -0
- data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
- data/lib/merb-core/test/helpers/request_helper.rb +344 -0
- data/lib/merb-core/test/helpers/route_helper.rb +33 -0
- data/lib/merb-core/test/helpers/view_helper.rb +121 -0
- data/lib/merb-core/test/matchers.rb +9 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +319 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +335 -0
- data/lib/merb-core/test/run_specs.rb +47 -0
- data/lib/merb-core/test/tasks/spectasks.rb +68 -0
- data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
- data/lib/merb-core/test/test_ext/object.rb +14 -0
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +345 -0
- data/lib/merb-core/version.rb +11 -0
- data/spec/private/config/adapter_spec.rb +32 -0
- data/spec/private/config/config_spec.rb +202 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/kernel_spec.rb +169 -0
- data/spec/private/dispatch/bootloader_spec.rb +24 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +35 -0
- data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
- data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
- data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
- data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
- data/spec/private/dispatch/fixture/config/init.rb +45 -0
- data/spec/private/dispatch/fixture/config/rack.rb +11 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +1874 -0
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
- data/spec/private/dispatch/route_params_spec.rb +24 -0
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/dispatch/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +166 -0
- data/spec/private/rack/application_spec.rb +49 -0
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +139 -0
- data/spec/private/router/route_spec.rb +414 -0
- data/spec/private/router/router_spec.rb +175 -0
- data/spec/private/vendor/facets/plural_spec.rb +564 -0
- data/spec/private/vendor/facets/singular_spec.rb +489 -0
- data/spec/public/DEFINITIONS +11 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +193 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +41 -0
- data/spec/public/abstract_controller/controllers/partial.rb +121 -0
- data/spec/public/abstract_controller/controllers/render.rb +113 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
- data/spec/public/abstract_controller/display_spec.rb +33 -0
- data/spec/public/abstract_controller/filter_spec.rb +106 -0
- data/spec/public/abstract_controller/helper_spec.rb +21 -0
- data/spec/public/abstract_controller/partial_spec.rb +61 -0
- data/spec/public/abstract_controller/render_spec.rb +90 -0
- data/spec/public/abstract_controller/spec_helper.rb +31 -0
- data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
- data/spec/public/boot_loader/spec_helper.rb +1 -0
- data/spec/public/controller/authentication_spec.rb +103 -0
- data/spec/public/controller/base_spec.rb +36 -0
- data/spec/public/controller/controllers/authentication.rb +45 -0
- data/spec/public/controller/controllers/base.rb +36 -0
- data/spec/public/controller/controllers/display.rb +118 -0
- data/spec/public/controller/controllers/redirect.rb +30 -0
- data/spec/public/controller/controllers/responder.rb +93 -0
- data/spec/public/controller/controllers/url.rb +7 -0
- data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
- data/spec/public/controller/display_spec.rb +84 -0
- data/spec/public/controller/redirect_spec.rb +27 -0
- data/spec/public/controller/responder_spec.rb +163 -0
- data/spec/public/controller/spec_helper.rb +11 -0
- data/spec/public/controller/url_spec.rb +180 -0
- data/spec/public/core/merb_core_spec.rb +45 -0
- data/spec/public/core_ext/class_spec.rb +91 -0
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
- data/spec/public/core_ext/kernel_spec.rb +9 -0
- data/spec/public/core_ext/spec_helper.rb +1 -0
- data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
- data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
- data/spec/public/directory_structure/directory/config/router.rb +3 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +562 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +181 -0
- data/spec/public/logger/spec_helper.rb +1 -0
- data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
- data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
- data/spec/public/reloading/directory/config/init.rb +2 -0
- data/spec/public/reloading/directory/log/merb_test.log +138 -0
- data/spec/public/reloading/reload_spec.rb +103 -0
- data/spec/public/request/multipart_spec.rb +41 -0
- data/spec/public/request/request_spec.rb +228 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +1556 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/nested_resources_spec.rb +41 -0
- data/spec/public/router/resource_spec.rb +37 -0
- data/spec/public/router/resources_spec.rb +82 -0
- data/spec/public/router/spec_helper.rb +90 -0
- data/spec/public/router/special_spec.rb +61 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +104 -0
- data/spec/public/template/templates/error.html.erb +2 -0
- data/spec/public/template/templates/template.html.erb +1 -0
- data/spec/public/template/templates/template.html.myt +1 -0
- data/spec/public/test/controller_matchers_spec.rb +402 -0
- data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
- data/spec/public/test/controllers/dispatch_controller.rb +11 -0
- data/spec/public/test/controllers/spec_helper_controller.rb +38 -0
- data/spec/public/test/multipart_request_helper_spec.rb +159 -0
- data/spec/public/test/multipart_upload_text_file.txt +1 -0
- data/spec/public/test/request_helper_spec.rb +221 -0
- data/spec/public/test/route_helper_spec.rb +71 -0
- data/spec/public/test/route_matchers_spec.rb +162 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +183 -0
- data/spec/spec_helper.rb +68 -0
- metadata +542 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
module Language
|
2
|
+
|
3
|
+
module English
|
4
|
+
|
5
|
+
# = English Nouns Number Inflection.
|
6
|
+
#
|
7
|
+
# This module provides english singular <-> plural noun inflections.
|
8
|
+
module Inflect
|
9
|
+
|
10
|
+
@singular_of = {}
|
11
|
+
@plural_of = {}
|
12
|
+
|
13
|
+
@singular_rules = []
|
14
|
+
@plural_rules = []
|
15
|
+
|
16
|
+
class << self
|
17
|
+
# Defines a general inflection exception case.
|
18
|
+
#
|
19
|
+
# ==== Parameters
|
20
|
+
# singular<String>::
|
21
|
+
# singular form of the word
|
22
|
+
# plural<String>::
|
23
|
+
# plural form of the word
|
24
|
+
#
|
25
|
+
# ==== Examples
|
26
|
+
#
|
27
|
+
# Here we define erratum/errata exception case:
|
28
|
+
#
|
29
|
+
# Language::English::Inflector.word "erratum", "errata"
|
30
|
+
#
|
31
|
+
# In case singular and plural forms are the same omit
|
32
|
+
# second argument on call:
|
33
|
+
#
|
34
|
+
# Language::English::Inflector.word 'information'
|
35
|
+
def word(singular, plural=nil)
|
36
|
+
plural = singular unless plural
|
37
|
+
singular_word(singular, plural)
|
38
|
+
plural_word(singular, plural)
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear(type = :all)
|
42
|
+
if type == :singular || type == :all
|
43
|
+
@singular_of = {}
|
44
|
+
@singular_rules = []
|
45
|
+
@singularization_rules, @singularization_regex = nil, nil
|
46
|
+
end
|
47
|
+
if type == :plural || type == :all
|
48
|
+
@singular_of = {}
|
49
|
+
@singular_rules = []
|
50
|
+
@singularization_rules, @singularization_regex = nil, nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Define a singularization exception.
|
56
|
+
#
|
57
|
+
# ==== Parameters
|
58
|
+
# singular<String>::
|
59
|
+
# singular form of the word
|
60
|
+
# plural<String>::
|
61
|
+
# plural form of the word
|
62
|
+
def singular_word(singular, plural)
|
63
|
+
@singular_of[plural] = singular
|
64
|
+
@singular_of[plural.capitalize] = singular.capitalize
|
65
|
+
end
|
66
|
+
|
67
|
+
# Define a pluralization exception.
|
68
|
+
#
|
69
|
+
# ==== Parameters
|
70
|
+
# singular<String>::
|
71
|
+
# singular form of the word
|
72
|
+
# plural<String>::
|
73
|
+
# plural form of the word
|
74
|
+
def plural_word(singular, plural)
|
75
|
+
@plural_of[singular] = plural
|
76
|
+
@plural_of[singular.capitalize] = plural.capitalize
|
77
|
+
end
|
78
|
+
|
79
|
+
# Define a general rule.
|
80
|
+
#
|
81
|
+
# ==== Parameters
|
82
|
+
# singular<String>::
|
83
|
+
# ending of the word in singular form
|
84
|
+
# plural<String>::
|
85
|
+
# ending of the word in plural form
|
86
|
+
# whole_word<Boolean>::
|
87
|
+
# for capitalization, since words can be
|
88
|
+
# capitalized (Man => Men) #
|
89
|
+
# ==== Examples
|
90
|
+
# Once the following rule is defined:
|
91
|
+
# Language::English::Inflector.rule 'y', 'ies'
|
92
|
+
#
|
93
|
+
# You can see the following results:
|
94
|
+
# irb> "fly".plural
|
95
|
+
# => flies
|
96
|
+
# irb> "cry".plural
|
97
|
+
# => cries
|
98
|
+
# Define a general rule.
|
99
|
+
|
100
|
+
def rule(singular, plural, whole_word = false)
|
101
|
+
singular_rule(singular, plural)
|
102
|
+
plural_rule(singular, plural)
|
103
|
+
word(singular, plural) if whole_word
|
104
|
+
end
|
105
|
+
|
106
|
+
# Define a singularization rule.
|
107
|
+
#
|
108
|
+
# ==== Parameters
|
109
|
+
# singular<String>::
|
110
|
+
# ending of the word in singular form
|
111
|
+
# plural<String>::
|
112
|
+
# ending of the word in plural form
|
113
|
+
#
|
114
|
+
# ==== Examples
|
115
|
+
# Once the following rule is defined:
|
116
|
+
# Language::English::Inflector.singular_rule 'o', 'oes'
|
117
|
+
#
|
118
|
+
# You can see the following results:
|
119
|
+
# irb> "heroes".singular
|
120
|
+
# => hero
|
121
|
+
def singular_rule(singular, plural)
|
122
|
+
@singular_rules << [singular, plural]
|
123
|
+
end
|
124
|
+
|
125
|
+
# Define a plurualization rule.
|
126
|
+
#
|
127
|
+
# ==== Parameters
|
128
|
+
# singular<String>::
|
129
|
+
# ending of the word in singular form
|
130
|
+
# plural<String>::
|
131
|
+
# ending of the word in plural form
|
132
|
+
#
|
133
|
+
# ==== Examples
|
134
|
+
# Once the following rule is defined:
|
135
|
+
# Language::English::Inflector.singular_rule 'fe', 'ves'
|
136
|
+
#
|
137
|
+
# You can see the following results:
|
138
|
+
# irb> "wife".plural
|
139
|
+
# => wives
|
140
|
+
def plural_rule(singular, plural)
|
141
|
+
@plural_rules << [singular, plural]
|
142
|
+
end
|
143
|
+
|
144
|
+
# Read prepared singularization rules.
|
145
|
+
def singularization_rules
|
146
|
+
if defined?(@singularization_regex) && @singularization_regex
|
147
|
+
return [@singularization_regex, @singularization_hash]
|
148
|
+
end
|
149
|
+
# No sorting needed: Regexen match on longest string
|
150
|
+
@singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i")
|
151
|
+
@singularization_hash = Hash[*@singular_rules.flatten].invert
|
152
|
+
[@singularization_regex, @singularization_hash]
|
153
|
+
end
|
154
|
+
|
155
|
+
# Read prepared pluralization rules.
|
156
|
+
def pluralization_rules
|
157
|
+
if defined?(@pluralization_regex) && @pluralization_regex
|
158
|
+
return [@pluralization_regex, @pluralization_hash]
|
159
|
+
end
|
160
|
+
@pluralization_regex = Regexp.new("(" + @plural_rules.map {|s,p| s}.join("|") + ")$", "i")
|
161
|
+
@pluralization_hash = Hash[*@plural_rules.flatten]
|
162
|
+
[@pluralization_regex, @pluralization_hash]
|
163
|
+
end
|
164
|
+
|
165
|
+
attr_reader :singular_of, :plural_of
|
166
|
+
|
167
|
+
# Convert an English word from plurel to singular.
|
168
|
+
#
|
169
|
+
# "boys".singular #=> boy
|
170
|
+
# "tomatoes".singular #=> tomato
|
171
|
+
#
|
172
|
+
# ==== Parameters
|
173
|
+
# word<String>:: word to singularize
|
174
|
+
#
|
175
|
+
# ==== Returns
|
176
|
+
# <String>:: singularized form of word
|
177
|
+
#
|
178
|
+
# ==== Notes
|
179
|
+
# Aliased as singularize (a Railism)
|
180
|
+
def singular(word)
|
181
|
+
if result = singular_of[word]
|
182
|
+
return result.dup
|
183
|
+
end
|
184
|
+
result = word.dup
|
185
|
+
regex, hash = singularization_rules
|
186
|
+
result.sub!(regex) {|m| hash[m]}
|
187
|
+
singular_of[word] = result
|
188
|
+
return result
|
189
|
+
end
|
190
|
+
|
191
|
+
# Alias for #singular (a Railism).
|
192
|
+
#
|
193
|
+
alias_method(:singularize, :singular)
|
194
|
+
|
195
|
+
# Convert an English word from singular to plurel.
|
196
|
+
#
|
197
|
+
# "boy".plural #=> boys
|
198
|
+
# "tomato".plural #=> tomatoes
|
199
|
+
#
|
200
|
+
# ==== Parameters
|
201
|
+
# word<String>:: word to pluralize
|
202
|
+
#
|
203
|
+
# ==== Returns
|
204
|
+
# <String>:: pluralized form of word
|
205
|
+
#
|
206
|
+
# ==== Notes
|
207
|
+
# Aliased as pluralize (a Railism)
|
208
|
+
def plural(word)
|
209
|
+
# special exceptions
|
210
|
+
return "" if word == ""
|
211
|
+
if result = plural_of[word]
|
212
|
+
return result.dup
|
213
|
+
end
|
214
|
+
result = word.dup
|
215
|
+
regex, hash = pluralization_rules
|
216
|
+
result.sub!(regex) {|m| hash[m]}
|
217
|
+
plural_of[word] = result
|
218
|
+
return result
|
219
|
+
end
|
220
|
+
|
221
|
+
# Alias for #plural (a Railism).
|
222
|
+
alias_method(:pluralize, :plural)
|
223
|
+
end
|
224
|
+
|
225
|
+
# One argument means singular and plural are the same.
|
226
|
+
|
227
|
+
word 'equipment'
|
228
|
+
word 'information'
|
229
|
+
word 'money'
|
230
|
+
word 'species'
|
231
|
+
word 'series'
|
232
|
+
word 'fish'
|
233
|
+
word 'sheep'
|
234
|
+
word 'moose'
|
235
|
+
word 'hovercraft'
|
236
|
+
word 'grass'
|
237
|
+
word 'rain'
|
238
|
+
word 'milk'
|
239
|
+
word 'rice'
|
240
|
+
word 'plurals'
|
241
|
+
|
242
|
+
# Two arguments defines a singular and plural exception.
|
243
|
+
|
244
|
+
word 'Swiss' , 'Swiss'
|
245
|
+
word 'life' , 'lives'
|
246
|
+
word 'wife' , 'wives'
|
247
|
+
word 'goose' , 'geese'
|
248
|
+
word 'criterion' , 'criteria'
|
249
|
+
word 'alias' , 'aliases'
|
250
|
+
word 'status' , 'statuses'
|
251
|
+
word 'axis' , 'axes'
|
252
|
+
word 'crisis' , 'crises'
|
253
|
+
word 'testis' , 'testes'
|
254
|
+
word 'potato' , 'potatoes'
|
255
|
+
word 'tomato' , 'tomatoes'
|
256
|
+
word 'buffalo' , 'buffaloes'
|
257
|
+
word 'torpedo' , 'torpedoes'
|
258
|
+
word 'quiz' , 'quizzes'
|
259
|
+
word 'matrix' , 'matrices'
|
260
|
+
word 'vertex' , 'vertices'
|
261
|
+
word 'index' , 'indices'
|
262
|
+
word 'ox' , 'oxen'
|
263
|
+
word 'mouse' , 'mice'
|
264
|
+
word 'louse' , 'lice'
|
265
|
+
word 'thesis' , 'theses'
|
266
|
+
word 'thief' , 'thieves'
|
267
|
+
word 'analysis' , 'analyses'
|
268
|
+
word 'erratum' , 'errata'
|
269
|
+
word 'phenomenon', 'phenomena'
|
270
|
+
word 'octopus' , 'octopi'
|
271
|
+
word 'thesaurus' , 'thesauri'
|
272
|
+
word 'movie' , 'movies'
|
273
|
+
word 'cactus' , 'cacti'
|
274
|
+
word 'plus' , 'plusses'
|
275
|
+
word 'cross' , 'crosses'
|
276
|
+
word 'medium' , 'media'
|
277
|
+
word 'cow' , 'kine'
|
278
|
+
word 'datum' , 'data'
|
279
|
+
word 'basis' , 'bases'
|
280
|
+
word 'diagnosis' , 'diagnoses'
|
281
|
+
|
282
|
+
# One-way singularization exception (convert plural to singular).
|
283
|
+
|
284
|
+
# General rules.
|
285
|
+
rule 'person' , 'people', true
|
286
|
+
rule 'shoe' , 'shoes', true
|
287
|
+
rule 'hive' , 'hives', true
|
288
|
+
rule 'man' , 'men', true
|
289
|
+
rule 'child' , 'children', true
|
290
|
+
rule 'news' , 'news', true
|
291
|
+
rule 'rf' , 'rves'
|
292
|
+
rule 'af' , 'aves'
|
293
|
+
rule 'ero' , 'eroes'
|
294
|
+
rule 'man' , 'men'
|
295
|
+
rule 'ch' , 'ches'
|
296
|
+
rule 'sh' , 'shes'
|
297
|
+
rule 'ss' , 'sses'
|
298
|
+
rule 'ta' , 'tum'
|
299
|
+
rule 'ia' , 'ium'
|
300
|
+
rule 'ra' , 'rum'
|
301
|
+
rule 'ay' , 'ays'
|
302
|
+
rule 'ey' , 'eys'
|
303
|
+
rule 'oy' , 'oys'
|
304
|
+
rule 'uy' , 'uys'
|
305
|
+
rule 'y' , 'ies'
|
306
|
+
rule 'x' , 'xes'
|
307
|
+
rule 'lf' , 'lves'
|
308
|
+
rule 'ffe' , 'ffes'
|
309
|
+
rule 'afe' , 'aves'
|
310
|
+
rule 'ouse' , 'ouses'
|
311
|
+
# more cases of words ending in -oses not being singularized properly
|
312
|
+
# than cases of words ending in -osis
|
313
|
+
# rule 'osis' , 'oses'
|
314
|
+
rule 'ox' , 'oxes'
|
315
|
+
rule 'us' , 'uses'
|
316
|
+
rule '' , 's'
|
317
|
+
|
318
|
+
# One-way singular rules.
|
319
|
+
|
320
|
+
singular_rule 'of' , 'ofs' # proof
|
321
|
+
singular_rule 'o' , 'oes' # hero, heroes
|
322
|
+
singular_rule 'f' , 'ves'
|
323
|
+
|
324
|
+
# One-way plural rules.
|
325
|
+
|
326
|
+
#plural_rule 'fe' , 'ves' # safe, wife
|
327
|
+
plural_rule 's' , 'ses'
|
328
|
+
plural_rule 'ive' , 'ives' # don't want to snag wife
|
329
|
+
plural_rule 'fe' , 'ves' # don't want to snag perspectives
|
330
|
+
|
331
|
+
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
class String
|
337
|
+
def singular
|
338
|
+
Language::English::Inflect.singular(self)
|
339
|
+
end
|
340
|
+
alias_method(:singularize, :singular)
|
341
|
+
def plural
|
342
|
+
Language::English::Inflect.plural(self)
|
343
|
+
end
|
344
|
+
alias_method(:pluralize, :plural)
|
345
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Merb
|
2
|
+
VERSION = '0.9.4' unless defined?(Merb::VERSION)
|
3
|
+
|
4
|
+
# Merb::RELEASE meanings:
|
5
|
+
# 'dev' : unreleased
|
6
|
+
# 'pre' : pre-release Gem candidates
|
7
|
+
# nil : released
|
8
|
+
# You should never check in to trunk with this changed. It should
|
9
|
+
# stay 'dev'. Change it to nil in release tags.
|
10
|
+
RELEASE = 'dev' unless defined?(Merb::RELEASE)
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
MERB_BIN = File.dirname(__FILE__) + "/../../../bin/merb"
|
4
|
+
|
5
|
+
describe Merb::Config do
|
6
|
+
before do
|
7
|
+
ARGV.replace([])
|
8
|
+
Merb::Server.should_receive(:start).and_return(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should load the runner adapter by default" do
|
12
|
+
Merb.start
|
13
|
+
Merb::Config[:adapter].should == "runner"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should load mongrel adapter when running `merb`" do
|
17
|
+
load(MERB_BIN)
|
18
|
+
Merb::Config[:adapter].should == "mongrel"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should override adapter when running `merb -a other`" do
|
22
|
+
ARGV.push *%w[-a other]
|
23
|
+
load(MERB_BIN)
|
24
|
+
Merb::Config[:adapter].should == "other"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should load irb adapter when running `merb -i`" do
|
28
|
+
ARGV << '-i'
|
29
|
+
load(MERB_BIN)
|
30
|
+
Merb::Config[:adapter].should == "irb"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Config do
|
4
|
+
before do
|
5
|
+
Merb::Config.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be able to yield the configuration via #use" do
|
9
|
+
res = nil
|
10
|
+
Merb::Config.use {|c| res = c}
|
11
|
+
res.should == Merb::Config.defaults
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to get a configuration key" do
|
15
|
+
Merb::Config[:host].should == "0.0.0.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to set a configuration key" do
|
19
|
+
Merb::Config[:bar] = "Hello"
|
20
|
+
Merb::Config[:bar].should == "Hello"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be able to #delete a configuration key" do
|
24
|
+
Merb::Config[:bar] = "Hello"
|
25
|
+
Merb::Config[:bar].should == "Hello"
|
26
|
+
Merb::Config.delete(:bar)
|
27
|
+
Merb::Config[:bar].should == nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to #fetch a key that does exist" do
|
31
|
+
Merb::Config.fetch(:host, "192.168.2.1").should == "0.0.0.0"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to #fetch a key that does exist" do
|
35
|
+
Merb::Config.fetch(:bar, "heylo").should == "heylo"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to dump to YAML" do
|
39
|
+
Merb::Config.to_yaml.should == Merb::Config.instance_variable_get("@configuration").to_yaml
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should support -u to set the user to run Merb as" do
|
43
|
+
Merb::Config.parse_args(["-u", "tester"])
|
44
|
+
Merb::Config[:user].should == "tester"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should support -G to set the group to run Merb as" do
|
48
|
+
Merb::Config.parse_args(["-G", "tester"])
|
49
|
+
Merb::Config[:group].should == "tester"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should support -d to daemonize Merb" do
|
53
|
+
Merb::Config.parse_args(["-d"])
|
54
|
+
Merb::Config[:daemonize].should == true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should support -c to set the number of cluster nodes" do
|
58
|
+
Merb::Config.parse_args(["-c", "4"])
|
59
|
+
Merb::Config[:cluster].should == "4"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should support -p to set the port number" do
|
63
|
+
Merb::Config.parse_args(["-p", "6000"])
|
64
|
+
Merb::Config[:port].should == "6000"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should support -o to set the socket filename" do
|
68
|
+
Merb::Config.parse_args(["-o", "merb.2.sock"])
|
69
|
+
Merb::Config[:socket_file].should == "merb.2.sock"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should support --socket-file to set the socket filename" do
|
73
|
+
Merb::Config.parse_args(["--socket-file", "app.thin.0.sock"])
|
74
|
+
Merb::Config[:socket_file].should == "app.thin.0.sock" # 0 is default socket #
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should support -s to set the socket number" do
|
78
|
+
Merb::Config.parse_args(["-s", "0"])
|
79
|
+
Merb::Config[:socket].should == "0"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should support --socket to set the socket number" do
|
83
|
+
Merb::Config.parse_args(["--socket", "3"])
|
84
|
+
Merb::Config[:socket].should == "3"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should support -P to set the PIDfile" do
|
88
|
+
Merb::Config.parse_args(["-P", "pidfile"])
|
89
|
+
Merb::Config[:pid_file].should == "pidfile"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should have server return PIDfile setting as is with no cluster nodes" do
|
93
|
+
Merb::Config.parse_args(["-P", "pidfile", "-p", "6000"])
|
94
|
+
Merb::Server.pid_file(6000).should == "pidfile"
|
95
|
+
Merb::Server.pid_files.should == ["pidfile"]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should support setting of PIDfile with cluster nodes" do
|
99
|
+
Merb::Config.parse_args(["-P", "/tmp/merb.pidfile", "-c", "2", "-p", "6000"])
|
100
|
+
Merb::Server.pid_file(6000).should == "/tmp/merb.6000.pidfile"
|
101
|
+
Merb::Server.pid_file(6001).should == "/tmp/merb.6001.pidfile"
|
102
|
+
|
103
|
+
Dir.should_receive(:[]).with("/tmp/merb.*.pidfile")
|
104
|
+
Merb::Server.pid_files
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should support default PIDfile setting" do
|
108
|
+
Merb::Config.parse_args(["-p", "6000"])
|
109
|
+
Merb::Server.pid_file(6000).should == Merb.log_path / "merb.6000.pid"
|
110
|
+
|
111
|
+
Dir.should_receive(:[]).with(Merb.log_path / "merb.*.pid")
|
112
|
+
Merb::Server.pid_files
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should support -h to set the hostname" do
|
116
|
+
Merb::Config.parse_args(["-h", "hostname"])
|
117
|
+
Merb::Config[:host].should == "hostname"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should support -i to specify loading IRB" do
|
121
|
+
Merb::Config.parse_args(["-i"])
|
122
|
+
Merb::Config[:adapter].should == "irb"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should support -l to specify the log level" do
|
126
|
+
Merb::Config.parse_args(["-l", "debug"])
|
127
|
+
Merb::Config[:log_level].should == :debug
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should support -L to specify the location of the log file" do
|
131
|
+
Merb::Config.parse_args(["-L", "log_file"])
|
132
|
+
Merb::Config[:log_file].should == "log_file"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should support -r to specify a runner" do
|
136
|
+
Merb::Config.parse_args(["-r", "foo_runner"])
|
137
|
+
Merb::Config[:runner_code].should == "foo_runner"
|
138
|
+
Merb::Config[:adapter].should == "runner"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should support -R to specify a rackup file" do
|
142
|
+
Merb::Config.parse_args(["-R", "config.ru"])
|
143
|
+
Merb::Config[:rackup].should == "config.ru"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should support -K for a graceful kill" do
|
147
|
+
Merb::Server.should_receive(:kill).with("all", 1)
|
148
|
+
Merb.start(["-K", "all"])
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should support -k for a hard kill" do
|
152
|
+
Merb::Server.should_receive(:kill).with("all", 9)
|
153
|
+
Merb.start(["-k", "all"])
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should support -X off to turn off the mutex" do
|
157
|
+
Merb::Config.parse_args(["-X", "off"])
|
158
|
+
Merb::Config[:use_mutex].should == false
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should support -X on to turn off the mutex" do
|
162
|
+
Merb::Config.parse_args(["-X", "on"])
|
163
|
+
Merb::Config[:use_mutex].should == true
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should take Merb.disable into account" do
|
167
|
+
Merb::Config[:disabled_components].should == []
|
168
|
+
Merb::Config[:disabled_components] << :foo
|
169
|
+
Merb.disable(:bar)
|
170
|
+
Merb.disable(:buz, :fux)
|
171
|
+
Merb::Config[:disabled_components].should == [:foo, :bar, :buz, :fux]
|
172
|
+
Merb.disabled?(:foo).should == true
|
173
|
+
Merb.disabled?(:foo, :buz).should == true
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should take Merb.testing? into account" do
|
177
|
+
$TESTING.should == true
|
178
|
+
Merb::Config[:testing].should be_nil
|
179
|
+
Merb.should be_testing
|
180
|
+
$TESTING = false
|
181
|
+
Merb.should_not be_testing
|
182
|
+
Merb::Config[:testing] = true
|
183
|
+
Merb.should be_testing
|
184
|
+
$TESTING = true; Merb::Config[:testing] = false # reset
|
185
|
+
end
|
186
|
+
|
187
|
+
it "supports -V to turn on verbose mode" do
|
188
|
+
Merb::Config[:verbose] = false
|
189
|
+
Merb::Config.parse_args(["-V"])
|
190
|
+
Merb::Config[:verbose].should be(true)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "supports --verbose to turn on verbose mode" do
|
194
|
+
Merb::Config[:verbose] = false
|
195
|
+
Merb::Config.parse_args(["--verbose"])
|
196
|
+
Merb::Config[:verbose].should be(true)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "has verbose mode turned off by default" do
|
200
|
+
Merb::Config[:verbose].should be(false)
|
201
|
+
end
|
202
|
+
end
|