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

Defined in:
lib/roda.rb

Overview

Instance methods for the Roda class.

Instance Method Summary collapse

Instance Method Details

#call(env, &block) ⇒ Object

Create a request and response of the appopriate class, the instance_exec the route block with the request, handling any halts. This is not usually called directly.



308
309
310
311
312
# File 'lib/roda.rb', line 308

def call(env, &block)
  @_request = self.class::RodaRequest.new(self, env)
  @_response = self.class::RodaResponse.new
  _route(&block)
end

#envObject

The environment hash for the current request. Example:

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


317
318
319
# File 'lib/roda.rb', line 317

def env
  request.env
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


328
329
330
# File 'lib/roda.rb', line 328

def opts
  self.class.opts
end

#requestObject

The instance of the request class related to this request. This is the same object yielded by Roda.route.



334
335
336
# File 'lib/roda.rb', line 334

def request
  @_request
end

#responseObject

The instance of the response class related to this request.



339
340
341
# File 'lib/roda.rb', line 339

def response
  @_response
end

#sessionObject

The session for the current request. Raises a RodaError if a session handler has not been loaded.



345
346
347
# File 'lib/roda.rb', line 345

def session
  env[SESSION_KEY] || raise(RodaError, "You're missing a session handler. You can get started by adding use Rack::Session::Cookie")
end