Sha256: 86af5f274160b6599d2e5e4be1bc884392eaf274d2045940ffa7a50309273838

Contents?: true

Size: 972 Bytes

Versions: 25

Compression:

Stored size: 972 Bytes

Contents

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

module Innate
  # We track the current request/response/session (Trinity) in Thread.current
  # 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

    # Run setup and call the app
    def call(env)
      setup(env)
      @app.call(env)
    end

    # Setup new Request/Response/Session for this request/response cycle.
    # The parameters are here to allow Ramaze to inject its own classes.
    def setup(env, request = Request, response = Response, session = Session)
      current = Thread.current
      req = current[:request] = request.new(env)
      res = current[:response] = response.new
      current[:actions] = []
      current[:session] = Session.new(req, res)
    end
  end
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
manveru-innate-2009.05 lib/innate/current.rb
manveru-innate-2009.06.12 lib/innate/current.rb
manveru-innate-2009.06 lib/innate/current.rb
manveru-innate-2009.07 lib/innate/current.rb
rjspotter-innate-2009.06.29 lib/innate/current.rb
rjspotter-innate-2009.06.30 lib/innate/current.rb
rjspotter-innate-2009.06.31 lib/innate/current.rb
innate-2013.02.21 lib/innate/current.rb
innate-2013.02 lib/innate/current.rb
innate-2012.12 lib/innate/current.rb
innate-2012.03 lib/innate/current.rb
innate-2011.12 lib/innate/current.rb
innate-2011.10 lib/innate/current.rb
innate-2011.04 lib/innate/current.rb
innate-2011.01 lib/innate/current.rb
innate-2010.07 lib/innate/current.rb
innate-2010.06.18 lib/innate/current.rb
innate-2010.04 lib/innate/current.rb
innate-2010.03 lib/innate/current.rb
innate-2010.01 lib/innate/current.rb