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.
- 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/symbol.rb
DELETED
data/lib/merb/dispatcher.rb
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
module Merb
|
|
2
|
-
class Dispatcher
|
|
3
|
-
|
|
4
|
-
DEFAULT_ERROR_TEMPLATE = Erubis::MEruby.new((File.read(
|
|
5
|
-
File.join(Merb.root, 'app/views/exceptions/internal_server_error.html.erb')) rescue "Internal Server Error!"))
|
|
6
|
-
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
def use_mutex=(val)
|
|
10
|
-
@@use_mutex = val
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
@@mutex = Mutex.new
|
|
14
|
-
@@use_mutex = ::Merb::Config[:use_mutex]
|
|
15
|
-
# This is where we grab the incoming request REQUEST_URI and use that in
|
|
16
|
-
# the merb RouteMatcher to determine which controller and method to run.
|
|
17
|
-
# Returns a 2 element tuple of: [controller, action]
|
|
18
|
-
#
|
|
19
|
-
# ControllerExceptions are rescued here and redispatched.
|
|
20
|
-
# Exceptions still return [controller, action]
|
|
21
|
-
def handle(http_request, response)
|
|
22
|
-
start = Time.now
|
|
23
|
-
request = Merb::Request.new(http_request)
|
|
24
|
-
Merb.logger.info("Params: #{request.params.inspect}")
|
|
25
|
-
Merb.logger.info("Cookies: #{request.cookies.inspect}")
|
|
26
|
-
# user friendly error messages
|
|
27
|
-
if request.route_params.empty?
|
|
28
|
-
raise ControllerExceptions::BadRequest, "No routes match the request"
|
|
29
|
-
elsif request.controller_name.nil?
|
|
30
|
-
raise ControllerExceptions::BadRequest, "Route matched, but route did not specify a controller"
|
|
31
|
-
end
|
|
32
|
-
Merb.logger.debug("Routed to: #{request.route_params.inspect}")
|
|
33
|
-
# set controller class and the action to call
|
|
34
|
-
klass = request.controller_class
|
|
35
|
-
dispatch_action(klass, request.action, request, response)
|
|
36
|
-
rescue => exception
|
|
37
|
-
Merb.logger.error(Merb.exception(exception))
|
|
38
|
-
exception = controller_exception(exception)
|
|
39
|
-
dispatch_exception(request, response, exception)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
# setup the controller and call the chosen action
|
|
45
|
-
def dispatch_action(klass, action, request, response, status=200)
|
|
46
|
-
# build controller
|
|
47
|
-
controller = klass.build(request, response, status)
|
|
48
|
-
# complete setup benchmarking
|
|
49
|
-
#controller._benchmarks[:setup_time] = Time.now - start
|
|
50
|
-
if @@use_mutex
|
|
51
|
-
@@mutex.synchronize { controller.dispatch(action) }
|
|
52
|
-
else
|
|
53
|
-
controller.dispatch(action)
|
|
54
|
-
end
|
|
55
|
-
[controller, action]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Re-route the current request to the Exception controller
|
|
59
|
-
# if it is available, and try to render the exception nicely
|
|
60
|
-
# if it is not available then just render a simple text error
|
|
61
|
-
def dispatch_exception(request, response, exception)
|
|
62
|
-
klass = Exceptions rescue Controller
|
|
63
|
-
request.params[:original_params] = request.params.dup rescue {}
|
|
64
|
-
request.params[:original_session] = request.session.dup rescue {}
|
|
65
|
-
request.params[:original_cookies] = request.cookies.dup rescue {}
|
|
66
|
-
request.params[:exception] = exception
|
|
67
|
-
request.params[:action] = exception.name
|
|
68
|
-
dispatch_action(klass, exception.name, request, response, exception.class::STATUS)
|
|
69
|
-
rescue => dispatch_issue
|
|
70
|
-
dispatch_issue = controller_exception(dispatch_issue)
|
|
71
|
-
# when no action/template exist for an exception, or an
|
|
72
|
-
# exception occurs on an InternalServerError the message is
|
|
73
|
-
# rendered as simple text.
|
|
74
|
-
# ControllerExceptions raised from exception actions are
|
|
75
|
-
# dispatched back into the Exceptions controller
|
|
76
|
-
if dispatch_issue.is_a?(ControllerExceptions::NotFound)
|
|
77
|
-
dispatch_default_exception(klass, request, response, exception)
|
|
78
|
-
elsif dispatch_issue.is_a?(ControllerExceptions::InternalServerError)
|
|
79
|
-
dispatch_default_exception(klass, request, response, dispatch_issue)
|
|
80
|
-
else
|
|
81
|
-
exception = dispatch_issue
|
|
82
|
-
retry
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# if no custom actions are available to render an exception
|
|
87
|
-
# then the errors will end up here for processing
|
|
88
|
-
def dispatch_default_exception(klass, request, response, e)
|
|
89
|
-
controller = klass.build(request, response, e.class::STATUS)
|
|
90
|
-
if e.is_a? ControllerExceptions::Redirection
|
|
91
|
-
controller.headers.merge!('Location' => e.message)
|
|
92
|
-
controller.instance_variable_set("@_body", %{ }) #fix
|
|
93
|
-
else
|
|
94
|
-
@exception = e # for ERB
|
|
95
|
-
controller.instance_variable_set("@_body", DEFAULT_ERROR_TEMPLATE.result(binding))
|
|
96
|
-
end
|
|
97
|
-
[controller, e.name]
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Wraps any non-ControllerException errors in an
|
|
101
|
-
# InternalServerError ready for displaying over HTTP
|
|
102
|
-
def controller_exception(e)
|
|
103
|
-
e.kind_of?(ControllerExceptions::Base) ?
|
|
104
|
-
e : ControllerExceptions::InternalServerError.new(e)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
end # end class << self
|
|
108
|
-
end
|
|
109
|
-
end
|
data/lib/merb/drb_server.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'drb'
|
|
2
|
-
require File.dirname(__FILE__)+'/upload_progress'
|
|
3
|
-
|
|
4
|
-
module Merb
|
|
5
|
-
|
|
6
|
-
class DrbServiceProvider
|
|
7
|
-
include DRbUndumped
|
|
8
|
-
|
|
9
|
-
class << self
|
|
10
|
-
|
|
11
|
-
def upload_progress
|
|
12
|
-
@upload_progress ||= ::Merb::UploadProgress.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
data/lib/merb/erubis_ext.rb
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require 'erubis'
|
|
2
|
-
module Erubis
|
|
3
|
-
class MEruby < Erubis::Eruby
|
|
4
|
-
include PercentLineEnhancer
|
|
5
|
-
include StringBufferEnhancer
|
|
6
|
-
end
|
|
7
|
-
def self.load_yaml_file(file, binding = binding)
|
|
8
|
-
YAML::load(Erubis::MEruby.new(IO.read(File.expand_path(file))).result(binding))
|
|
9
|
-
end
|
|
10
|
-
end
|
data/lib/merb/exceptions.rb
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'coderay'
|
|
3
|
-
rescue LoadError => ex
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
module Merb
|
|
7
|
-
# ControllerExceptions are a way of simplifying controller code by placing
|
|
8
|
-
# exceptional logic back into the MVC pattern.
|
|
9
|
-
#
|
|
10
|
-
# When a ControllerException is raised within your application merb will
|
|
11
|
-
# attempt to re-route the request to your Exceptions controller to render
|
|
12
|
-
# the error in a friendly mannor.
|
|
13
|
-
#
|
|
14
|
-
# For example you might have an action in your app that raises NotFound
|
|
15
|
-
# if a some resource was not available
|
|
16
|
-
#
|
|
17
|
-
# def show
|
|
18
|
-
# product = Product.find(params[:id])
|
|
19
|
-
# raise NotFound if product.nil?
|
|
20
|
-
# [...]
|
|
21
|
-
# end
|
|
22
|
-
#
|
|
23
|
-
# This would halt execution of your action and re-route it over to your
|
|
24
|
-
# Exceptions controller which might look something like
|
|
25
|
-
#
|
|
26
|
-
# class Exceptions < Application
|
|
27
|
-
# def not_found
|
|
28
|
-
# render :layout => :none
|
|
29
|
-
# end
|
|
30
|
-
# end
|
|
31
|
-
#
|
|
32
|
-
# As usual the not_found action will look for a template in
|
|
33
|
-
# app/views/exceptions/not_found.html.erb
|
|
34
|
-
#
|
|
35
|
-
# Note: All standard ControllerExceptions have an HTTP status code associated
|
|
36
|
-
# with them which is sent to the browser when the action it is rendered.
|
|
37
|
-
#
|
|
38
|
-
# Note: If you do not specifiy how to handle raised ControllerExceptions
|
|
39
|
-
# or an unhandlable exception occurs within your customised exception action
|
|
40
|
-
# then they will be rendered using the built-in error template
|
|
41
|
-
# in development mode this "built in" template will show stack-traces for
|
|
42
|
-
# any of the ServerError family of exceptions (you can force the stack-trace
|
|
43
|
-
# to display in production mode using the :exception_details config option in
|
|
44
|
-
# merb.yml)
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
# Internal Exceptions
|
|
48
|
-
#
|
|
49
|
-
# Any other rogue errors (not ControllerExceptions) that occur during the
|
|
50
|
-
# execution of you app will be converted into the ControllerException
|
|
51
|
-
# InternalServerError, and like all ControllerExceptions can be caught
|
|
52
|
-
# on your Exceptions controller.
|
|
53
|
-
#
|
|
54
|
-
# InternalServerErrors return status 500, a common use for cusomizing this
|
|
55
|
-
# action might be to send emails to the development team, warning that their
|
|
56
|
-
# application have exploded. Mock example:
|
|
57
|
-
#
|
|
58
|
-
# def internal_server_error
|
|
59
|
-
# MySpecialMailer.deliver(
|
|
60
|
-
# "team@cowboys.com",
|
|
61
|
-
# "Exception occured at #{Time.now}",
|
|
62
|
-
# params[:exception])
|
|
63
|
-
# render :inline => 'Something is wrong, but the team are on it!'
|
|
64
|
-
# end
|
|
65
|
-
#
|
|
66
|
-
# Note: The special param[:exception] is available in all Exception actions
|
|
67
|
-
# and contains the ControllerException that was raised (this is handy if
|
|
68
|
-
# you want to display the associated message or display more detailed info)
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
# Extending ControllerExceptions
|
|
72
|
-
#
|
|
73
|
-
# To extend the use of the ControllerExceptions one may extend any of the
|
|
74
|
-
# HTTPError classes.
|
|
75
|
-
#
|
|
76
|
-
# As an example we can create an exception called AdminAccessRequired.
|
|
77
|
-
#
|
|
78
|
-
# class AdminAccessRequired < Merb::ControllerExceptions::Unauthorized; end
|
|
79
|
-
#
|
|
80
|
-
# Add the required action to our Exceptions controller
|
|
81
|
-
#
|
|
82
|
-
# class Exceptions < Application
|
|
83
|
-
# def admin_access_required
|
|
84
|
-
# render
|
|
85
|
-
# end
|
|
86
|
-
# end
|
|
87
|
-
#
|
|
88
|
-
# In app/views/exceptions/admin_access_required.rhtml
|
|
89
|
-
#
|
|
90
|
-
# <h1>You're not an administrator!</h1>
|
|
91
|
-
# <p>You tried to access <%= @tried_to_access %> but that URL is
|
|
92
|
-
# restricted to administrators.</p>
|
|
93
|
-
#
|
|
94
|
-
module ControllerExceptions
|
|
95
|
-
|
|
96
|
-
# Mapping of status code names to their numeric value.
|
|
97
|
-
STATUS_CODES = {}
|
|
98
|
-
|
|
99
|
-
class Base < StandardError
|
|
100
|
-
def name
|
|
101
|
-
self.class.to_s.snake_case.split('::').last
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
#
|
|
105
|
-
# Registers any subclasses with status codes for easy lookup by
|
|
106
|
-
# set_status in Merb::Controller.
|
|
107
|
-
#
|
|
108
|
-
# Inheritance ensures this method gets inherited by any subclasses, so
|
|
109
|
-
# it goes all the way down the chain of inheritance.
|
|
110
|
-
#
|
|
111
|
-
def self.inherited(subclass)
|
|
112
|
-
if subclass.const_defined?(:STATUS)
|
|
113
|
-
STATUS_CODES[subclass.name.snake_case.to_sym] = subclass.const_get(:STATUS)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
class Informational < Merb::ControllerExceptions::Base; end
|
|
119
|
-
class Continue < Merb::ControllerExceptions::Informational; STATUS = 100; end
|
|
120
|
-
class SwitchingProtocols < Merb::ControllerExceptions::Informational; STATUS = 101; end
|
|
121
|
-
class Successful < Merb::ControllerExceptions::Base; end
|
|
122
|
-
class OK < Merb::ControllerExceptions::Successful; STATUS = 200; end
|
|
123
|
-
class Created < Merb::ControllerExceptions::Successful; STATUS = 201; end
|
|
124
|
-
class Accepted < Merb::ControllerExceptions::Successful; STATUS = 202; end
|
|
125
|
-
class NonAuthoritativeInformation < Merb::ControllerExceptions::Successful; STATUS = 203; end
|
|
126
|
-
class NoContent < Merb::ControllerExceptions::Successful; STATUS = 204; end
|
|
127
|
-
class ResetContent < Merb::ControllerExceptions::Successful; STATUS = 205; end
|
|
128
|
-
class PartialContent < Merb::ControllerExceptions::Successful; STATUS = 206; end
|
|
129
|
-
class Redirection < Merb::ControllerExceptions::Base; end
|
|
130
|
-
class MultipleChoices < Merb::ControllerExceptions::Redirection; STATUS = 300; end
|
|
131
|
-
class MovedPermanently < Merb::ControllerExceptions::Redirection; STATUS = 301; end
|
|
132
|
-
class MovedTemporarily < Merb::ControllerExceptions::Redirection; STATUS = 302; end
|
|
133
|
-
class SeeOther < Merb::ControllerExceptions::Redirection; STATUS = 303; end
|
|
134
|
-
class NotModified < Merb::ControllerExceptions::Redirection; STATUS = 304; end
|
|
135
|
-
class UseProxy < Merb::ControllerExceptions::Redirection; STATUS = 305; end
|
|
136
|
-
class TemporaryRedirect < Merb::ControllerExceptions::Redirection; STATUS = 307; end
|
|
137
|
-
class ClientError < Merb::ControllerExceptions::Base; end
|
|
138
|
-
class BadRequest < Merb::ControllerExceptions::ClientError; STATUS = 400; end
|
|
139
|
-
class MultiPartParseError < Merb::ControllerExceptions::BadRequest; end
|
|
140
|
-
class Unauthorized < Merb::ControllerExceptions::ClientError; STATUS = 401; end
|
|
141
|
-
class PaymentRequired < Merb::ControllerExceptions::ClientError; STATUS = 402; end
|
|
142
|
-
class Forbidden < Merb::ControllerExceptions::ClientError; STATUS = 403; end
|
|
143
|
-
class NotFound < Merb::ControllerExceptions::ClientError; STATUS = 404; end
|
|
144
|
-
class ActionNotFound < Merb::ControllerExceptions::NotFound; end
|
|
145
|
-
class TemplateNotFound < Merb::ControllerExceptions::NotFound; end
|
|
146
|
-
class LayoutNotFound < Merb::ControllerExceptions::NotFound; end
|
|
147
|
-
class MethodNotAllowed < Merb::ControllerExceptions::ClientError; STATUS = 405; end
|
|
148
|
-
class NotAcceptable < Merb::ControllerExceptions::ClientError; STATUS = 406; end
|
|
149
|
-
class ProxyAuthenticationRequired < Merb::ControllerExceptions::ClientError; STATUS = 407; end
|
|
150
|
-
class RequestTimeout < Merb::ControllerExceptions::ClientError; STATUS = 408; end
|
|
151
|
-
class Conflict < Merb::ControllerExceptions::ClientError; STATUS = 409; end
|
|
152
|
-
class Gone < Merb::ControllerExceptions::ClientError; STATUS = 410; end
|
|
153
|
-
class LengthRequired < Merb::ControllerExceptions::ClientError; STATUS = 411; end
|
|
154
|
-
class PreconditionFailed < Merb::ControllerExceptions::ClientError; STATUS = 412; end
|
|
155
|
-
class RequestEntityTooLarge < Merb::ControllerExceptions::ClientError; STATUS = 413; end
|
|
156
|
-
class RequestURITooLarge < Merb::ControllerExceptions::ClientError; STATUS = 414; end
|
|
157
|
-
class UnsupportedMediaType < Merb::ControllerExceptions::ClientError; STATUS = 415; end
|
|
158
|
-
class RequestRangeNotSatisfiable < Merb::ControllerExceptions::ClientError; STATUS = 416; end
|
|
159
|
-
class ExpectationFailed < Merb::ControllerExceptions::ClientError; STATUS = 417; end
|
|
160
|
-
class ServerError < Merb::ControllerExceptions::Base; end
|
|
161
|
-
class NotImplemented < Merb::ControllerExceptions::ServerError; STATUS = 501; end
|
|
162
|
-
class BadGateway < Merb::ControllerExceptions::ServerError; STATUS = 502; end
|
|
163
|
-
class ServiceUnavailable < Merb::ControllerExceptions::ServerError; STATUS = 503; end
|
|
164
|
-
class GatewayTimeout < Merb::ControllerExceptions::ServerError; STATUS = 504; end
|
|
165
|
-
class HTTPVersionNotSupported < Merb::ControllerExceptions::ServerError; STATUS = 505; end
|
|
166
|
-
class InternalServerError < Merb::ControllerExceptions::ServerError;
|
|
167
|
-
STATUS = 500
|
|
168
|
-
DEFAULT_TEMPLATE = ::Merb::Dispatcher::DEFAULT_ERROR_TEMPLATE
|
|
169
|
-
|
|
170
|
-
def initialize(exception = nil)
|
|
171
|
-
@exception = exception
|
|
172
|
-
@coderay = CodeRay rescue nil
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def backtrace
|
|
176
|
-
@exception ? @exception.backtrace : backtrace
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def message
|
|
180
|
-
@exception ? @exception.message : message
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
# PLEASE STOP REMOVING THIS ONE GUYS! It's used to show exceptions in the log file
|
|
186
|
-
# this is the second time I've had to add it back.
|
|
187
|
-
def self.exception(e)
|
|
188
|
-
"#{ e.message } - (#{ e.class })\n" <<
|
|
189
|
-
"#{(e.backtrace or []).join("\n")}"
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
require 'find'
|
|
3
|
-
|
|
4
|
-
module Merb
|
|
5
|
-
|
|
6
|
-
class AppGenerator
|
|
7
|
-
def self.run(path)
|
|
8
|
-
require 'rubygems'
|
|
9
|
-
require 'rubigen'
|
|
10
|
-
|
|
11
|
-
require 'rubigen/scripts/generate'
|
|
12
|
-
source = RubiGen::PathSource.new(:application,
|
|
13
|
-
File.join(File.dirname(__FILE__), "../../../../app_generators"))
|
|
14
|
-
RubiGen::Base.reset_sources
|
|
15
|
-
RubiGen::Base.append_sources source
|
|
16
|
-
RubiGen::Scripts::Generate.new.run([path], :generator => 'merb', :backtrace => true)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
# Provides some basic generator support that is generally required in various
|
|
2
|
-
# Generators
|
|
3
|
-
|
|
4
|
-
module Merb
|
|
5
|
-
module GeneratorHelpers
|
|
6
|
-
|
|
7
|
-
class ModelGeneratorBase < RubiGen::Base
|
|
8
|
-
|
|
9
|
-
default_options :author => nil
|
|
10
|
-
attr_reader :name, :model_attributes
|
|
11
|
-
attr_accessor :model_template_name, :model_test_generator_name, :migration_generator_name
|
|
12
|
-
|
|
13
|
-
def initialize(runtime_args, runtime_options = {})
|
|
14
|
-
super
|
|
15
|
-
usage if args.empty?
|
|
16
|
-
@class_name = args.shift.snake_case.to_const_string
|
|
17
|
-
extract_options
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def manifest
|
|
21
|
-
unless @class_name
|
|
22
|
-
puts banner
|
|
23
|
-
exit 1
|
|
24
|
-
end
|
|
25
|
-
record do |m|
|
|
26
|
-
|
|
27
|
-
# ensure there are no other definitions of this model already defined.
|
|
28
|
-
m.class_collisions(@class_name)
|
|
29
|
-
# Ensure appropriate folder(s) exists
|
|
30
|
-
m.directory 'app/models'
|
|
31
|
-
#
|
|
32
|
-
model_filename = @class_name.snake_case
|
|
33
|
-
spec_filename = @class_name.snake_case.pluralize
|
|
34
|
-
table_name = spec_filename
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# Create stubs
|
|
38
|
-
m.template model_template_name,
|
|
39
|
-
"app/models/#{model_filename}.rb",
|
|
40
|
-
:assigns => { :class_name => @class_name,
|
|
41
|
-
:table_attributes => model_attributes}
|
|
42
|
-
|
|
43
|
-
# Check to see if a scope has been set for which test framework to use.
|
|
44
|
-
# If we try to run the dependency without an :rspec or :test_unit scope an
|
|
45
|
-
# error will be raised.
|
|
46
|
-
scopes = RubiGen::Base.sources.select{ |s| s.is_a?( RubiGen::PathFilteredSource )}.first.filters
|
|
47
|
-
if scopes.include?(:rspec) || scopes.include?(:test_unit)
|
|
48
|
-
unless options[:skip_testing]
|
|
49
|
-
m.dependency model_test_generator_name, [@class_name]
|
|
50
|
-
end
|
|
51
|
-
else
|
|
52
|
-
puts "\nSelect a scope for :rspec or :test_unit in script/generate if you want to generate test stubs\n\n"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
unless options[:skip_migration]
|
|
56
|
-
m.dependency migration_generator_name,["add_model_#{spec_filename}"], :table_name => table_name, :table_attributes => model_attributes
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
protected
|
|
63
|
-
def banner
|
|
64
|
-
<<-EOS
|
|
65
|
-
Creates a new model for merb
|
|
66
|
-
|
|
67
|
-
USAGE: #{$0} #{spec.name} NameOfModel [field:type field:type]
|
|
68
|
-
|
|
69
|
-
Example:
|
|
70
|
-
#{$0} #{spec.name} person
|
|
71
|
-
|
|
72
|
-
If you already have 3 migrations, this will create the AddModelPeople migration in
|
|
73
|
-
schema/migration/004_add_model_people.rb
|
|
74
|
-
|
|
75
|
-
Options:
|
|
76
|
-
--skip-migration will not create a migration file
|
|
77
|
-
|
|
78
|
-
EOS
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def add_options!(opts)
|
|
82
|
-
opts.separator ''
|
|
83
|
-
opts.separator 'Options:'
|
|
84
|
-
# For each option below, place the default
|
|
85
|
-
# at the top of the file next to "default_options"
|
|
86
|
-
# opts.on("-a", "--author=\"Your Name\"", String,
|
|
87
|
-
# "Some comment about this option",
|
|
88
|
-
# "Default: none") { |options[:author]| }
|
|
89
|
-
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
|
90
|
-
opts.on( "--skip-migration", "Don't generate a migration for this model") { |options[:skip_migration]| }
|
|
91
|
-
opts.on( "--skip-testing", "Don't generate a test or spec file for this model") { |options[:skip_testing]| }
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def extract_options
|
|
95
|
-
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
|
96
|
-
# Templates can access these value via the attr_reader-generated methods, but not the
|
|
97
|
-
# raw instance variable value.
|
|
98
|
-
# @author = options[:author]
|
|
99
|
-
# get the attributes into a format that can be used.
|
|
100
|
-
attribute = Struct.new(:name, :type)
|
|
101
|
-
@model_attributes = args.map{ |b| b.split(":").size > 1 ? attribute.new(*b.split(":")) : nil }.compact
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class MigrationGeneratorBase < RubiGen::Base
|
|
106
|
-
|
|
107
|
-
default_options :author => nil
|
|
108
|
-
|
|
109
|
-
attr_reader :name
|
|
110
|
-
attr_accessor :migration_template_name
|
|
111
|
-
|
|
112
|
-
def initialize(runtime_args, runtime_options = {})
|
|
113
|
-
super
|
|
114
|
-
usage if args.empty?
|
|
115
|
-
@class_name = args.shift
|
|
116
|
-
options[:table_name] ||= runtime_options[:table_name]
|
|
117
|
-
extract_options
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def manifest
|
|
121
|
-
unless @class_name
|
|
122
|
-
puts banner
|
|
123
|
-
exit 1
|
|
124
|
-
end
|
|
125
|
-
record do |m|
|
|
126
|
-
# Ensure appropriate folder(s) exists
|
|
127
|
-
m.directory 'schema/migrations'
|
|
128
|
-
|
|
129
|
-
# Create stubs
|
|
130
|
-
highest_migration = Dir[Dir.pwd+'/schema/migrations/*'].map{|f| File.basename(f) =~ /^(\d+)/; $1}.max
|
|
131
|
-
filename = format("%03d_%s", (highest_migration.to_i+1), @class_name.snake_case)
|
|
132
|
-
m.template "new_migration.erb", "schema/migrations/#{filename}.rb",
|
|
133
|
-
:assigns => { :class_name => @class_name,
|
|
134
|
-
:table_name => options[:table_name],
|
|
135
|
-
:table_attributes => options[:table_attributes] }
|
|
136
|
-
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
protected
|
|
141
|
-
def banner
|
|
142
|
-
<<-EOS
|
|
143
|
-
Creates a new migration for merb
|
|
144
|
-
|
|
145
|
-
USAGE: #{$0} #{spec.name} NameOfMigration [field:type field:type]
|
|
146
|
-
|
|
147
|
-
Example:
|
|
148
|
-
#{$0} #{spec.name} AddPeople
|
|
149
|
-
|
|
150
|
-
If you already have 3 migrations, this will create the AddPeople migration in
|
|
151
|
-
schema/migration/004_add_people.rb
|
|
152
|
-
|
|
153
|
-
#{$0} #{spec.name} project --table-name projects_table name:string created_at:timestamp
|
|
154
|
-
|
|
155
|
-
This will create a migration that creates a table call projects_table with these attributes:
|
|
156
|
-
string :name
|
|
157
|
-
timestamp :created_at
|
|
158
|
-
|
|
159
|
-
EOS
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def add_options!(opts)
|
|
163
|
-
opts.separator ''
|
|
164
|
-
opts.separator 'Options:'
|
|
165
|
-
# For each option below, place the default
|
|
166
|
-
# at the top of the file next to "default_options"
|
|
167
|
-
# opts.on("-a", "--author=\"Your Name\"", String,
|
|
168
|
-
# "Some comment about this option",
|
|
169
|
-
# "Default: none") { |options[:author]| }
|
|
170
|
-
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
|
171
|
-
opts.on( "--table-name=\"table_name_for_migration\"",
|
|
172
|
-
String,
|
|
173
|
-
"Include a create table with the given table name"){ |options[:table_name]| }
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def extract_options
|
|
177
|
-
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
|
178
|
-
# Templates can access these value via the attr_reader-generated methods, but not the
|
|
179
|
-
# raw instance variable value.
|
|
180
|
-
# @author = options[:author]
|
|
181
|
-
if !options[:table_attributes]
|
|
182
|
-
attribute = Struct.new(:name, :type)
|
|
183
|
-
options[:table_attributes] = args.map{ |b| b.split(":").size == 2 ? attribute.new(*b.split(":")) : nil }.compact
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
class MerbModelTestGenerator < RubiGen::Base
|
|
189
|
-
|
|
190
|
-
default_options :author => nil
|
|
191
|
-
|
|
192
|
-
attr_reader :name, :model_test_template_name, :model_test_path_name, :model_test_file_suffix
|
|
193
|
-
|
|
194
|
-
def initialize(runtime_args, runtime_options = {})
|
|
195
|
-
super
|
|
196
|
-
usage if args.empty?
|
|
197
|
-
@class_name = args.shift.snake_case.to_const_string
|
|
198
|
-
extract_options
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def manifest
|
|
202
|
-
unless @class_name
|
|
203
|
-
puts banner
|
|
204
|
-
exit 1
|
|
205
|
-
end
|
|
206
|
-
record do |m|
|
|
207
|
-
# ensure there are no other definitions of this model already defined.
|
|
208
|
-
# Ensure appropriate folder(s) exists
|
|
209
|
-
m.directory model_test_path_name
|
|
210
|
-
#
|
|
211
|
-
model_filename = @class_name.snake_case
|
|
212
|
-
|
|
213
|
-
# Create stubs
|
|
214
|
-
m.template model_test_template_name,
|
|
215
|
-
"#{model_test_path_name}/#{model_filename}_#{model_test_file_suffix}.rb",
|
|
216
|
-
:assigns => {:class_name => @class_name}
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
protected
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def add_options!(opts)
|
|
224
|
-
# opts.separator ''
|
|
225
|
-
# opts.separator 'Options:'
|
|
226
|
-
# For each option below, place the default
|
|
227
|
-
# at the top of the file next to "default_options"
|
|
228
|
-
# opts.on("-a", "--author=\"Your Name\"", String,
|
|
229
|
-
# "Some comment about this option",
|
|
230
|
-
# "Default: none") { |options[:author]| }
|
|
231
|
-
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def extract_options
|
|
235
|
-
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
|
236
|
-
# Templates can access these value via the attr_reader-generated methods, but not the
|
|
237
|
-
# raw instance variable value.
|
|
238
|
-
# @author = options[:author]
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
# Pass the following options are available to this generatrs
|
|
243
|
-
class ControllerGeneratorBase < RubiGen::Base
|
|
244
|
-
|
|
245
|
-
default_options :author => nil
|
|
246
|
-
|
|
247
|
-
attr_reader :name, :class_name, :file_name
|
|
248
|
-
|
|
249
|
-
def initialize(runtime_args, runtime_options = {})
|
|
250
|
-
super
|
|
251
|
-
usage if args.empty?
|
|
252
|
-
@name = args.shift
|
|
253
|
-
@class_name = @name.camel_case #.pluralize
|
|
254
|
-
@file_name = @name.snake_case #.pluralize
|
|
255
|
-
@engine = runtime_options[:engine] || "erb" # set by subclasses only
|
|
256
|
-
@template_actions = runtime_options[:actions] || %w[index] # Used by subclasses only
|
|
257
|
-
@test_generator = runtime_options[:test_stub_generator] || "merb_controller_test"
|
|
258
|
-
@base_dest_folder = runtime_options[:base_dest_folder] || "app"
|
|
259
|
-
extract_options
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
def manifest
|
|
263
|
-
record do |m|
|
|
264
|
-
|
|
265
|
-
# ensure there are no other definitions of this model already defined.
|
|
266
|
-
m.class_collisions(@class_name)
|
|
267
|
-
|
|
268
|
-
m.directory "#{@base_dest_folder}/controllers"
|
|
269
|
-
m.template "controller.rb", "#{@base_dest_folder}/controllers/#{file_name}.rb", :assigns => {:actions => @template_actions}
|
|
270
|
-
|
|
271
|
-
m.directory "#{@base_dest_folder}/views/#{file_name}"
|
|
272
|
-
|
|
273
|
-
# Include templates if they exist
|
|
274
|
-
@template_actions.each do |the_action|
|
|
275
|
-
template_name = "#{the_action}.html.#{@engine}"
|
|
276
|
-
template_path = "/" + source_path(spec.name).split("/")[0..-2].join("/")
|
|
277
|
-
|
|
278
|
-
if File.exists?(File.join(template_path,template_name))
|
|
279
|
-
m.template template_name, "#{@base_dest_folder}/views/#{file_name}/#{template_name}"
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
m.directory "#{@base_dest_folder}/helpers/"
|
|
284
|
-
m.template "helper.rb", "#{@base_dest_folder}/helpers/#{file_name}_helper.rb"
|
|
285
|
-
m.dependency @test_generator, [name], :destination => destination_root, :template_actions => @template_actions
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
protected
|
|
290
|
-
def banner
|
|
291
|
-
<<-EOS
|
|
292
|
-
Creates a Merb controller
|
|
293
|
-
|
|
294
|
-
USAGE: #{$0} #{spec.name} name"
|
|
295
|
-
EOS
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
def add_options!(opts)
|
|
299
|
-
# opts.separator ''
|
|
300
|
-
# opts.separator 'Options:'
|
|
301
|
-
# For each option below, place the default
|
|
302
|
-
# at the top of the file next to "default_options"
|
|
303
|
-
# opts.on("-a", "--author=\"Your Name\"", String,
|
|
304
|
-
# "Some comment about this option",
|
|
305
|
-
# "Default: none") { |options[:author]| }
|
|
306
|
-
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def extract_options
|
|
310
|
-
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
|
311
|
-
# Templates can access these value via the attr_reader-generated methods, but not the
|
|
312
|
-
# raw instance variable value.
|
|
313
|
-
# @author = options[:author]
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
end
|
|
318
|
-
end
|