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

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

#envObject

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

#optsObject

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


324
325
326
# File 'lib/roda.rb', line 324

def opts
  self.class.opts
end

#requestObject

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

#responseObject

The instance of the response class related to this request.



335
336
337
# File 'lib/roda.rb', line 335

def response
  @_response
end

#sessionObject

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