Class: Qlive::Rack
- Inherits:
-
Object
- Object
- Qlive::Rack
- Defined in:
- lib/qlive/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, opts) ⇒ Rack
Returns a new instance of Rack.
7 8 9 10 11 12 |
# File 'lib/qlive/rack.rb', line 7 def initialize(app, opts) Qlive.setup.merge!(opts) @app = app @regex_qs = /#{opts[:magic_param] || 'qlive'}=([^&\?]+)/i Registry.find_suites end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/qlive/rack.rb', line 14 def call(env) suite = nil if env["REQUEST_METHOD"].upcase == 'GET' m = @regex_qs.match(env['QUERY_STRING']) if m && m.length > 0 request = ::Rack::Request.new(env) suite = Registry.build_suite(m[1]) suite.prepare({ :request => request, :session => env["rack.session"] }) suite.before_each_suite(request) end end status, headers, body = @app.call(env) if suite suite.before_suite_response(status, headers, body) inject_html(:after_open, :head, suite.html_after_head_open, body, headers) inject_html(:before_close, :head, suite.html_before_head_close, body, headers) inject_html(:after_open, :body, suite.html_after_body_open, body, headers) inject_html(:before_close, :body, suite.html_before_body_close, body, headers) end [status, headers, body] end |