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:


The instance of the request class related to this request. This is the same object yielded by Roda.route.


The instance of the response class related to this request.

Public Class methods


Create a request and response of the appropriate class

[show source]
    # File lib/roda.rb
485 def initialize(env)
486   klass = self.class
487   @_request =, env)
488   @_response =
489 end

Public Instance methods


Handle dispatching to the main route, catching :halt and handling the result of the block.

[show source]
    # File lib/roda.rb
493 def _roda_handle_main_route
494   catch(:halt) do
495     r = @_request
496     r.block_result(_roda_run_main_route(r))
497     @_response.finish
498   end
499 end

Treat the given block as a routing block, catching :halt if thrown by the block.

[show source]
    # File lib/roda.rb
503 def _roda_handle_route
504   catch(:halt) do
505     @_request.block_result(yield)
506     @_response.finish
507   end
508 end

Default implementation of the main route, usually overridden by Roda.route.

[show source]
    # File lib/roda.rb
512 def _roda_main_route(_)
513 end

Run the main route block with the request. Designed for extension by plugins

[show source]
    # File lib/roda.rb
517 def _roda_run_main_route(r)
518   _roda_main_route(r)
519 end

Deprecated method for the previous main route dispatch API.

[show source]
    # File lib/roda.rb
522 def call(&block)
523   # RODA4: Remove
524   catch(:halt) do
525     r = @_request
526     r.block_result(instance_exec(r, &block)) # Fallback
527     @_response.finish
528   end
529 end

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
    # File lib/roda.rb
539 def env
540   @_request.env
541 end

The class-level options hash. This should probably not be modified at the instance level. Example:

Roda.plugin :render
Roda.route do |r|
[show source]
    # File lib/roda.rb
550 def opts
551   self.class.opts
552 end

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

session # => {}
[show source]
    # File lib/roda.rb
566 def session
567   @_request.session
568 end