Class: Innate::Current

Inherits:
Object
  • Object
show all
Extended by:
Trinity
Defined in:
lib/innate/current.rb

Overview

Uses STATE to scope request/response/session per Fiber/Thread so we can reach them from anywhere in the code without passing around the objects directly.

Instance Method Summary collapse

Methods included from Trinity

action

Methods included from StateAccessor

each, #state_accessor, #state_reader, #state_writer

Constructor Details

#initialize(app, *rest) ⇒ Current

Returns a new instance of Current.



11
12
13
14
15
16
17
# File 'lib/innate/current.rb', line 11

def initialize(app, *rest)
  if rest.empty?
    @app = app
  else
    @app = Rack::Cascade.new([app, *rest])
  end
end

Instance Method Details

#call(env) ⇒ Object

Wrap into STATE, run setup and call the app inside STATE.



21
22
23
24
25
26
# File 'lib/innate/current.rb', line 21

def call(env)
  STATE.wrap do
    setup(env)
    @app.call(env)
  end
end

#setup(env, request = Request, response = Response, session = Session) ⇒ Object

Setup new Request/Response/Session for this request/response cycle. The parameters are here to allow Ramaze to inject its own classes.



30
31
32
33
34
35
# File 'lib/innate/current.rb', line 30

def setup(env, request = Request, response = Response, session = Session)
  req = STATE[:request] = request.new(env)
  res = STATE[:response] = response.new
  STATE[:actions] = []
  STATE[:session] = Session.new(req, res)
end