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
-
#call(&block) ⇒ Object
(also: #_call)
instance_exec the route block in the scope of the receiver, with the related request.
-
#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:
309 310 311 |
# File 'lib/roda.rb', line 309 def _request @_request end |
#_response ⇒ Object (readonly) Also known as: response
:nodoc:
313 314 315 |
# File 'lib/roda.rb', line 313 def _response @_response end |
Instance Method Details
#call(&block) ⇒ Object Also known as: _call
instance_exec the route block in the scope of the receiver, with the related request. Catch :halt so that the route block can throw :halt at any point with the rack response to use.
279 280 281 282 283 284 285 |
# File 'lib/roda.rb', line 279 def call(&block) catch(:halt) do r = @_request r.block_result(instance_exec(r, &block)) @_response.finish end end |
#env ⇒ Object
The environment hash for the current request. Example:
env['REQUEST_METHOD'] # => 'GET'
294 295 296 |
# File 'lib/roda.rb', line 294 def env @_request.env end |
#initialize(env) ⇒ Object
Create a request and response of the appropriate class
269 270 271 272 273 |
# File 'lib/roda.rb', line 269 def initialize(env) klass = self.class @_request = klass::RodaRequest.new(self, env) @_response = klass::RodaResponse.new end |
#opts ⇒ Object
305 306 307 |
# File 'lib/roda.rb', line 305 def opts self.class.opts end |
#session ⇒ Object
The session hash for the current request. Raises RodaError if no session exists. Example:
session # => {}
321 322 323 |
# File 'lib/roda.rb', line 321 def session @_request.session end |