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
325 def initialize(env)
326   klass = self.class
327   @_request = klass::RodaRequest.new(self, env)
328   @_response = klass::RodaResponse.new
329 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
335 def call(&block)
336   catch(:halt) do
337     r = @_request
338     r.block_result(instance_exec(r, &block))
339     @_response.finish
340   end
341 end
env ()

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
    # File lib/roda.rb
350 def env
351   @_request.env
352 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
361 def opts
362   self.class.opts
363 end
session ()

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

session # => {}
[show source]
    # File lib/roda.rb
377 def session
378   @_request.session
379 end