merb 0.5.3 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +0 -20
- data/README +0 -277
- data/Rakefile +80 -199
- data/TODO +0 -3
- metadata +19 -438
- data/SVN_REVISION +0 -1
- data/app_generators/merb/USAGE +0 -5
- data/app_generators/merb/merb_generator.rb +0 -108
- data/app_generators/merb/templates/Rakefile +0 -124
- data/app_generators/merb/templates/app/controllers/application.rb +0 -3
- data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
- data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
- data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
- data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
- data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
- data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
- data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
- data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
- data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
- data/app_generators/merb/templates/config/boot.rb +0 -11
- data/app_generators/merb/templates/config/dependencies.rb +0 -41
- data/app_generators/merb/templates/config/environments/development.rb +0 -1
- data/app_generators/merb/templates/config/environments/production.rb +0 -1
- data/app_generators/merb/templates/config/environments/test.rb +0 -1
- data/app_generators/merb/templates/config/merb.yml +0 -82
- data/app_generators/merb/templates/config/merb_init.rb +0 -17
- data/app_generators/merb/templates/config/plugins.yml +0 -1
- data/app_generators/merb/templates/config/router.rb +0 -35
- data/app_generators/merb/templates/config/upload.conf +0 -0
- data/app_generators/merb/templates/public/images/merb.jpg +0 -0
- data/app_generators/merb/templates/public/merb.fcgi +0 -6
- data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
- data/app_generators/merb/templates/script/destroy +0 -32
- data/app_generators/merb/templates/script/generate +0 -32
- data/app_generators/merb/templates/script/stop_merb +0 -13
- data/app_generators/merb/templates/script/win_script.cmd +0 -1
- data/app_generators/merb/templates/spec/spec.opts +0 -6
- data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
- data/app_generators/merb/templates/test/test_helper.rb +0 -14
- data/app_generators/merb_plugin/USAGE +0 -5
- data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
- data/app_generators/merb_plugin/templates/LICENSE +0 -20
- data/app_generators/merb_plugin/templates/README +0 -4
- data/app_generators/merb_plugin/templates/Rakefile +0 -35
- data/app_generators/merb_plugin/templates/TODO +0 -5
- data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
- data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
- data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
- data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
- data/bin/merb +0 -4
- data/lib/autotest/discover.rb +0 -3
- data/lib/autotest/merb_rspec.rb +0 -80
- data/lib/merb.rb +0 -188
- data/lib/merb/abstract_controller.rb +0 -399
- data/lib/merb/assets.rb +0 -160
- data/lib/merb/assets.rb.orig +0 -119
- data/lib/merb/boot_loader.rb +0 -286
- data/lib/merb/boot_loader.rb.orig +0 -235
- data/lib/merb/caching.rb +0 -5
- data/lib/merb/caching/action_cache.rb +0 -92
- data/lib/merb/caching/fragment_cache.rb +0 -39
- data/lib/merb/caching/store/file_cache.rb +0 -90
- data/lib/merb/caching/store/memory_cache.rb +0 -85
- data/lib/merb/config.rb +0 -290
- data/lib/merb/constants.rb +0 -50
- data/lib/merb/controller.rb +0 -220
- data/lib/merb/cookies.rb +0 -95
- data/lib/merb/core_ext.rb +0 -15
- data/lib/merb/core_ext/array.rb +0 -0
- data/lib/merb/core_ext/class.rb +0 -180
- data/lib/merb/core_ext/enumerable.rb +0 -49
- data/lib/merb/core_ext/get_args.rb +0 -76
- data/lib/merb/core_ext/hash.rb +0 -306
- data/lib/merb/core_ext/inflections.rb +0 -112
- data/lib/merb/core_ext/inflector.rb +0 -275
- data/lib/merb/core_ext/kernel.rb +0 -242
- data/lib/merb/core_ext/mash.rb +0 -88
- data/lib/merb/core_ext/module.rb +0 -67
- data/lib/merb/core_ext/numeric.rb +0 -72
- data/lib/merb/core_ext/object.rb +0 -183
- data/lib/merb/core_ext/string.rb +0 -53
- data/lib/merb/core_ext/symbol.rb +0 -6
- data/lib/merb/dispatcher.rb +0 -109
- data/lib/merb/drb_server.rb +0 -19
- data/lib/merb/erubis_ext.rb +0 -10
- data/lib/merb/exceptions.rb +0 -192
- data/lib/merb/generators/merb_app/merb_app.rb +0 -22
- data/lib/merb/generators/merb_generator_helpers.rb +0 -318
- data/lib/merb/generators/merb_plugin.rb +0 -22
- data/lib/merb/logger.rb +0 -78
- data/lib/merb/mail_controller.rb +0 -268
- data/lib/merb/mailer.rb +0 -87
- data/lib/merb/mixins/basic_authentication.rb +0 -35
- data/lib/merb/mixins/controller.rb +0 -160
- data/lib/merb/mixins/erubis_capture.rb +0 -68
- data/lib/merb/mixins/general_controller.rb +0 -253
- data/lib/merb/mixins/inline_partial.rb +0 -32
- data/lib/merb/mixins/render.rb +0 -465
- data/lib/merb/mixins/responder.rb +0 -449
- data/lib/merb/mixins/view_context.rb +0 -558
- data/lib/merb/mixins/web_controller.rb +0 -36
- data/lib/merb/mongrel_handler.rb +0 -168
- data/lib/merb/part_controller.rb +0 -29
- data/lib/merb/plugins.rb +0 -16
- data/lib/merb/rack_adapter.rb +0 -37
- data/lib/merb/request.rb +0 -465
- data/lib/merb/router.rb +0 -646
- data/lib/merb/server.rb +0 -169
- data/lib/merb/session.rb +0 -23
- data/lib/merb/session/cookie_store.rb +0 -118
- data/lib/merb/session/mem_cache_session.rb +0 -131
- data/lib/merb/session/memory_session.rb +0 -176
- data/lib/merb/template.rb +0 -37
- data/lib/merb/template/erubis.rb +0 -68
- data/lib/merb/template/haml.rb +0 -87
- data/lib/merb/template/markaby.rb +0 -59
- data/lib/merb/template/xml_builder.rb +0 -50
- data/lib/merb/test/fake_request.rb +0 -74
- data/lib/merb/test/helper.rb +0 -260
- data/lib/merb/test/hpricot.rb +0 -136
- data/lib/merb/test/multipart.rb +0 -66
- data/lib/merb/test/rspec.rb +0 -18
- data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
- data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
- data/lib/merb/upload_handler.rb +0 -80
- data/lib/merb/upload_progress.rb +0 -48
- data/lib/merb/version.rb +0 -49
- data/lib/merb/view_context.rb +0 -79
- data/lib/tasks.rb +0 -7
- data/lib/tasks/merb.rake +0 -54
- data/merb_default_generators/model/USAGE +0 -0
- data/merb_default_generators/model/model_generator.rb +0 -16
- data/merb_default_generators/model/templates/new_model_template.erb +0 -5
- data/merb_default_generators/resource_controller/USAGE +0 -0
- data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
- data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
- data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
- data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
- data/merb_generators/controller/USAGE +0 -5
- data/merb_generators/controller/controller_generator.rb +0 -16
- data/merb_generators/controller/templates/controller.rb +0 -8
- data/merb_generators/controller/templates/helper.rb +0 -5
- data/merb_generators/controller/templates/index.html.erb +0 -3
- data/merb_generators/part_controller/USAGE +0 -5
- data/merb_generators/part_controller/part_controller_generator.rb +0 -27
- data/merb_generators/part_controller/templates/controller.rb +0 -8
- data/merb_generators/part_controller/templates/helper.rb +0 -5
- data/merb_generators/part_controller/templates/index.html.erb +0 -3
- data/merb_generators/resource/USAGE +0 -0
- data/merb_generators/resource/resource_generator.rb +0 -67
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
- data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
- data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
- data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
- data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
- data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
- data/spec/fixtures/config/merb.yml +0 -18
- data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
- data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
- data/spec/fixtures/foo.rb +0 -3
- data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
- data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
- data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
- data/spec/fixtures/models/router_spec_models.rb +0 -30
- data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
- data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
- data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
- data/spec/fixtures/sample.txt +0 -1
- data/spec/fixtures/views/erubis.html.erb +0 -1
- data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
- data/spec/fixtures/views/examples/_haml.html.haml +0 -1
- data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
- data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
- data/spec/fixtures/views/examples/hello.xml.builder +0 -1
- data/spec/fixtures/views/examples/js.js.erb +0 -1
- data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
- data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
- data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
- data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
- data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
- data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
- data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
- data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
- data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
- data/spec/fixtures/views/haml.html.haml +0 -1
- data/spec/fixtures/views/haml.xml.haml +0 -2
- data/spec/fixtures/views/layout/application.html.erb +0 -1
- data/spec/fixtures/views/layout/application.xml.erb +0 -1
- data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
- data/spec/fixtures/views/markaby.html.mab +0 -1
- data/spec/fixtures/views/nested/example/test.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
- data/spec/fixtures/views/partials/_haml.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
- data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
- data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
- data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
- data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
- data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
- data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
- data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
- data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
- data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
- data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
- data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
- data/spec/merb/abstract_controller_spec.rb +0 -38
- data/spec/merb/assets_spec.rb +0 -207
- data/spec/merb/caching_spec.rb +0 -102
- data/spec/merb/config_spec.rb +0 -29
- data/spec/merb/controller_filters_spec.rb +0 -253
- data/spec/merb/controller_spec.rb +0 -126
- data/spec/merb/cookie_store_spec.rb +0 -72
- data/spec/merb/cookies_spec.rb +0 -96
- data/spec/merb/core_ext/class_spec.rb +0 -97
- data/spec/merb/core_ext/enumerable_spec.rb +0 -27
- data/spec/merb/core_ext/hash_spec.rb +0 -251
- data/spec/merb/core_ext/inflector_spec.rb +0 -34
- data/spec/merb/core_ext/kernel_spec.rb +0 -25
- data/spec/merb/core_ext/numeric_spec.rb +0 -26
- data/spec/merb/core_ext/object_spec.rb +0 -47
- data/spec/merb/core_ext/string_spec.rb +0 -22
- data/spec/merb/core_ext/symbol_spec.rb +0 -7
- data/spec/merb/dependency_spec.rb +0 -22
- data/spec/merb/dispatch_spec.rb +0 -528
- data/spec/merb/fake_request_spec.rb +0 -80
- data/spec/merb/generator_spec.rb +0 -248
- data/spec/merb/handler_spec.rb +0 -169
- data/spec/merb/mail_controller_spec.rb +0 -177
- data/spec/merb/mailer_spec.rb +0 -87
- data/spec/merb/multipart_spec.rb +0 -50
- data/spec/merb/part_controller_spec.rb +0 -124
- data/spec/merb/plugins_spec.rb +0 -80
- data/spec/merb/render_spec.rb +0 -469
- data/spec/merb/request_spec.rb +0 -287
- data/spec/merb/responder_spec.rb +0 -562
- data/spec/merb/router_spec.rb +0 -900
- data/spec/merb/server_spec.rb +0 -19
- data/spec/merb/template_spec.rb +0 -41
- data/spec/merb/upload_handler_spec.rb +0 -108
- data/spec/merb/version_spec.rb +0 -33
- data/spec/merb/view_context_spec.rb +0 -366
- data/spec/spec_generator_helper.rb +0 -34
- data/spec/spec_helper.rb +0 -101
- data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
- data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
- data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
- data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
data/lib/merb/core_ext/mash.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
|
2
|
-
# This class has dubious semantics and we only have it so that
|
3
|
-
# people can write params[:key] instead of params['key']
|
4
|
-
|
5
|
-
class Mash < Hash
|
6
|
-
def initialize(constructor = {})
|
7
|
-
if constructor.is_a?(Hash)
|
8
|
-
super()
|
9
|
-
update(constructor)
|
10
|
-
else
|
11
|
-
super(constructor)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def default(key = nil)
|
16
|
-
if key.is_a?(Symbol) && include?(key = key.to_s)
|
17
|
-
self[key]
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
24
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
25
|
-
|
26
|
-
def []=(key, value)
|
27
|
-
regular_writer(convert_key(key), convert_value(value))
|
28
|
-
end
|
29
|
-
|
30
|
-
def update(other_hash)
|
31
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
alias_method :merge!, :update
|
36
|
-
|
37
|
-
def key?(key)
|
38
|
-
super(convert_key(key))
|
39
|
-
end
|
40
|
-
|
41
|
-
alias_method :include?, :key?
|
42
|
-
alias_method :has_key?, :key?
|
43
|
-
alias_method :member?, :key?
|
44
|
-
|
45
|
-
def fetch(key, *extras)
|
46
|
-
super(convert_key(key), *extras)
|
47
|
-
end
|
48
|
-
|
49
|
-
def values_at(*indices)
|
50
|
-
indices.collect {|key| self[convert_key(key)]}
|
51
|
-
end
|
52
|
-
|
53
|
-
def dup
|
54
|
-
Mash.new(self)
|
55
|
-
end
|
56
|
-
|
57
|
-
def merge(hash)
|
58
|
-
self.dup.update(hash)
|
59
|
-
end
|
60
|
-
|
61
|
-
def delete(key)
|
62
|
-
super(convert_key(key))
|
63
|
-
end
|
64
|
-
|
65
|
-
def stringify_keys!; self end
|
66
|
-
def symbolize_keys!; self end
|
67
|
-
|
68
|
-
# Convert to a Hash with String keys.
|
69
|
-
def to_hash
|
70
|
-
Hash.new(default).merge(self)
|
71
|
-
end
|
72
|
-
|
73
|
-
protected
|
74
|
-
def convert_key(key)
|
75
|
-
key.kind_of?(Symbol) ? key.to_s : key
|
76
|
-
end
|
77
|
-
|
78
|
-
def convert_value(value)
|
79
|
-
case value
|
80
|
-
when Hash
|
81
|
-
value.to_mash
|
82
|
-
when Array
|
83
|
-
value.collect { |e| e.is_a?(Hash) ? e.to_mash : e }
|
84
|
-
else
|
85
|
-
value
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
data/lib/merb/core_ext/module.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
|
3
|
-
# alias_method_chain :foo, :bar produces the following pattern:
|
4
|
-
#
|
5
|
-
# alias_method :foo_without_bar, :foo
|
6
|
-
# alias_method :foo, :foo_with_bar
|
7
|
-
#
|
8
|
-
# You will then need to write the foo_with_bar method, which will
|
9
|
-
# be able to reference foo_without_bar:
|
10
|
-
#
|
11
|
-
# def foo_with_bar
|
12
|
-
# foo_without_bar.map {|x| x + 1 }
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# Method punctuation (foo? and foo!) will be retained:
|
16
|
-
#
|
17
|
-
# alias_method_chain :foo?, :bar will produce:
|
18
|
-
# foo_without_bar?
|
19
|
-
# foo_with_bar?
|
20
|
-
#
|
21
|
-
# alias_method_chain :foo!, :bar will produce:
|
22
|
-
# foo_without_bar!
|
23
|
-
# foo_with_bar!
|
24
|
-
def alias_method_chain(target, feature)
|
25
|
-
# Strip out punctuation on predicates or bang methods since
|
26
|
-
# e.g. target?_without_feature is not a valid method name.
|
27
|
-
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
28
|
-
yield(aliased_target, punctuation) if block_given?
|
29
|
-
alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
|
30
|
-
alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
|
31
|
-
end
|
32
|
-
|
33
|
-
# defines a series of instance variables to be initialized when
|
34
|
-
# the class is initialized.
|
35
|
-
#
|
36
|
-
# For instance, you could create the class Foo:
|
37
|
-
#
|
38
|
-
# class Foo
|
39
|
-
# attr_initialize :bar, :baz
|
40
|
-
# attr_accessor :bar, :baz
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# and initialize an instance of the class as follows:
|
44
|
-
#
|
45
|
-
# Foo.new(1, 2)
|
46
|
-
#
|
47
|
-
# which will create a new Foo object with #bar equal to 1 and #baz
|
48
|
-
# equal to 2.
|
49
|
-
#
|
50
|
-
# Passing a different number of arguments to <tt>new</tt> than you
|
51
|
-
# passed to attr_initialize will result in an ArgumentError being
|
52
|
-
# thrown.
|
53
|
-
def attr_initialize(*attrs)
|
54
|
-
define_method(:initialize) do |*passed|
|
55
|
-
raise ArgumentError, "Wrong number of arguments" \
|
56
|
-
unless attrs.size == passed.size
|
57
|
-
|
58
|
-
attrs.each_with_index do |att, i|
|
59
|
-
instance_variable_set("@#{att}", passed[i])
|
60
|
-
end
|
61
|
-
|
62
|
-
after_initialize if respond_to? :after_initialize
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
class Numeric
|
2
|
-
|
3
|
-
# Converts a number to currency. Optionally, it allows localization of currency.
|
4
|
-
#
|
5
|
-
# 1.5.to_currency #=> "$1.50"
|
6
|
-
#
|
7
|
-
# You can also localize the symbol that appears before the number, the
|
8
|
-
# thousands delimiter, the decimal delimiter, and the symbol that appears
|
9
|
-
# after the number:
|
10
|
-
# 1.5.to_currency nil, ",", ".", "$USD" #=> "1.50$USD"
|
11
|
-
# 67_000.5.to_currency nil, ".", ",", "DM" #=> "67.000,50DM"
|
12
|
-
def to_currency(pre_symbol='$', thousands=',', decimal='.', post_symbol=nil)
|
13
|
-
"#{pre_symbol}#{("%.2f" % self ).gsub(".", decimal).gsub(/(\d)(?=(?:\d{3})+(?:$|[\\#{decimal}]))/,"\\1#{thousands}")}#{post_symbol}"
|
14
|
-
end
|
15
|
-
|
16
|
-
# Divides the number by 1,000,000
|
17
|
-
#
|
18
|
-
# 2.microseconds #=> 2.0e-06
|
19
|
-
def microseconds() Float(self * (10 ** -6)) end
|
20
|
-
# Divides the number by 1,000
|
21
|
-
#
|
22
|
-
# 2.milliseconds #=> 0.002
|
23
|
-
def milliseconds() Float(self * (10 ** -3)) end
|
24
|
-
# Returns the same number as is passed in
|
25
|
-
#
|
26
|
-
# 2.seconds #=> 2
|
27
|
-
def seconds() self end
|
28
|
-
# Multiplies the number by 60
|
29
|
-
#
|
30
|
-
# 2.minutes #=> 120
|
31
|
-
def minutes() 60 * seconds end
|
32
|
-
# Multiplies the number by 60 minutes
|
33
|
-
#
|
34
|
-
# 2.hours #=> 7200
|
35
|
-
def hours() 60 * minutes end
|
36
|
-
# Multiples the number by 24 hours
|
37
|
-
#
|
38
|
-
# 2.days #=> 172800
|
39
|
-
def days() 24 * hours end
|
40
|
-
# Multiples the number by 7 days
|
41
|
-
#
|
42
|
-
# 2.weeks #=> 1209600
|
43
|
-
def weeks() 7 * days end
|
44
|
-
# Multiples the number by 30 days
|
45
|
-
#
|
46
|
-
# 2.months #=> 5184000
|
47
|
-
def months() 30 * days end
|
48
|
-
# Multiplies the number by 365 days
|
49
|
-
#
|
50
|
-
# 2.years #=> 63072000
|
51
|
-
def years() 365 * days end
|
52
|
-
# Multiplies the number by 10 years
|
53
|
-
#
|
54
|
-
# 2.decades #=> 630720000
|
55
|
-
def decades() 10 * years end
|
56
|
-
|
57
|
-
# Each of the time extensions also works in the singular:
|
58
|
-
#
|
59
|
-
# 1.day #=> 86400
|
60
|
-
# 1.hour #=> 3600
|
61
|
-
alias_method :microsecond, :microseconds
|
62
|
-
alias_method :millisecond, :milliseconds
|
63
|
-
alias_method :second, :seconds
|
64
|
-
alias_method :minute, :minutes
|
65
|
-
alias_method :hour, :hours
|
66
|
-
alias_method :day, :days
|
67
|
-
alias_method :week, :weeks
|
68
|
-
alias_method :month, :months
|
69
|
-
alias_method :year, :years
|
70
|
-
alias_method :decade, :decades
|
71
|
-
|
72
|
-
end
|
data/lib/merb/core_ext/object.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
|
3
|
-
# Yields <tt>value</tt> to the passed block and returns the value.
|
4
|
-
# The object passed in as the value parameter is also passed to the block
|
5
|
-
# as a parameter.
|
6
|
-
#
|
7
|
-
# returning({}) do |hsh|
|
8
|
-
# hsh.merge!((:bar => :baz))
|
9
|
-
# end #=> {:bar => :baz}
|
10
|
-
def returning(value)
|
11
|
-
yield(value)
|
12
|
-
value
|
13
|
-
end
|
14
|
-
|
15
|
-
# Extracts the singleton class, so that metaprogramming can be done on it.
|
16
|
-
#
|
17
|
-
# Let's look at two code snippets:
|
18
|
-
#
|
19
|
-
# class MyString < String; end
|
20
|
-
#
|
21
|
-
# MyString.instance_eval do
|
22
|
-
# define_method :foo do
|
23
|
-
# puts self
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# MyString.meta_class.instance_eval do
|
28
|
-
# define_method :bar do
|
29
|
-
# puts self
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# def String.add_meta_var(var)
|
34
|
-
# self.meta_class.instance_eval do
|
35
|
-
# define_method var do
|
36
|
-
# puts "HELLO"
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# MyString.new("Hello").foo #=> "Hello"
|
42
|
-
# MyString.new("Hello").bar #=> NoMethodError: undefined method `bar' for "Hello":MyString
|
43
|
-
# MyString.foo #=> NoMethodError: undefined method `foo' for MyString:Class
|
44
|
-
# MyString.bar #=> MyString
|
45
|
-
# String.bar #=> NoMethodError: undefined method `bar' for String:Class
|
46
|
-
#
|
47
|
-
# MyString.add_meta_var(:x)
|
48
|
-
# MyString.x #=> HELLO
|
49
|
-
#
|
50
|
-
# As you can see, using #meta_class allows you to execute code (and here, define
|
51
|
-
# a method) on the metaclass itself. It also allows you to define class methods that can
|
52
|
-
# be run on subclasses, and then be able to execute code on the metaclass of the subclass
|
53
|
-
# (here MyString).
|
54
|
-
#
|
55
|
-
# In this case, we were able to define a class method (add_meta_var) on String that was
|
56
|
-
# executable by the MyString subclass. It was then able to define a method on the subclass
|
57
|
-
# by adding it to the MyString metaclass.
|
58
|
-
#
|
59
|
-
# For more information, you can check out _why's excellent article at:
|
60
|
-
# http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
|
61
|
-
def meta_class() class << self; self end end
|
62
|
-
|
63
|
-
# Runs instance_eval on the metaclass (see Object#meta_class).
|
64
|
-
#
|
65
|
-
# String.meta_eval do
|
66
|
-
# define_method :zoo do
|
67
|
-
# puts "zoo"
|
68
|
-
# end
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# String.zoo # => "zoo"
|
72
|
-
def meta_eval(&blk) meta_class.instance_eval( &blk ) end
|
73
|
-
|
74
|
-
# Defines a method on the metaclass (see Object#meta_class).
|
75
|
-
#
|
76
|
-
# String.meta_def :zoo do
|
77
|
-
# puts "zoo"
|
78
|
-
# end
|
79
|
-
#
|
80
|
-
# String.zoo #=> "zoo"
|
81
|
-
#
|
82
|
-
# If the class inherits from another class, it will only be defined
|
83
|
-
# on the direct class meta_def is called on.
|
84
|
-
#
|
85
|
-
# class Foo; end
|
86
|
-
# class Bar < Foo; end
|
87
|
-
# class Baz < Foo; end
|
88
|
-
#
|
89
|
-
# Bar.meta_def :q do; "Q"; end
|
90
|
-
# Foo.q #=> undefined method `r' for Foo:Class
|
91
|
-
# Bar.q #=> "Q"
|
92
|
-
# Baz.q #=> undefined method `r' for Baz:Class
|
93
|
-
#
|
94
|
-
# See Object#class_def for a comprehensive example containing meta_def
|
95
|
-
def meta_def(name, &blk) meta_eval { define_method name, &blk } end
|
96
|
-
|
97
|
-
# Defines a method on new instances of the class.
|
98
|
-
#
|
99
|
-
# String.class_def :zoo do
|
100
|
-
# puts "zoo"
|
101
|
-
# end
|
102
|
-
#
|
103
|
-
# "HELLO".zoo #=> "zoo"
|
104
|
-
#
|
105
|
-
# In combination with meta_def, you can do some pretty powerful
|
106
|
-
# things:
|
107
|
-
#
|
108
|
-
# require 'merb_object'
|
109
|
-
# class Foo
|
110
|
-
# def self.var
|
111
|
-
# @var
|
112
|
-
# end
|
113
|
-
# def self.make_var baz
|
114
|
-
# attr_accessor baz
|
115
|
-
# meta_def baz do |val|
|
116
|
-
# @var = val
|
117
|
-
# end
|
118
|
-
# class_def :initialize do
|
119
|
-
# instance_variable_set("@#{baz}", self.class.var)
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# It might look a bit hairy, but here are some results that
|
125
|
-
# may help:
|
126
|
-
#
|
127
|
-
# class Bar < Foo
|
128
|
-
# make_var :foo
|
129
|
-
# foo "FOO"
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
# Bar.new.foo #=> "FOO"
|
133
|
-
#
|
134
|
-
# Essentially, what's happening is that Foo.make_var has the
|
135
|
-
# following effects when some symbol (:foo) is passed in:
|
136
|
-
# * Adds a new :foo accessor (returning @foo)
|
137
|
-
# * Adds a new foo method on the **class**, allowing you to set
|
138
|
-
# a default value.
|
139
|
-
# * Sets @foo to that default value when new objects are
|
140
|
-
# initialized.
|
141
|
-
#
|
142
|
-
# In the case of the Bar class, the following occurred:
|
143
|
-
# * make_var :foo created a new :foo accessor
|
144
|
-
# * foo "FOO" set the default value of @foo to "FOO"
|
145
|
-
# * Bar.new created a new Bar object containing the
|
146
|
-
# instance variable @foo containing the default value
|
147
|
-
# "FOO"
|
148
|
-
def class_def name, &blk
|
149
|
-
class_eval { define_method name, &blk }
|
150
|
-
end
|
151
|
-
|
152
|
-
# Returns true if:
|
153
|
-
# * it's an empty array
|
154
|
-
# * it's an empty string
|
155
|
-
# * !self evaluates to true
|
156
|
-
#
|
157
|
-
# [].blank? #=> true
|
158
|
-
# [1].blank? #=> false
|
159
|
-
# [nil].blank? #=> false
|
160
|
-
# nil.blank? #=> true
|
161
|
-
# true.blank? #=> false
|
162
|
-
# false.blank? #=> true
|
163
|
-
# "".blank? #=> true
|
164
|
-
# " ".blank? #=> true
|
165
|
-
# " hey ho ".blank? #=> false
|
166
|
-
def blank?
|
167
|
-
if respond_to?(:empty?) && respond_to?(:strip)
|
168
|
-
empty? or strip.empty?
|
169
|
-
elsif respond_to?(:empty?)
|
170
|
-
empty?
|
171
|
-
else
|
172
|
-
!self
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def full_const_get(name)
|
177
|
-
list = name.split("::")
|
178
|
-
obj = Object
|
179
|
-
list.each {|x| obj = obj.const_get(x) }
|
180
|
-
obj
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|
data/lib/merb/core_ext/string.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
class String
|
4
|
-
class InvalidPathConversion < Exception; end
|
5
|
-
|
6
|
-
# Escapes any characters in the string that would have special meaning in a
|
7
|
-
# regular expression.
|
8
|
-
# $ "\*?{}.".escape_regexp #=> "\\*\\?\\{\\}\\."
|
9
|
-
def escape_regexp
|
10
|
-
Regexp.escape self
|
11
|
-
end
|
12
|
-
|
13
|
-
# "FooBar".snake_case #=> "foo_bar"
|
14
|
-
def snake_case
|
15
|
-
gsub(/\B[A-Z]/, '_\&').downcase
|
16
|
-
end
|
17
|
-
|
18
|
-
# "foo_bar".camel_case #=> "FooBar"
|
19
|
-
def camel_case
|
20
|
-
split('_').map{|e| e.capitalize}.join
|
21
|
-
end
|
22
|
-
|
23
|
-
# "merb/core_ext/string" #=> "Merb::CoreExt::String"
|
24
|
-
#
|
25
|
-
# About 50% faster than string.split('/').map{ |s| s.camel_case }.join('::')
|
26
|
-
def to_const_string
|
27
|
-
new_string = ""
|
28
|
-
input = StringScanner.new(self.downcase)
|
29
|
-
until input.eos?
|
30
|
-
if input.scan(/([a-z][a-zA-Z\d]*)(_|$|\/)/)
|
31
|
-
new_string << input[1].capitalize
|
32
|
-
new_string << "::" if input[2] == '/'
|
33
|
-
else
|
34
|
-
raise InvalidPathConversion, self
|
35
|
-
end
|
36
|
-
end
|
37
|
-
new_string
|
38
|
-
end
|
39
|
-
|
40
|
-
# Concatenates a path
|
41
|
-
# $ "merb"/"core_ext" #=> "merb/core_ext"
|
42
|
-
def /(o)
|
43
|
-
File.join(self, o.to_s)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Takes lines of text, removes any indentation, and
|
47
|
-
# adds +indentation+ number of spaces to each line
|
48
|
-
# $ " Hello\n Bob\nHow are you?".indent(3)
|
49
|
-
# #=> " Hello\n Bob\n How are you?"
|
50
|
-
def indent(indentation)
|
51
|
-
match(/\s*/) && gsub(/^\s{0,#{$&.length}}/, " " * indentation)
|
52
|
-
end
|
53
|
-
end
|