Sha256: 4a831673fcf0d4e5788bb4b4ad949bfd092a9bee609eb4d75d012b4a82795730

Contents?: true

Size: 855 Bytes

Versions: 4

Compression:

Stored size: 855 Bytes

Contents

require 'innate/request'
require 'innate/response'

module Innate
  # 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.
  class Current
    extend Trinity

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

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

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

    # Setup new Request/Response/Session for this request/response cycle

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
manveru-innate-2009.02.06 lib/innate/current.rb
manveru-innate-2009.02.21 lib/innate/current.rb
manveru-innate-2009.02.25 lib/innate/current.rb
manveru-innate-2009.03.24 lib/innate/current.rb