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
489 def initialize(env)
490   klass = self.class
491   @_request =, env)
492   @_response =
493 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
497 def _roda_handle_main_route
498   catch(:halt) do
499     r = @_request
500     r.block_result(_roda_run_main_route(r))
501     @_response.finish
502   end
503 end

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

[show source]
    # File lib/roda.rb
507 def _roda_handle_route
508   catch(:halt) do
509     @_request.block_result(yield)
510     @_response.finish
511   end
512 end

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

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

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

[show source]
    # File lib/roda.rb
521 def _roda_run_main_route(r)
522   _roda_main_route(r)
523 end

Deprecated method for the previous main route dispatch API.

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

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
    # File lib/roda.rb
543 def env
544   @_request.env
545 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
554 def opts
555   self.class.opts
556 end

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

session # => {}
[show source]
    # File lib/roda.rb
570 def session
571   @_request.session
572 end