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:



302
303
304
# File 'lib/roda.rb', line 302

def _request
  @_request
end

#_responseObject (readonly) Also known as: response

:nodoc:



306
307
308
# File 'lib/roda.rb', line 306

def _response
  @_response
end

Instance Method Details

#call(&block) ⇒ Object

instance_exec the route block in the scope of the receiver, with the related request. Catch :halt so that the route block can throw :halt at any point with the rack response to use.



276
277
278
279
280
281
282
# File 'lib/roda.rb', line 276

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

#envObject

The environment hash for the current request. Example:

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


287
288
289
# File 'lib/roda.rb', line 287

def env
  @_request.env
end

#initialize(env) ⇒ Object

Create a request and response of the appropriate class



266
267
268
269
270
# File 'lib/roda.rb', line 266

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


298
299
300
# File 'lib/roda.rb', line 298

def opts
  self.class.opts
end

#sessionObject

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

session # => {}


314
315
316
# File 'lib/roda.rb', line 314

def session
  @_request.session
end