module Roda::RodaPlugins::Base::InstanceMethods
Instance methods for the Roda
class.
Constants
- SESSION_KEY
Public Instance Methods
call(env, &block)
click to toggle source
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.
# 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()
click to toggle source
The environment hash for the current request. Example:
env['REQUEST_METHOD'] # => 'GET'
# File lib/roda.rb, line 313 def env request.env end
opts()
click to toggle source
The class-level options hash. This should probably not be modified at the instance level. Example:
Roda.plugin :render Roda.route do |r| opts[:render_opts].inspect end
# File lib/roda.rb, line 324 def opts self.class.opts end
request()
click to toggle source
The instance of the request class related to this request. This is the same object yielded by Roda.route.
# File lib/roda.rb, line 330 def request @_request end
response()
click to toggle source
The instance of the response class related to this request.
# File lib/roda.rb, line 335 def response @_response end
session()
click to toggle source
The session for the current request. Raises a RodaError
if a session handler has not been loaded.
# 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
Private Instance Methods
_route(&block)
click to toggle source
Internals of call
, extracted so that plugins can override behavior after the request and response have been setup.
# File lib/roda.rb, line 349 def _route(&block) catch(:halt) do request.block_result(instance_exec(@_request, &block)) response.finish end end