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.

Public Class methods

new(env)

Create a request and response of the appropriate class

[show source]
    # File lib/roda.rb
515 def initialize(env)
516   klass = self.class
517   @_request = klass::RodaRequest.new(self, env)
518   @_response = klass::RodaResponse.new
519 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
523 def _roda_handle_main_route
524   catch(:halt) do
525     r = @_request
526     r.block_result(_roda_run_main_route(r))
527     @_response.finish
528   end
529 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
533 def _roda_handle_route
534   catch(:halt) do
535     @_request.block_result(yield)
536     @_response.finish
537   end
538 end
_roda_main_route(_)

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

[show source]
    # File lib/roda.rb
542 def _roda_main_route(_)
543 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
547 def _roda_run_main_route(r)
548   _roda_main_route(r)
549 end
call(&block)

Deprecated method for the previous main route dispatch API.

[show source]
    # File lib/roda.rb
552 def call(&block)
553   # RODA4: Remove
554   catch(:halt) do
555     r = @_request
556     r.block_result(instance_exec(r, &block)) # Fallback
557     @_response.finish
558   end
559 end
env()

The environment hash for the current request. Example:

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

The class-level options hash. This should 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
580 def opts
581   self.class.opts
582 end
session()

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

session # => {}
[show source]
    # File lib/roda.rb
596 def session
597   @_request.session
598 end