module Roda::RodaPlugins::Base::InstanceMethods

  1. lib/roda.rb

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.

Methods

Public Class

  1. new

Public Instance

  1. call
  2. env
  3. opts
  4. session

Public Class methods

new (env)

Create a request and response of the appropriate class

[show source]
# File lib/roda.rb, line 255
def initialize(env)
  klass = self.class
  @_request = klass::RodaRequest.new(self, env)
  @_response = klass::RodaResponse.new
end

Public Instance methods

call (&block)

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.

[show source]
# File lib/roda.rb, line 265
def call(&block)
  catch(:halt) do
    r = @_request
    r.block_result(instance_exec(r, &block))
    @_response.finish
  end
end
env ()

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
# File lib/roda.rb, line 276
def env
  @_request.env
end
opts ()

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
[show source]
# File lib/roda.rb, line 287
def opts
  self.class.opts
end
session ()

The session hash for the current request. Raises RodaError if no session exists. Example:

session # => {}
[show source]
# File lib/roda.rb, line 303
def session
  @_request.session
end