Module: Roda::RodaPlugins::Base::InstanceMethods
- Defined in:
- lib/roda.rb
Overview
Instance methods for the Roda class.
Constant Summary collapse
- SESSION_KEY =
'rack.session'.freeze
Instance Method Summary collapse
-
#call(env, &block) ⇒ Object
Create a request and response of the appopriate class, the instance_exec the route block with the request, handling any halts.
-
#env ⇒ Object
The environment hash for the current request.
-
#opts ⇒ Object
The class-level options hash.
-
#request ⇒ Object
The instance of the request class related to this request.
-
#response ⇒ Object
The instance of the response class related to this request.
-
#session ⇒ Object
The session for the current request.
Instance Method Details
#call(env, &block) ⇒ Object
Create a request and response of the appopriate class, the instance_exec the route block with the request, handling any halts. This is not usually called directly.
304 305 306 307 308 |
# File 'lib/roda.rb', line 304 def call(env, &block) @_request = self.class::RodaRequest.new(self, env) @_response = self.class::RodaResponse.new _route(&block) end |
#env ⇒ Object
The environment hash for the current request. Example:
env['REQUEST_METHOD'] # => 'GET'
313 314 315 |
# File 'lib/roda.rb', line 313 def env request.env end |
#opts ⇒ Object
324 325 326 |
# File 'lib/roda.rb', line 324 def opts self.class.opts end |
#request ⇒ Object
The instance of the request class related to this request. This is the same object yielded by Roda.route.
330 331 332 |
# File 'lib/roda.rb', line 330 def request @_request end |
#response ⇒ Object
The instance of the response class related to this request.
335 336 337 |
# File 'lib/roda.rb', line 335 def response @_response end |
#session ⇒ Object
The session for the current request. Raises a RodaError if a session handler has not been loaded.
341 342 343 |
# File 'lib/roda.rb', line 341 def session env[SESSION_KEY] || raise(RodaError, "You're missing a session handler. You can get started by adding use Rack::Session::Cookie") end |