Module: Roda::RodaPlugins::Base::InstanceMethods
- Defined in:
- lib/roda.rb
Overview
Instance methods for the Roda class.
In addition to the listed methods, the following two methods are available:
- request
-
The instance of the request class related to this request. This is the same object yielded by Roda.route.
- response
-
The instance of the response class related to this request.
Instance Attribute Summary collapse
-
#_request ⇒ Object
(also: #request)
readonly
:nodoc:.
-
#_response ⇒ Object
(also: #response)
readonly
:nodoc:.
Instance Method Summary collapse
-
#_roda_handle_main_route ⇒ Object
Handle dispatching to the main route, catching :halt and handling the result of the block.
-
#_roda_handle_route ⇒ Object
Treat the given block as a routing block, catching :halt if thrown by the block.
-
#_roda_main_route(_) ⇒ Object
Default implementation of the main route, usually overridden by Roda.route.
-
#_roda_run_main_route(r) ⇒ Object
Run the main route block with the request.
-
#call(&block) ⇒ Object
(also: #_call)
Deprecated method for the previous main route dispatch API.
-
#env ⇒ Object
The environment hash for the current request.
-
#initialize(env) ⇒ Object
Create a request and response of the appropriate class.
-
#opts ⇒ Object
The class-level options hash.
-
#session ⇒ Object
The session hash for the current request.
Instance Attribute Details
#_request ⇒ Object (readonly) Also known as: request
:nodoc:
558 559 560 |
# File 'lib/roda.rb', line 558 def _request @_request end |
#_response ⇒ Object (readonly) Also known as: response
:nodoc:
562 563 564 |
# File 'lib/roda.rb', line 562 def _response @_response end |
Instance Method Details
#_roda_handle_main_route ⇒ Object
Handle dispatching to the main route, catching :halt and handling the result of the block.
497 498 499 500 501 502 503 |
# File 'lib/roda.rb', line 497 def _roda_handle_main_route catch(:halt) do r = @_request r.block_result(_roda_run_main_route(r)) @_response.finish end end |
#_roda_handle_route ⇒ Object
Treat the given block as a routing block, catching :halt if thrown by the block.
507 508 509 510 511 512 |
# File 'lib/roda.rb', line 507 def _roda_handle_route catch(:halt) do @_request.block_result(yield) @_response.finish end end |
#_roda_main_route(_) ⇒ Object
Default implementation of the main route, usually overridden by Roda.route.
516 517 |
# File 'lib/roda.rb', line 516 def _roda_main_route(_) end |
#_roda_run_main_route(r) ⇒ Object
Run the main route block with the request. Designed for extension by plugins
521 522 523 |
# File 'lib/roda.rb', line 521 def _roda_run_main_route(r) _roda_main_route(r) end |
#call(&block) ⇒ Object Also known as: _call
Deprecated method for the previous main route dispatch API.
526 527 528 529 530 531 532 533 |
# File 'lib/roda.rb', line 526 def call(&block) # RODA4: Remove catch(:halt) do r = @_request r.block_result(instance_exec(r, &block)) # Fallback @_response.finish end end |
#env ⇒ Object
The environment hash for the current request. Example:
env['REQUEST_METHOD'] # => 'GET'
543 544 545 |
# File 'lib/roda.rb', line 543 def env @_request.env end |
#initialize(env) ⇒ Object
Create a request and response of the appropriate class
489 490 491 492 493 |
# File 'lib/roda.rb', line 489 def initialize(env) klass = self.class @_request = klass::RodaRequest.new(self, env) @_response = klass::RodaResponse.new end |
#opts ⇒ Object
554 555 556 |
# File 'lib/roda.rb', line 554 def opts self.class.opts end |
#session ⇒ Object
The session hash for the current request. Raises RodaError if no session exists. Example:
session # => {}
570 571 572 |
# File 'lib/roda.rb', line 570 def session @_request.session end |