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.



293
294
295
296
297
# File 'lib/roda.rb', line 293

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'


302
303
304
# File 'lib/roda.rb', line 302

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


313
314
315
# File 'lib/roda.rb', line 313

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.



319
320
321
# File 'lib/roda.rb', line 319

def request
  @_request
end

#responseObject

The instance of the response class related to this request.



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

def response
  @_response
end

#sessionObject

The session for the current request. Raises a RodaError if a session handler has not been loaded.



330
331
332
# File 'lib/roda.rb', line 330

def session
  env[SESSION_KEY] || raise(RodaError, "You're missing a session handler. You can get started by adding use Rack::Session::Cookie")
end