Module: Roda::RodaPlugins::Base::InstanceMethods

Defined in:
lib/roda.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_requestObject (readonly) Also known as: request

:nodoc:



554
555
556
# File 'lib/roda.rb', line 554

def _request
  @_request
end

#_responseObject (readonly) Also known as: response

:nodoc:



558
559
560
# File 'lib/roda.rb', line 558

def _response
  @_response
end

Instance Method Details

#_roda_handle_main_routeObject

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



493
494
495
496
497
498
499
# File 'lib/roda.rb', line 493

def _roda_handle_main_route
  catch(:halt) do
    r = @_request
    r.block_result(_roda_run_main_route(r))
    @_response.finish
  end
end

#_roda_handle_routeObject

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



503
504
505
506
507
508
# File 'lib/roda.rb', line 503

def _roda_handle_route
  catch(:halt) do
    @_request.block_result(yield)
    @_response.finish
  end
end

#_roda_main_route(_) ⇒ Object

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



512
513
# File 'lib/roda.rb', line 512

def _roda_main_route(_)
end

#_roda_run_main_route(r) ⇒ Object

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



517
518
519
# File 'lib/roda.rb', line 517

def _roda_run_main_route(r)
  _roda_main_route(r)
end

#call(&block) ⇒ Object Also known as: _call

Deprecated method for the previous main route dispatch API.



522
523
524
525
526
527
528
529
# File 'lib/roda.rb', line 522

def call(&block)
  # RODA4: Remove
  catch(:halt) do
    r = @_request
    r.block_result(instance_exec(r, &block)) # Fallback
    @_response.finish
  end
end

#envObject

The environment hash for the current request. Example:

env['REQUEST_METHOD'] # => 'GET'


539
540
541
# File 'lib/roda.rb', line 539

def env
  @_request.env
end

#initialize(env) ⇒ Object

Create a request and response of the appropriate class



485
486
487
488
489
# File 'lib/roda.rb', line 485

def initialize(env)
  klass = self.class
  @_request = klass::RodaRequest.new(self, env)
  @_response = klass::RodaResponse.new
end

#optsObject

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


550
551
552
# File 'lib/roda.rb', line 550

def opts
  self.class.opts
end

#sessionObject

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

session # => {}


566
567
568
# File 'lib/roda.rb', line 566

def session
  @_request.session
end