Module: Jets::Router::Compat::RouteSet
- Included in:
- RouteSet
- Defined in:
- lib/jets/router/compat/route_set.rb
Overview
Related:
Jets::Controller::Compat::ActionDispatch::Routing::UrlFor
Jets::Controller::Request::Compat::RouteSet
Jets::Router::Compat::RouteSet
Compat::RouteSet makes the Jets::Router::RouteSet “compatible” with the Rails RouteSet. Importantly, it provides a custom url_for method that mimics the Rails url_for method.
Defined Under Namespace
Classes: Generator, RouteWithParams
Constant Summary collapse
- RESERVED_OPTIONS =
Original: RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name, :original_script_name, :relative_url_root]
UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }
ActionDispatch::Routing::RouteSet::RESERVED_OPTIONS
- UNKNOWN =
ActionDispatch::Routing::RouteSet::UNKNOWN
Instance Method Summary collapse
-
#mounted_helpers ⇒ Object
interface method.
-
#polymorphic_mappings ⇒ Object
This is only used for Custom resolve polymporphic path support Stub out.
-
#url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil, reserved = RESERVED_OPTIONS) ⇒ Object
This method is a version of the Rails RouteSet#url_for method.
Instance Method Details
#mounted_helpers ⇒ Object
interface method
112 113 114 |
# File 'lib/jets/router/compat/route_set.rb', line 112 def mounted_helpers Module.new end |
#polymorphic_mappings ⇒ Object
This is only used for Custom resolve polymporphic path support Stub out. Jets does not currently support this. interface method
93 94 95 |
# File 'lib/jets/router/compat/route_set.rb', line 93 def polymorphic_mappings {} end |
#url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil, reserved = RESERVED_OPTIONS) ⇒ Object
This method is a version of the Rails RouteSet#url_for method. It only resolves simple routes for simple cases:
when nil
when Hash, ActionController::Parameters
This is because ActionDispatch::Routing::UrlFor#url_for gets called before and then calls out to this method. Only have to account for 2 cases to mimic Jets behavior.
Based on Jets ActionDispatch::Routing::RouteSet#url_for
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jets/router/compat/route_set.rb', line 34 def url_for(, route_name = nil, url_strategy = UNKNOWN, method_name = nil, reserved = RESERVED_OPTIONS) user = password = nil if [:user] && [:password] user = .delete :user password = .delete :password end # save recall_controller for url_options when controller not specified by user # IE: redirect_to action: :routes recall_controller = [:_recall][:controller] recall = .delete(:_recall) { {} } original_script_name = .delete(:original_script_name) # script_name = find_script_name options (original) script_name = .delete(:script_name) if original_script_name script_name = original_script_name + script_name end = .dup reserved.each { |ro| .delete ro } [:controller] ||= recall_controller route_with_params = generate(route_name, , recall) path = route_with_params.path(method_name) if [:trailing_slash] && ![:format] && !path.end_with?("/") path += "/" end params = route_with_params.params if .key? :params if [:params]&.respond_to?(:to_hash) params.merge! [:params] else params[:params] = [:params] end end [:path] = path [:script_name] = script_name [:params] = params [:user] = user [:password] = password url_strategy.call end |