Class: Lotus::Routing::HttpRouter Private
- Inherits:
-
HttpRouter
- Object
- HttpRouter
- Lotus::Routing::HttpRouter
- Defined in:
- lib/lotus/routing/http_router.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
HTTP router
This implementation is based on ::HttpRouter (http_router gem).
Lotus::Router wraps an instance of this class, in order to protect its public API from any future change of ::HttpRouter.
Instance Method Summary collapse
-
#action_separator ⇒ Object
private
Separator between controller and action name.
-
#find(options) ⇒ Object
private
Finds a path from the given options.
-
#initialize(options = {}, &blk) ⇒ HttpRouter
constructor
private
Initialize the router.
-
#mount(app, options) ⇒ Object
private
Allow to mount a Rack app.
- #no_response(request, env) ⇒ Object private
-
#options(path, options = {}, &blk) ⇒ Object
private
Support for OPTIONS HTTP verb.
- #pass_on_response(response) ⇒ Object private
- #raw_call(env, &blk) ⇒ Object private
-
#raw_path(route, *args) ⇒ Object
private
Generate a relative URL for a specified named route.
-
#raw_url(route, *args) ⇒ Object
private
Generate an absolute URL for a specified named route.
- #reset! ⇒ Object private
Constructor Details
#initialize(options = {}, &blk) ⇒ HttpRouter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the router.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lotus/routing/http_router.rb', line 39 def initialize( = {}, &blk) super(, &nil) @default_scheme = [:scheme] if [:scheme] @default_host = [:host] if [:host] @default_port = [:port] if [:port] @route_class = [:route] || Routing::Route @resolver = [:resolver] || Routing::EndpointResolver.new() @parsers = Routing::Parsers.new([:parsers]) @prefix = Utils::PathPrefix.new([:prefix] || '') @force_ssl = Lotus::Routing::ForceSsl.new(!![:force_ssl], host: @default_host, port: @default_port) end |
Instance Method Details
#action_separator ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Separator between controller and action name.
58 59 60 |
# File 'lib/lotus/routing/http_router.rb', line 58 def action_separator @resolver.action_separator end |
#find(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds a path from the given options.
68 69 70 |
# File 'lib/lotus/routing/http_router.rb', line 68 def find() @resolver.find() end |
#mount(app, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allow to mount a Rack app
112 113 114 115 116 |
# File 'lib/lotus/routing/http_router.rb', line 112 def mount(app, ) add("#{ options.fetch(:at) }*").to( @resolver.resolve(to: app) ) end |
#no_response(request, env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
140 141 142 143 144 145 146 |
# File 'lib/lotus/routing/http_router.rb', line 140 def no_response(request, env) if request.acceptable_methods.any? && !request.acceptable_methods.include?(env['REQUEST_METHOD']) [405, {'Allow' => request.acceptable_methods.sort.join(", ")}, []] else @default_app.call(env) end end |
#options(path, options = {}, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Support for OPTIONS HTTP verb
102 103 104 |
# File 'lib/lotus/routing/http_router.rb', line 102 def (path, = {}, &blk) add_with_request_method(path, :options, , &blk) end |
#pass_on_response(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
135 136 137 |
# File 'lib/lotus/routing/http_router.rb', line 135 def pass_on_response(response) super response.to_a end |
#raw_call(env, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 |
# File 'lib/lotus/routing/http_router.rb', line 119 def raw_call(env, &blk) if response = @force_ssl.call(env) response else super(@parsers.call(env)) end end |
#raw_path(route, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a relative URL for a specified named route.
78 79 80 81 82 |
# File 'lib/lotus/routing/http_router.rb', line 78 def raw_path(route, *args) _rescue_url_recognition do _custom_path(super(route, *args)) end end |
#raw_url(route, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate an absolute URL for a specified named route.
90 91 92 93 94 |
# File 'lib/lotus/routing/http_router.rb', line 90 def raw_url(route, *args) _rescue_url_recognition do _custom_path(super(route, *args)) end end |
#reset! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
128 129 130 131 132 |
# File 'lib/lotus/routing/http_router.rb', line 128 def reset! uncompile @routes, @named_routes, @root = [], Hash.new{|h,k| h[k] = []}, Node::Root.new(self) @default_host, @default_port, @default_scheme = 'localhost', 80, 'http' end |