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

new (env)

Create a request and response of the appropriate class

[show source]
    # File lib/roda.rb
539 def initialize(env)
540   klass = self.class
541   @_request =, env)
542   @_response =
543 end

Public Instance methods

_roda_handle_main_route ()

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

[show source]
    # File lib/roda.rb
547 def _roda_handle_main_route
548   catch(:halt) do
549     r = @_request
550     r.block_result(_roda_run_main_route(r))
551     @_response.finish
552   end
553 end
_roda_handle_route ()

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

[show source]
    # File lib/roda.rb
557 def _roda_handle_route
558   catch(:halt) do
559     @_request.block_result(yield)
560     @_response.finish
561   end
562 end
_roda_main_route (_)

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

[show source]
    # File lib/roda.rb
566 def _roda_main_route(_)
567 end
_roda_run_main_route (r)

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

[show source]
    # File lib/roda.rb
571 def _roda_run_main_route(r)
572   _roda_main_route(r)
573 end
call (&block)

Deprecated method for the previous main route dispatch API.

[show source]
    # File lib/roda.rb
576 def call(&block)
577   # RODA4: Remove
578   catch(:halt) do
579     r = @_request
580     r.block_result(instance_exec(r, &block)) # Fallback
581     @_response.finish
582   end
583 end
env ()

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
    # File lib/roda.rb
593 def env
594   @_request.env
595 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|
[show source]
    # File lib/roda.rb
604 def opts
605   self.class.opts
606 end
session ()

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

session # => {}
[show source]
    # File lib/roda.rb
620 def session
621   @_request.session
622 end