class Racket::Current
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.
Constants
- State
Holds
Racket
internal state, available to the controller instance but mostly used for keeping track of things that don't belong to the actual request.
Public Class Methods
init(router_params)
click to toggle source
Called whenever a new request needs to be processed.
@param [RouterParams] router_params @return [Module] A module encapsulating all state relating to the current request
# File lib/racket/current.rb, line 32 def self.init(router_params) init_module(init_properties(*router_params.to_a)) end
Private Class Methods
init_module(properties)
click to toggle source
# File lib/racket/current.rb, line 36 def self.init_module(properties) Module.new do properties.each_pair { |key, value| define_method(key) { value } } end end
init_properties(action, params, env)
click to toggle source
# File lib/racket/current.rb, line 42 def self.init_properties(action, params, env) properties = { racket: State.new(action, nil, params), request: Request.new(env), response: Response.new } session = env.fetch('rack.session', nil) properties[:session] = Session.new(session) if session properties end