module Roda::RodaPlugins::Base::InstanceMethods
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
Source
# File lib/roda.rb, line 489 def initialize(env) klass = self.class @_request = klass::RodaRequest.new(self, env) @_response = klass::RodaResponse.new end
Create a request and response of the appropriate class
Public Instance Methods
Source
# File lib/roda.rb, line 497 def _roda_handle_main_route catch(:halt) do r = @_request r.block_result(_roda_run_main_route(r)) @_response.finish end end
Handle dispatching to the main route, catching :halt and handling the result of the block.
Source
# File lib/roda.rb, line 507 def _roda_handle_route catch(:halt) do @_request.block_result(yield) @_response.finish end end
Treat the given block as a routing block, catching :halt if thrown by the block.
Source
# File lib/roda.rb, line 516 def _roda_main_route(_) end
Default implementation of the main route, usually overridden by Roda.route.
Source
# File lib/roda.rb, line 521 def _roda_run_main_route(r) _roda_main_route(r) end
Run the main route block with the request. Designed for extension by plugins
Source
# File lib/roda.rb, line 526 def call(&block) # RODA4: Remove catch(:halt) do r = @_request r.block_result(instance_exec(r, &block)) # Fallback @_response.finish end end
Deprecated method for the previous main route dispatch API.
Source
# File lib/roda.rb, line 543 def env @_request.env end
The environment hash for the current request. Example:
env['REQUEST_METHOD'] # => 'GET'
Source
# File lib/roda.rb, line 554 def opts self.class.opts end
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
Source
# File lib/roda.rb, line 570 def session @_request.session end
The session hash for the current request. Raises RodaError
if no session exists. Example:
session # => {}
Private Instance Methods
Source
# File lib/roda.rb, line 577 def _convert_class_Integer(value) value.to_i end
Convert the segment matched by the Integer matcher to an integer.