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
501 def initialize(env)
502   klass = self.class
503   @_request = klass::RodaRequest.new(self, env)
504   @_response = klass::RodaResponse.new
505 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
509 def _roda_handle_main_route
510   catch(:halt) do
511     r = @_request
512     r.block_result(_roda_run_main_route(r))
513     @_response.finish
514   end
515 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
519 def _roda_handle_route
520   catch(:halt) do
521     @_request.block_result(yield)
522     @_response.finish
523   end
524 end
_roda_main_route(_)

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

[show source]
    # File lib/roda.rb
528 def _roda_main_route(_)
529 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
533 def _roda_run_main_route(r)
534   _roda_main_route(r)
535 end
call(&block)

Deprecated method for the previous main route dispatch API.

[show source]
    # File lib/roda.rb
538 def call(&block)
539   # RODA4: Remove
540   catch(:halt) do
541     r = @_request
542     r.block_result(instance_exec(r, &block)) # Fallback
543     @_response.finish
544   end
545 end
env()

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'
[show source]
    # File lib/roda.rb
555 def env
556   @_request.env
557 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
566 def opts
567   self.class.opts
568 end
session()

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

session # => {}
[show source]
    # File lib/roda.rb
582 def session
583   @_request.session
584 end