rad_core 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -3
- data/lib/components/config.rb +6 -0
- data/lib/components/controller.rb +5 -0
- data/lib/components/controller.yml +3 -0
- data/lib/components/conveyors.rb +7 -0
- data/lib/components/environment.rb +5 -0
- data/lib/components/environment.yml +3 -0
- data/lib/components/flash.rb +5 -0
- data/lib/components/html.rb +4 -0
- data/lib/components/html.yml +3 -0
- data/lib/components/http.rb +6 -0
- data/lib/components/http.yml +13 -0
- data/lib/components/logger.rb +5 -0
- data/lib/components/mailer.rb +9 -0
- data/lib/components/remote.rb +4 -0
- data/lib/components/router.rb +13 -0
- data/lib/components/router.yml +2 -0
- data/lib/components/template.rb +8 -0
- data/lib/components/template.yml +1 -0
- data/lib/components/web.rb +8 -0
- data/lib/components/workspace.rb +1 -0
- data/lib/rad/{support → _support}/active_support/locales/en/actionpack.yml +0 -0
- data/lib/rad/{support → _support}/active_support/locales/en/activesupport.yml +0 -0
- data/lib/rad/_support/active_support/locales/ru/actionview.yml +162 -0
- data/lib/rad/_support/active_support/locales/ru/activesupport.yml +16 -0
- data/lib/rad/_support/active_support/locales/ru/datetime.yml +49 -0
- data/lib/rad/{support → _support}/active_support/micelaneous.rb +0 -0
- data/lib/rad/{support → _support}/active_support/time.rb +0 -0
- data/lib/rad/{support → _support}/active_support.rb +14 -2
- data/lib/rad/{support → _support}/addressable.rb +0 -0
- data/lib/rad/_support/callbacks.rb +166 -0
- data/lib/rad/_support/class_loader.rb +9 -0
- data/lib/rad/_support/encoding.rb +3 -0
- data/lib/rad/_support/exception.rb +45 -0
- data/lib/rad/_support/extensions.rb +20 -0
- data/lib/rad/_support/filters.rb +32 -0
- data/lib/rad/{support → _support}/hacks_and_fixes.rb +0 -0
- data/lib/rad/{support → _support}/mime.rb +6 -0
- data/lib/rad/{support → _support}/module.rb +7 -9
- data/lib/rad/_support/require.rb +62 -0
- data/lib/rad/{support → _support}/rson.rb +0 -0
- data/lib/rad/{support → _support}/ruby_ext_with_active_support.rb +0 -0
- data/lib/rad/{support → _support}/string.rb +9 -1
- data/lib/rad/controller/_abstract/micelaneous.rb +27 -0
- data/lib/rad/controller/_abstract/render.rb +159 -0
- data/lib/rad/controller/_abstract/responder.rb +13 -0
- data/lib/rad/controller/_abstract.rb +37 -0
- data/lib/rad/controller/_context.rb +15 -0
- data/lib/rad/controller/_http.rb +50 -0
- data/lib/rad/controller/_require.rb +19 -0
- data/lib/rad/controller/abstract.rb +1 -0
- data/lib/rad/controller/context.rb +1 -0
- data/lib/rad/controller/http.rb +1 -0
- data/lib/rad/controller/processors/controller_caller.rb +22 -24
- data/lib/rad/controller/processors/controller_error_handling.rb +46 -48
- data/lib/rad/controller/processors/controller_logger.rb +7 -9
- data/lib/rad/controller.rb +1 -28
- data/lib/rad/conveyors/_conveyor.rb +73 -0
- data/lib/rad/conveyors/_conveyors.rb +19 -0
- data/lib/rad/conveyors/_params.rb +10 -0
- data/lib/rad/conveyors/_processor.rb +13 -0
- data/lib/rad/conveyors/_require.rb +10 -0
- data/lib/rad/conveyors/_workspace.rb +34 -0
- data/lib/rad/conveyors/params.rb +1 -0
- data/lib/rad/conveyors/processor.rb +1 -0
- data/lib/rad/conveyors/processors/conveyor_logger.rb +23 -0
- data/lib/rad/conveyors/workspace.rb +1 -0
- data/lib/rad/conveyors.rb +1 -0
- data/lib/rad/core_web/_controller_micelaneous_helper.rb +17 -0
- data/lib/rad/core_web/_require.rb +25 -0
- data/lib/rad/core_web/_router/abstract_routing_helper.rb +20 -0
- data/lib/rad/core_web/_router/controller_routing_helper.rb +56 -0
- data/lib/rad/core_web/_router/view_routing_helper.rb +57 -0
- data/lib/rad/environment/_config.rb +27 -0
- data/lib/rad/environment/_environment.rb +17 -0
- data/lib/rad/environment/_files_helper.rb +55 -0
- data/lib/rad/environment/_logger.rb +53 -0
- data/lib/rad/environment/_require.rb +24 -0
- data/lib/rad/environment/config.rb +1 -111
- data/lib/rad/environment.rb +1 -55
- data/lib/{rad_core → rad}/gems.rb +2 -3
- data/lib/rad/html/_flash.rb +40 -0
- data/lib/rad/html/_helpers/basic_html_helper.rb +72 -0
- data/lib/rad/html/_helpers/flash_helper.rb +3 -0
- data/lib/rad/html/_helpers/form_helper.rb +114 -0
- data/lib/rad/html/_helpers/html_helper.rb +3 -0
- data/lib/rad/html/_helpers/javascript_helper.rb +27 -0
- data/lib/rad/html/_helpers/model_helper.rb +143 -0
- data/lib/rad/html/_require.rb +15 -0
- data/lib/rad/html/processors/prepare_flash.rb +22 -23
- data/lib/rad/html/processors/scoped_params.rb +18 -21
- data/lib/rad/html.rb +1 -26
- data/lib/rad/http/_http.rb +11 -0
- data/lib/rad/http/_http_adapter.rb +44 -0
- data/lib/rad/http/_request.rb +50 -0
- data/lib/rad/http/_require.rb +33 -0
- data/lib/rad/http/_response.rb +84 -0
- data/lib/rad/http/{support → _support}/rack/fixes.rb +0 -0
- data/lib/rad/http/_support/rack/rack_adapter.rb +57 -0
- data/lib/rad/http/processors/evaluate_format.rb +16 -19
- data/lib/rad/http/processors/http_logger.rb +10 -12
- data/lib/rad/http/processors/http_writer.rb +24 -26
- data/lib/rad/http/processors/prepare_params.rb +19 -18
- data/lib/rad/http/request.rb +1 -0
- data/lib/rad/http/response.rb +1 -0
- data/lib/rad/http.rb +1 -48
- data/lib/rad/mailer/_letter.rb +28 -0
- data/lib/rad/mailer/_mailer.rb +13 -0
- data/lib/rad/mailer/_mailer_controller.rb +38 -0
- data/lib/rad/mailer/_require.rb +7 -0
- data/lib/rad/mailer/mailer_controller.rb +1 -0
- data/lib/rad/mailer/processors/letter_builder.rb +34 -0
- data/lib/rad/mailer.rb +1 -0
- data/lib/rad/profiles/mailer.rb +5 -0
- data/lib/rad/profiles/web.rb +29 -52
- data/lib/rad/remote/_remote_controller.rb +9 -0
- data/lib/rad/remote/_require.rb +6 -0
- data/lib/rad/remote/processors/remote_caller.rb +44 -46
- data/lib/rad/remote/processors/remote_logger.rb +8 -10
- data/lib/rad/remote/remote_controller.rb +1 -0
- data/lib/rad/remote.rb +1 -9
- data/lib/rad/router/_abstract_router.rb +50 -0
- data/lib/rad/router/_alias_router.rb +124 -0
- data/lib/rad/router/_basic_router.rb +72 -0
- data/lib/rad/router/_configurator.rb +19 -0
- data/lib/rad/router/_core_routing_helper.rb +39 -0
- data/lib/rad/router/_default_format_processor.rb +10 -0
- data/lib/rad/router/_object_router.rb +184 -0
- data/lib/rad/router/_require.rb +31 -0
- data/lib/rad/router/_restful_router.rb +124 -0
- data/lib/rad/router/_router.rb +294 -0
- data/lib/rad/router/_simple_router.rb +21 -0
- data/lib/rad/router/abstract_router.rb +1 -0
- data/lib/rad/router/alias_router.rb +1 -0
- data/lib/rad/router/configurator.rb +1 -0
- data/lib/rad/router/micelaneous_router.rb +1 -0
- data/lib/rad/router/object_router.rb +1 -0
- data/lib/rad/router/processors/router.rb +23 -0
- data/lib/rad/router/restful_router.rb +1 -0
- data/lib/rad/{html/include_into_controller.rb → router/simple_router.rb} +0 -0
- data/lib/rad/router.rb +1 -29
- data/lib/rad/spec/controller.rb +20 -11
- data/lib/rad/spec/environment.rb +22 -38
- data/lib/rad/spec/http.rb +13 -86
- data/lib/rad/spec/http_controller.rb +105 -0
- data/lib/rad/spec/mailer.rb +27 -0
- data/lib/rad/spec/remote.rb +2 -2
- data/lib/rad/spec/router.rb +9 -11
- data/lib/rad/spec/template.rb +8 -2
- data/lib/rad/spec/xhtml.rb +0 -2
- data/lib/rad/spec.rb +4 -2
- data/lib/rad/template/_context.rb +92 -0
- data/lib/rad/template/_relative_path_resolver.rb +8 -0
- data/lib/rad/template/_require.rb +15 -0
- data/lib/rad/template/{support → _support}/tilt.rb +0 -0
- data/lib/rad/template/{support → _support}/tilt_fixes.rb +0 -0
- data/lib/rad/template/_template.rb +175 -0
- data/lib/rad/template/template_context.rb +1 -62
- data/lib/rad/template.rb +1 -25
- data/lib/rad.rb +8 -0
- data/readme.md +40 -12
- data/spec/controller/{abstract_controller_spec → abstract_spec}/views/OperationsOrderSpec/action.erb +0 -0
- data/spec/controller/{abstract_controller_spec → abstract_spec}/views/ViewVariablesSpec/action.erb +0 -0
- data/spec/controller/abstract_spec.rb +126 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/NamespaceSpec/ClassSpec}/show.erb +0 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/actions.erb +0 -0
- data/spec/controller/{controller_context_spec/views/NamespaceSpec/ClassSpec → context_spec/views/item_spec}/show.erb +0 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/update.erb +0 -0
- data/spec/controller/{controller_context_spec → context_spec}/views/namespace_spec/class_spec/update.erb +0 -0
- data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/actions.erb +0 -0
- data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/show.erb +0 -0
- data/spec/controller/context_spec.rb +123 -0
- data/spec/controller/error_handling_spec.rb +21 -27
- data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperMethodSpec/action.erb +0 -0
- data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperSpec/action.erb +0 -0
- data/spec/controller/{controller_helper_spec.rb → helper_spec.rb} +7 -13
- data/spec/controller/{http_controller_spec.rb → http_spec.rb} +17 -23
- data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/custom_template.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AnotherActionSpec → render_spec/views/another_action_spec}/another_action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AnotherLayout → render_spec/views/another_layout}/action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/ForbidPartialAsActionSpec → render_spec/views/forbid_partial_as_action_spec}/_action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.html.erb +0 -0
- data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.js.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_with_layout.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_without_layout.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutSpec → render_spec/views/layout_spec}/action.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/admin.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.html.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.js.erb +0 -0
- data/spec/controller/{controller_render_spec/views/MultipleActions → render_spec/views/multiple_actions}/actions.haml +0 -0
- data/spec/controller/render_spec/views/relative_spec/a/form.erb +1 -0
- data/spec/controller/render_spec/views/relative_spec/a/show.erb +1 -0
- data/spec/controller/render_spec/views/relative_spec/b/form.erb +1 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/some_template.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/standalone.html.erb +0 -0
- data/spec/controller/{controller_render_spec.rb → render_spec.rb} +37 -27
- data/spec/{conveyor/conveyor_spec.rb → conveyors/conveyors_spec.rb} +36 -14
- data/spec/environment/config_spec.rb +13 -21
- data/spec/environment/environment_spec.rb +14 -41
- data/spec/environment/logger_spec.rb +4 -13
- data/spec/environment/minimal_app_spec/app.rb +1 -1
- data/spec/environment/minimal_app_spec.rb +12 -14
- data/spec/environment/standard_app_spec/app/lib/app/init.rb +1 -1
- data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -1
- data/spec/environment/standard_app_spec.rb +17 -25
- data/spec/html/basic_html_helper_spec.rb +7 -4
- data/spec/html/form_helper_spec.rb +5 -5
- data/spec/html/javascript_helper_spec.rb +9 -5
- data/spec/html/model_helper_spec.rb +9 -6
- data/spec/html/scoped_params_spec.rb +2 -2
- data/spec/html/spec_helper.rb +16 -24
- data/spec/http/http_spec.rb +14 -35
- data/spec/http/micelaneous_spec.rb +3 -3
- data/spec/{mail → mailer}/mail_controller_spec/views/body_template_spec/signup.erb +0 -0
- data/spec/{mail → mailer}/mail_controller_spec.rb +36 -12
- data/spec/mailer/spec_helper.rb +5 -0
- data/spec/remote/remote_spec.rb +23 -8
- data/spec/router/alias_router_spec.rb +29 -30
- data/spec/router/basic_router_spec.rb +44 -0
- data/spec/router/configurator_spec.rb +9 -6
- data/spec/router/integration_spec.rb +10 -7
- data/spec/router/object_router_spec.rb +186 -0
- data/spec/router/persistent_params_spec.rb +4 -4
- data/spec/router/restful_router_spec.rb +61 -53
- data/spec/router/{basic_spec.rb → router_spec.rb} +26 -23
- data/spec/router/routing_helper_spec.rb +5 -6
- data/spec/spec_helper.rb +4 -0
- data/spec/support/callbacks_spec.rb +1 -1
- data/spec/support/filters_spec.rb +2 -2
- data/spec/support/spec_helper.rb +1 -1
- data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -1
- data/spec/template/template_spec/views/nested/format/a.erb +1 -1
- data/spec/template/template_spec/views/nested/format/b.js.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -1
- data/spec/template/template_spec.rb +62 -48
- data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -1
- data/spec/template/tilt_spec/views/concat_and_capture.haml +1 -1
- data/spec/template/tilt_spec.rb +17 -19
- data/spec/{integration → web}/basic_spec/views/smoke_test_spec/action.erb +0 -0
- data/spec/{integration → web}/basic_spec.rb +31 -12
- data/spec/{integration → web}/controller_routing_helper_spec.rb +13 -11
- data/spec/{integration → web}/flash_spec.rb +57 -42
- data/spec/{integration → web}/spec_helper_spec.rb +11 -10
- data/spec/{integration → web}/view_routing_helper_spec.rb +44 -36
- metadata +338 -318
- data/lib/rad/controller/abstract_controller/micelaneous.rb +0 -31
- data/lib/rad/controller/abstract_controller/render.rb +0 -160
- data/lib/rad/controller/abstract_controller/responder.rb +0 -17
- data/lib/rad/controller/abstract_controller.rb +0 -64
- data/lib/rad/controller/controller_context.rb +0 -15
- data/lib/rad/controller/http_controller.rb +0 -48
- data/lib/rad/conveyor/conveyor.rb +0 -74
- data/lib/rad/conveyor/conveyors.rb +0 -20
- data/lib/rad/conveyor/params.rb +0 -14
- data/lib/rad/conveyor/processor.rb +0 -68
- data/lib/rad/conveyor/processors/conveyor_logger.rb +0 -25
- data/lib/rad/conveyor/workspace.rb +0 -36
- data/lib/rad/conveyor.rb +0 -29
- data/lib/rad/environment/dependency_resolver.rb +0 -107
- data/lib/rad/environment/environment.rb +0 -29
- data/lib/rad/environment/files_helper.rb +0 -55
- data/lib/rad/environment/logger.rb +0 -21
- data/lib/rad/html/flash.rb +0 -42
- data/lib/rad/html/helpers/basic_html_helper.rb +0 -83
- data/lib/rad/html/helpers/flash_helper.rb +0 -5
- data/lib/rad/html/helpers/form_helper.rb +0 -115
- data/lib/rad/html/helpers/html_helper.rb +0 -5
- data/lib/rad/html/helpers/javascript_helper.rb +0 -18
- data/lib/rad/html/helpers/model_helper.rb +0 -135
- data/lib/rad/http/http.rb +0 -21
- data/lib/rad/http/http_adapter.rb +0 -36
- data/lib/rad/http/middleware/static_files.rb +0 -21
- data/lib/rad/http/support/rack/rack_adapter.rb +0 -67
- data/lib/rad/http/support/rack/request.rb +0 -42
- data/lib/rad/http/support/rack/response.rb +0 -86
- data/lib/rad/integration/controller_micelaneous_helper.rb +0 -19
- data/lib/rad/integration/router/abstract_routing_helper.rb +0 -22
- data/lib/rad/integration/router/controller_routing_helper.rb +0 -58
- data/lib/rad/integration/router/view_routing_helper.rb +0 -104
- data/lib/rad/integration.rb +0 -30
- data/lib/rad/mail/letter.rb +0 -30
- data/lib/rad/mail/mail_controller.rb +0 -31
- data/lib/rad/mail/mailer.rb +0 -23
- data/lib/rad/mail/processors/letter_builder.rb +0 -36
- data/lib/rad/mail.rb +0 -15
- data/lib/rad/profiles/mail.rb +0 -16
- data/lib/rad/profiles/web_require.rb +0 -5
- data/lib/rad/remote/remote.rb +0 -15
- data/lib/rad/router/core/configurator.rb +0 -25
- data/lib/rad/router/core/core_routing_helper.rb +0 -41
- data/lib/rad/router/core/default_format_processor.rb +0 -12
- data/lib/rad/router/core/processors/router.rb +0 -29
- data/lib/rad/router/core/router.rb +0 -271
- data/lib/rad/router/core/simple_router.rb +0 -23
- data/lib/rad/router/routers/abstract_router.rb +0 -62
- data/lib/rad/router/routers/alias_router.rb +0 -113
- data/lib/rad/router/routers/restful_router.rb +0 -113
- data/lib/rad/spec/mail.rb +0 -31
- data/lib/rad/spec/view.rb +0 -10
- data/lib/rad/support/buffered_logger.rb +0 -44
- data/lib/rad/support/callbacks.rb +0 -168
- data/lib/rad/support/exception.rb +0 -31
- data/lib/rad/support/filters.rb +0 -34
- data/lib/rad/support/format.rb +0 -17
- data/lib/rad/support/micon.rb +0 -13
- data/lib/rad/support.rb +0 -63
- data/lib/rad/template/template.rb +0 -250
- data/spec/controller/abstract_controller_spec.rb +0 -132
- data/spec/controller/controller_context_spec.rb +0 -123
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +0 -1
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +0 -1
- data/spec/controller/spec_helper.rb +0 -19
- data/spec/conveyor/spec_helper.rb +0 -3
- data/spec/environment/config_spec/config.default.yml +0 -3
- data/spec/environment/config_spec/config.development.yml +0 -3
- data/spec/environment/config_spec/config.yml +0 -5
- data/spec/environment/spec_helper.rb +0 -1
- data/spec/http/http_spec/app/lib/app/init.rb +0 -10
- data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
- data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
- data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +0 -5
- data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
- data/spec/http/spec_helper.rb +0 -5
- data/spec/integration/spec_helper.rb +0 -5
- data/spec/mail/spec_helper.rb +0 -7
- data/spec/remote/spec_helper.rb +0 -17
- data/spec/router/spec_helper.rb +0 -20
- data/spec/template/spec_helper.rb +0 -6
- data/spec/template/template_spec/views/nested/format/b.erb +0 -1
@@ -0,0 +1,184 @@
|
|
1
|
+
class Rad::Router::ObjectRouter
|
2
|
+
include Rad::Router::AbstractRouter
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.class_to_resource = -> klass {raise ':class_to_resource not specified!'}
|
6
|
+
self.resource_to_class = -> resource {raise ':resource_to_class not specified!'}
|
7
|
+
self.id_to_class = -> id, params {raise ':id_to_class not specified!'}
|
8
|
+
|
9
|
+
self.default_class_method = :all
|
10
|
+
self.default_object_method = :show
|
11
|
+
|
12
|
+
@cached_class_to_resource, @cached_resource_to_class = {}, {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure options = {}
|
16
|
+
raise "can't configure ObjectRouter twice!" if configured?
|
17
|
+
self.configured = true
|
18
|
+
|
19
|
+
# parsing options
|
20
|
+
options.validate_options! :default_class_name, :class_to_resource, :resource_to_class, :id_to_class, :url_root, :prefix
|
21
|
+
|
22
|
+
self.default_class_name = options[:default_class_name] || raise(':default_class_name not provided!')
|
23
|
+
|
24
|
+
self.class_to_resource = options[:class_to_resource] if options.include? :class_to_resource
|
25
|
+
self.resource_to_class = options[:resource_to_class] if options.include? :resource_to_class
|
26
|
+
self.id_to_class = options[:id_to_class] if options.include? :id_to_class
|
27
|
+
|
28
|
+
self.url_root = parse_url_root options
|
29
|
+
self.prefix = parse_prefix options
|
30
|
+
end
|
31
|
+
|
32
|
+
def encode klass, method, params
|
33
|
+
return nil unless configured?
|
34
|
+
|
35
|
+
id = params[:id]
|
36
|
+
|
37
|
+
# id and resource
|
38
|
+
path = if id
|
39
|
+
raise ":id can be used with :default_class only (#{klass}, '#{id}')!" if klass != default_class
|
40
|
+
|
41
|
+
params.delete :id
|
42
|
+
raise ":id must not start from capital letter ('#{id}')!" if id =~ /^[A-Z]/
|
43
|
+
|
44
|
+
path = if !method or method == default_object_method
|
45
|
+
"/#{id}"
|
46
|
+
else
|
47
|
+
"/#{id}/#{method}"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
resource = cached_class_to_resource klass
|
51
|
+
raise "no resource for #{klass}!" unless resource
|
52
|
+
raise "resource must start from capital letter (class: #{klass}, resource: '#{resource}')!" unless resource =~ /^[A-Z]/
|
53
|
+
|
54
|
+
path = if !method or method == default_class_method
|
55
|
+
"/#{resource}"
|
56
|
+
else
|
57
|
+
"/#{resource}/#{method}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# prefix
|
62
|
+
path = encode_prefix_params! path, params, prefix if prefix
|
63
|
+
|
64
|
+
# url_root
|
65
|
+
params[:url_root] = url_root if url_root
|
66
|
+
|
67
|
+
[path, params]
|
68
|
+
end
|
69
|
+
|
70
|
+
def decode path, params
|
71
|
+
return nil unless configured?
|
72
|
+
|
73
|
+
parts = path[1..-1].split('/')
|
74
|
+
|
75
|
+
# checking 'size' of path
|
76
|
+
extra_size = (prefix ? prefix.size : 0) + (url_root ? 1 : 0)
|
77
|
+
valid_range = (1 + extra_size)..(2 + extra_size)
|
78
|
+
raise "invalid 'size' of path, must be in #{valid_range}!" unless valid_range.include? parts.size
|
79
|
+
|
80
|
+
# url_root
|
81
|
+
if url_root
|
82
|
+
raise "invalid :url_root ('/#{parts.first}' should be equal to '#{url_root}')!" unless "/#{parts.first}" == url_root
|
83
|
+
parts.shift
|
84
|
+
end
|
85
|
+
|
86
|
+
# prefix
|
87
|
+
decode_prefix_params! parts, params, prefix if prefix
|
88
|
+
|
89
|
+
# id, resource and method
|
90
|
+
if parts.first =~ /^[A-Z]/
|
91
|
+
resource, method = parts
|
92
|
+
method ||= default_class_method
|
93
|
+
method = method.to_sym
|
94
|
+
|
95
|
+
raise "resource must be in plural form ('#{resource}')!" unless resource.pluralize == resource
|
96
|
+
|
97
|
+
klass = cached_resource_to_class resource
|
98
|
+
|
99
|
+
raise "no class for '#{resource}' resource!" unless klass
|
100
|
+
else
|
101
|
+
id, method = parts
|
102
|
+
|
103
|
+
method ||= default_object_method
|
104
|
+
method = method.to_sym
|
105
|
+
|
106
|
+
# sometimes we need params inside of :id_to_class block,
|
107
|
+
# for example to find out Space before finding Item
|
108
|
+
klass = id_to_class.call id, params
|
109
|
+
|
110
|
+
raise "no class for '#{id}' id!" unless klass
|
111
|
+
|
112
|
+
params[:id] = id
|
113
|
+
end
|
114
|
+
|
115
|
+
klass.must_be.a Class
|
116
|
+
return klass, method, params
|
117
|
+
end
|
118
|
+
|
119
|
+
def encode_method route_method, has_id
|
120
|
+
return nil unless configured?
|
121
|
+
|
122
|
+
token = route_method.sub(/_?path$/, '')
|
123
|
+
|
124
|
+
if has_id
|
125
|
+
method = token.empty? ? default_object_method : token
|
126
|
+
method = method.to_sym
|
127
|
+
|
128
|
+
return [default_class, method]
|
129
|
+
else
|
130
|
+
token = route_method.sub(/_path$/, '')
|
131
|
+
parts = token.split '_'
|
132
|
+
resource = parts.pop
|
133
|
+
method = parts.empty? ? default_class_method : parts.join('_')
|
134
|
+
|
135
|
+
# class
|
136
|
+
resource = resource.pluralize.camelize
|
137
|
+
klass = cached_resource_to_class resource
|
138
|
+
raise "no class for '#{resource}' resource!" unless klass
|
139
|
+
klass.must_be.a Class
|
140
|
+
|
141
|
+
# method
|
142
|
+
method = method.to_sym if method
|
143
|
+
|
144
|
+
return [klass, method]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
protected
|
149
|
+
attr_accessor :class_to_resource, :resource_to_class, :id_to_class, :default_class_method, :default_object_method,
|
150
|
+
:prefix, :url_root, :configured, :default_class_name
|
151
|
+
|
152
|
+
def default_class
|
153
|
+
@default_class ||= default_class_name.constantize
|
154
|
+
end
|
155
|
+
|
156
|
+
def configured?; !!@configured end
|
157
|
+
|
158
|
+
def cached_class_to_resource klass
|
159
|
+
unless @cached_class_to_resource.include? klass
|
160
|
+
resource = class_to_resource.call klass
|
161
|
+
resource.must_not =~ /\//
|
162
|
+
raise 'resource name must be in plural form' unless resource.pluralize == resource
|
163
|
+
@cached_class_to_resource[klass] = resource
|
164
|
+
end
|
165
|
+
@cached_class_to_resource[klass]
|
166
|
+
end
|
167
|
+
|
168
|
+
def cached_resource_to_class resource
|
169
|
+
unless @cached_resource_to_class.include? resource
|
170
|
+
klass = resource_to_class.call resource
|
171
|
+
@cached_resource_to_class[resource] = klass
|
172
|
+
end
|
173
|
+
@cached_resource_to_class[resource]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
Rad::Router::Configurator.class_eval do
|
179
|
+
def objects *args, &block
|
180
|
+
object_router = @router.routers[:object_router]
|
181
|
+
raise "There's no ObjectRouter (use config to add it)!" unless object_router
|
182
|
+
object_router.configure *args, &block
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Rad::Router
|
2
|
+
end
|
3
|
+
|
4
|
+
#
|
5
|
+
# Libraries
|
6
|
+
#
|
7
|
+
%w(
|
8
|
+
_configurator
|
9
|
+
_simple_router
|
10
|
+
_router
|
11
|
+
_default_format_processor
|
12
|
+
|
13
|
+
_core_routing_helper
|
14
|
+
).each{|f| require "rad/router/#{f}"}
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# Routers
|
19
|
+
#
|
20
|
+
%w(
|
21
|
+
_abstract_router
|
22
|
+
_basic_router
|
23
|
+
_alias_router
|
24
|
+
_restful_router
|
25
|
+
_object_router
|
26
|
+
).each{|f| require "rad/router/#{f}"}
|
27
|
+
|
28
|
+
|
29
|
+
#
|
30
|
+
# Helpers
|
31
|
+
#
|
@@ -0,0 +1,124 @@
|
|
1
|
+
class Rad::Router::RestfulRouter
|
2
|
+
include Rad::Router::AbstractRouter
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@resources, @class_names = {}, {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def add resource, options = {}
|
9
|
+
# parsing options
|
10
|
+
options.validate_options! :class_name, :url_root, :prefix
|
11
|
+
resource = resource.to_s
|
12
|
+
resource.must_not =~ /\//
|
13
|
+
raise "resource should be in plural form!" unless resource.pluralize == resource
|
14
|
+
class_name = options.delete(:class_name) || raise("no class name!")
|
15
|
+
class_name.must_be.a String
|
16
|
+
url_root = parse_url_root options
|
17
|
+
prefix = parse_prefix options
|
18
|
+
|
19
|
+
# logic
|
20
|
+
meta = Meta.new
|
21
|
+
meta.merge!(
|
22
|
+
class_name: class_name,
|
23
|
+
resource: resource,
|
24
|
+
url_root: url_root,
|
25
|
+
prefix: prefix
|
26
|
+
)
|
27
|
+
|
28
|
+
resources.must_not.include(resource.pluralize)
|
29
|
+
class_names.must_not.include(class_name)
|
30
|
+
resources[resource.pluralize] = meta
|
31
|
+
resources[resource.singularize] = meta
|
32
|
+
class_names[class_name] = meta
|
33
|
+
end
|
34
|
+
|
35
|
+
def encode klass, method, params
|
36
|
+
meta = class_names[klass.name]
|
37
|
+
return nil unless meta
|
38
|
+
|
39
|
+
path = if id = params.delete(:id)
|
40
|
+
"/#{meta[:resource]}/#{id}/#{method}"
|
41
|
+
else
|
42
|
+
"/#{meta[:resource]}/#{method}"
|
43
|
+
end
|
44
|
+
|
45
|
+
prefix = meta[:prefix]
|
46
|
+
path = encode_prefix_params! path, params, prefix if prefix
|
47
|
+
|
48
|
+
url_root = meta[:url_root]
|
49
|
+
params[:url_root] = url_root if url_root
|
50
|
+
|
51
|
+
[path, params]
|
52
|
+
end
|
53
|
+
|
54
|
+
def decode path, params
|
55
|
+
decode_as_object_resource(path, params) || decode_as_static_resource(path, params)
|
56
|
+
end
|
57
|
+
|
58
|
+
def encode_method route_method, has_id
|
59
|
+
token = route_method.sub(/_path$/, '')
|
60
|
+
|
61
|
+
resources.each do |name, meta|
|
62
|
+
if i = token.rindex(name)
|
63
|
+
route_method.size == i + name.size and route_method[(i-1)..(i-1)] == '_'
|
64
|
+
return meta.get_class, route_method[0..(i-2)].to_sym
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return nil
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
attr_accessor :resources, :class_names
|
73
|
+
|
74
|
+
def decode_as_object_resource path, params
|
75
|
+
parts = path[1..-1].split('/')
|
76
|
+
return nil unless parts.size >= 3
|
77
|
+
|
78
|
+
method, id, resource = parts.pop.to_sym, parts.pop, parts.pop
|
79
|
+
meta = resources[resource]
|
80
|
+
return nil unless meta
|
81
|
+
|
82
|
+
# url_root
|
83
|
+
url_root = meta[:url_root]
|
84
|
+
return nil if url_root and "/#{parts.shift}" != url_root
|
85
|
+
|
86
|
+
# prefix
|
87
|
+
return nil if parts.size != (meta[:prefix] ? meta[:prefix].size : 0)
|
88
|
+
prefix = meta[:prefix]
|
89
|
+
decode_prefix_params! parts, params, prefix if prefix
|
90
|
+
|
91
|
+
params[:id] = id
|
92
|
+
|
93
|
+
return meta.get_class, method, params
|
94
|
+
end
|
95
|
+
|
96
|
+
def decode_as_static_resource path, params
|
97
|
+
parts = path[1..-1].split('/')
|
98
|
+
return nil unless parts.size >= 2
|
99
|
+
|
100
|
+
# method & class
|
101
|
+
method, resource = parts.pop.to_sym, parts.pop
|
102
|
+
meta = resources[resource]
|
103
|
+
return nil unless meta
|
104
|
+
|
105
|
+
# url_root
|
106
|
+
url_root = meta[:url_root]
|
107
|
+
return nil if url_root and "/#{parts.shift}" != url_root
|
108
|
+
|
109
|
+
# prefix
|
110
|
+
return nil if parts.size != (meta[:prefix] ? meta[:prefix].size : 0)
|
111
|
+
prefix = meta[:prefix]
|
112
|
+
decode_prefix_params! parts, params, prefix if prefix
|
113
|
+
|
114
|
+
return meta.get_class, method, params
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
Rad::Router::Configurator.class_eval do
|
119
|
+
def resource *args, &block
|
120
|
+
restful_router = @router.routers[:restful_router]
|
121
|
+
raise "There's no RestfulRouter (use config to add it)!" unless restful_router
|
122
|
+
restful_router.add *args, &block
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
class Rad::Router
|
2
|
+
inject workspace: :workspace
|
3
|
+
|
4
|
+
attr_reader :routers, :format_processor
|
5
|
+
attr_accessor :default_path, :default_method
|
6
|
+
|
7
|
+
def initialize (
|
8
|
+
class_variable = :class,
|
9
|
+
routers = [[:default_router, Rad::Router::SimpleRouter.new]],
|
10
|
+
format_processor = Rad::Router::DefaultFormatProcessor.new
|
11
|
+
)
|
12
|
+
@class_variable, @format_processor = class_variable, format_processor
|
13
|
+
self.routers = routers
|
14
|
+
end
|
15
|
+
|
16
|
+
def routers= routers
|
17
|
+
@routers = Dictionary.new
|
18
|
+
routers.each do |k, v|
|
19
|
+
k.must_be.present
|
20
|
+
v.must_be.present
|
21
|
+
v.must.respond_to(:decode)
|
22
|
+
v.must.respond_to(:encode)
|
23
|
+
|
24
|
+
self.routers[k] = v
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def url_for *args
|
29
|
+
if args.first.is_a?(Class)
|
30
|
+
args.size.must_be.in 2..3
|
31
|
+
klass, method, options = args
|
32
|
+
url_for_class(klass, method, (options || {}))
|
33
|
+
else
|
34
|
+
first = args.first.to_s
|
35
|
+
if first =~ /^\//
|
36
|
+
args.size.must_be.in 1..2
|
37
|
+
path, options = args
|
38
|
+
url_for_path(path, (options || {}))
|
39
|
+
# elsif full_url? first
|
40
|
+
# args.size.must == 1
|
41
|
+
# return first
|
42
|
+
elsif first =~ /^http:\/\//
|
43
|
+
args.size.must_be.in 1..2
|
44
|
+
raise "can't use option with full url (#{first})" if args.size == 2 and !args.last.blank?
|
45
|
+
first
|
46
|
+
else
|
47
|
+
args.size.must_be.in 1..2
|
48
|
+
method, options = args
|
49
|
+
url_for_class(nil, method, (options || {}))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def decode path, params
|
55
|
+
path.first.must == '/'
|
56
|
+
# params = params.to_openobject
|
57
|
+
|
58
|
+
path, format = format_processor.remove_format path if format_processor
|
59
|
+
|
60
|
+
result = nil
|
61
|
+
routers.each do |name, route|
|
62
|
+
result = route.decode path, params
|
63
|
+
break if result
|
64
|
+
end
|
65
|
+
|
66
|
+
raise "no route for '#{safe_workspace.path}' request!" unless result
|
67
|
+
|
68
|
+
klass, method, params = result
|
69
|
+
method ||= default_method
|
70
|
+
params.must_be.defined
|
71
|
+
method.must_be.a Symbol
|
72
|
+
|
73
|
+
raise "invalid route! No method '#{method}' for #{klass}!" unless klass.instance_methods.include? method
|
74
|
+
raise "invalid route! You try to call protected method '#{method}' for '#{path}'!" unless klass.public_instance_methods.include? method
|
75
|
+
|
76
|
+
return klass, method, params
|
77
|
+
end
|
78
|
+
|
79
|
+
def encode klass, method, params = {}
|
80
|
+
klass.must_be.defined
|
81
|
+
method.must_be.a Symbol
|
82
|
+
params = params.clone
|
83
|
+
# method, params = method, params.to_openobject
|
84
|
+
|
85
|
+
format = params.delete(:format)
|
86
|
+
|
87
|
+
# raise "Invalid route! No method '#{method}' for #{klass}!" unless klass.method_defined? method
|
88
|
+
# raise "Invalid route! You try to call protected method '#{method}' for '#{klass}'!" unless klass.method_defined? method
|
89
|
+
|
90
|
+
inject_persistent_params! params
|
91
|
+
|
92
|
+
result = nil
|
93
|
+
routers.each do |name, route|
|
94
|
+
result = route.encode klass, method, params
|
95
|
+
break if result
|
96
|
+
end
|
97
|
+
|
98
|
+
raise "no route for '#{klass}.#{method}'!" unless result
|
99
|
+
|
100
|
+
path, params = result
|
101
|
+
path.must_be.defined
|
102
|
+
params.must_be.defined
|
103
|
+
|
104
|
+
path = format_processor.add_format path, format if format_processor and format
|
105
|
+
|
106
|
+
return path, params
|
107
|
+
end
|
108
|
+
|
109
|
+
def encode_method route_method, has_id
|
110
|
+
# method = method
|
111
|
+
route_method.must_be.present
|
112
|
+
|
113
|
+
result = nil
|
114
|
+
routers.each do |name, route|
|
115
|
+
result = route.respond_to :encode_method, route_method, has_id
|
116
|
+
break if result
|
117
|
+
end
|
118
|
+
|
119
|
+
raise "no route for '#{route_method}' route method!" unless result
|
120
|
+
|
121
|
+
klass, method = result
|
122
|
+
klass.must_be.defined
|
123
|
+
method.must_be.defined
|
124
|
+
method.must =~ /^[_a-zA-Z0-9]+$/
|
125
|
+
|
126
|
+
return [klass, method]
|
127
|
+
end
|
128
|
+
cache_method_with_params_in_production :encode_method
|
129
|
+
|
130
|
+
def persist_params &block
|
131
|
+
if block
|
132
|
+
before = safe_workspace.persist_params?
|
133
|
+
begin
|
134
|
+
safe_workspace[:persist_params] = true
|
135
|
+
block.call
|
136
|
+
ensure
|
137
|
+
safe_workspace.delete :persist_params unless before
|
138
|
+
end
|
139
|
+
else
|
140
|
+
safe_workspace[:persist_params] = true
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def dont_persist_params &block
|
145
|
+
if block
|
146
|
+
before = safe_workspace.persist_params?
|
147
|
+
begin
|
148
|
+
safe_workspace.delete :persist_params
|
149
|
+
block.call
|
150
|
+
ensure
|
151
|
+
safe_workspace[:persist_params] = true if before
|
152
|
+
end
|
153
|
+
else
|
154
|
+
safe_workspace.delete :persist_params
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def persist_params?
|
159
|
+
safe_workspace.persist_params?
|
160
|
+
end
|
161
|
+
|
162
|
+
def persistent_params; @persistent_params ||= [] end
|
163
|
+
|
164
|
+
def url_for_path path, params
|
165
|
+
# if full_url? path
|
166
|
+
# params.must_be.blank
|
167
|
+
# return path
|
168
|
+
# end
|
169
|
+
|
170
|
+
# params = params.to_openobject
|
171
|
+
|
172
|
+
|
173
|
+
# url_root = params.include?(:url_root) ? params.delete(:url_root) : config.url_root!
|
174
|
+
# if !url_root or url_root == '/'
|
175
|
+
# url = path.clone
|
176
|
+
# else
|
177
|
+
# url = url_root + path
|
178
|
+
# end
|
179
|
+
|
180
|
+
# url_root
|
181
|
+
url_root = params.delete(:url_root)
|
182
|
+
url = (url_root && url_root != '/') ? url_root + path : path.clone
|
183
|
+
|
184
|
+
# host port
|
185
|
+
host, port = params.delete(:host), params.delete(:port)
|
186
|
+
format = params.delete(:format)
|
187
|
+
|
188
|
+
# json
|
189
|
+
params = {json: params.to_json} if params.delete :as_json #and !params.empty?
|
190
|
+
|
191
|
+
# format
|
192
|
+
if format
|
193
|
+
params[:format] = format
|
194
|
+
url.marks.format = format.to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
# Delete 'nil' parameters
|
198
|
+
to_delete = []
|
199
|
+
params.each{|k, v| to_delete << k if v.nil?}
|
200
|
+
to_delete.each{|k| params.delete k}
|
201
|
+
|
202
|
+
# build url
|
203
|
+
delimiter = path.include?('?') ? '&' : '?'
|
204
|
+
url << "#{delimiter}#{params.to_query}" unless params.empty?
|
205
|
+
|
206
|
+
if host.blank?
|
207
|
+
url
|
208
|
+
else
|
209
|
+
%{http://#{host}#{":#{port}" unless port.blank?}#{url}}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def url_for_class klass, method, params
|
214
|
+
klass ||= current_class
|
215
|
+
# params = params.to_openobject
|
216
|
+
|
217
|
+
# special params
|
218
|
+
format = params[:format]
|
219
|
+
|
220
|
+
path, params = encode klass, method, params
|
221
|
+
url = url_for_path path, params
|
222
|
+
|
223
|
+
url.marks.format = format.to_s if format
|
224
|
+
|
225
|
+
url
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
#
|
230
|
+
# public helpers for :router component
|
231
|
+
#
|
232
|
+
delegate :configure, to: Rad::Router::Configurator
|
233
|
+
|
234
|
+
protected
|
235
|
+
# def full_url? url
|
236
|
+
# url =~ /[a-z0-9]+:\/\//
|
237
|
+
# end
|
238
|
+
|
239
|
+
# sometimes we need access to routers outside of conveyor :cycle,
|
240
|
+
# for example in spec routing helpers, in that case we just ignore workspace and it's variables
|
241
|
+
def safe_workspace
|
242
|
+
if rad.active? :cycle
|
243
|
+
workspace
|
244
|
+
else
|
245
|
+
Rad::Conveyors::Workspace.new
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def current_class; safe_workspace[@class_variable] end
|
250
|
+
|
251
|
+
DONOT_PERSIST = [:_, :_method, :_target]
|
252
|
+
|
253
|
+
def inject_persistent_params! params
|
254
|
+
persist = params.delete(:persist)
|
255
|
+
|
256
|
+
# global persistent params
|
257
|
+
unless cached_global_persistend_params = safe_workspace.cached_global_persistend_params
|
258
|
+
cached_global_persistend_params, workspace_params = {}, safe_workspace.params
|
259
|
+
if workspace_params
|
260
|
+
persistent_params.collect!{|k| k}
|
261
|
+
|
262
|
+
workspace_params.each do |k, v|
|
263
|
+
cached_global_persistend_params[k] = v if persistent_params.include?(k)
|
264
|
+
end
|
265
|
+
|
266
|
+
safe_workspace.cached_global_persistend_params = cached_global_persistend_params
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
cached_global_persistend_params.each do |k, v|
|
271
|
+
params[k] = v unless params.include? k
|
272
|
+
end
|
273
|
+
|
274
|
+
# underscored persistent params
|
275
|
+
if persist_params?
|
276
|
+
unless cached_persistend_params = safe_workspace.cached_persistend_params
|
277
|
+
cached_persistend_params, workspace_params = {}, safe_workspace.params
|
278
|
+
|
279
|
+
if workspace_params
|
280
|
+
workspace_params.each do |k, v|
|
281
|
+
cached_persistend_params[k] = v if (k =~ /^_/) and !DONOT_PERSIST.include?(k)
|
282
|
+
end
|
283
|
+
|
284
|
+
safe_workspace.cached_persistend_params = cached_persistend_params
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
cached_persistend_params.each do |k, v|
|
289
|
+
params[k] = v unless params.include? k
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Rad::Router::SimpleRouter
|
2
|
+
inject logger: :logger
|
3
|
+
|
4
|
+
def encode klass, method, params
|
5
|
+
path = "/#{klass.name.underscore}/#{method}"
|
6
|
+
return path, params
|
7
|
+
end
|
8
|
+
|
9
|
+
def decode path, params
|
10
|
+
parts = path[1..-1].split '/'
|
11
|
+
if parts.size >= 2
|
12
|
+
method = parts.pop.to_sym
|
13
|
+
|
14
|
+
class_path = parts.join('/')
|
15
|
+
class_name = class_path.camelize
|
16
|
+
klass = class_name.constantize
|
17
|
+
|
18
|
+
return klass, method, params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
@@ -0,0 +1,23 @@
|
|
1
|
+
rad.router
|
2
|
+
|
3
|
+
class Router < Rad::Conveyors::Processor
|
4
|
+
inject router: :router
|
5
|
+
|
6
|
+
def initialize next_processor, class_variable = :class, method_variable = :method
|
7
|
+
super(next_processor)
|
8
|
+
@class_variable, @method_variable = class_variable, method_variable
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
halt = catch :halt do
|
13
|
+
if workspace[@class_variable].blank? or workspace[@method_variable].blank?
|
14
|
+
klass, method, params = router.decode workspace.path, workspace.params
|
15
|
+
workspace[@class_variable], workspace[@method_variable], workspace.params = klass, method, params
|
16
|
+
end
|
17
|
+
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
next_processor.call unless halt
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.router
|
File without changes
|