Class: Knot::Dispatch::Router
- Inherits:
-
Object
- Object
- Knot::Dispatch::Router
- Extended by:
- API
- Includes:
- Context
- Defined in:
- lib/knot/dispatch/router.rb,
lib/knot/dispatch/router/api.rb,
lib/knot/dispatch/router/config.rb,
lib/knot/dispatch/router/context.rb
Defined Under Namespace
Modules: API, Context Classes: Config
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Class Method Summary collapse
Instance Method Summary collapse
- #_call!(error = nil) ⇒ Object
-
#initialize(request, route) ⇒ Router
constructor
A new instance of Router.
Methods included from API
delete, filter, get, head, options, patch, post, put
Methods included from Context
#json, #params, #redirect, #render, #respond!, #status
Constructor Details
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
27 28 29 |
# File 'lib/knot/dispatch/router.rb', line 27 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
27 28 29 |
# File 'lib/knot/dispatch/router.rb', line 27 def response @response end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
27 28 29 |
# File 'lib/knot/dispatch/router.rb', line 27 def route @route end |
Class Method Details
._call!(request) ⇒ Object
12 13 14 |
# File 'lib/knot/dispatch/router.rb', line 12 def self._call!(request) new(request, matching_route(request))._call! end |
.config ⇒ Object
16 17 18 |
# File 'lib/knot/dispatch/router.rb', line 16 def self.config @config ||= Knot::Dispatch::Router::Config.new(self) end |
.matching_route(request) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/knot/dispatch/router.rb', line 20 def self.matching_route(request) route = config.routes.find { |route| route.match?(request) } raise Knot::Dispatch::NoRouteError, "no route matches #{request.path}" if route.nil? return route end |
Instance Method Details
#_call!(error = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/knot/dispatch/router.rb', line 35 def _call!(error = nil) request.params.merge! Path.path_params(route.path, request) blocks = _config.applicable_filters(route).map(&:block) blocks << route.block catch(:halt) { blocks.map do |block| result = instance_exec error, &block response.body << result if result.is_a?(String) end.last } return response end |