Class: Racket::Current

Inherits:
Object
  • Object
show all
Defined in:
lib/racket/current.rb

Overview

Represents the current state of Racket while processing a request. The state gets mixed into the controller instance at the start of the request, making it easy to keep track on everything from within the controller instance.

Defined Under Namespace

Classes: State

Class Method Summary collapse

Class Method Details

.init(env, action, params) ⇒ Module

Called whenever a new request needs to be processed.

Parameters:

  • env (Hash)

    Rack environment

  • action (Symbol)

    Keeps track of which action was called on the controller

  • params (Array)

    Parameters sent to the action

Returns:

  • (Module)

    A module encapsulating all state relating to the current request



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/racket/current.rb', line 36

def self.init(env, action, params)
  racket = State.new(action, nil, params)
  request = Request.new(env)
  response = Response.new
  session = Session.new(env['rack.session']) if env.key?('rack.session')
  Module.new do
    define_method(:racket) { racket }
    define_method(:request) { request }
    define_method(:response) { response }
    define_method(:session) { session } if env.key?('rack.session')
  end
end