Class: Rack::ExvoWarez::Stats
- Inherits:
-
Object
- Object
- Rack::ExvoWarez::Stats
- Defined in:
- lib/rack/exvo/stats.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each ⇒ Object
-
#initialize(app) ⇒ Stats
constructor
A new instance of Stats.
Constructor Details
#initialize(app) ⇒ Stats
Returns a new instance of Stats.
4 5 6 7 |
# File 'lib/rack/exvo/stats.rb', line 4 def initialize(app) @app = app @payload = ERB.new(::File.read(::File.("../templates/stats.erb", __FILE__))).result(binding) end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/exvo/stats.rb', line 9 def call(env) request = Rack::Request.new(env) status, headers, @body = @app.call(env) if request.xhr? return [status, headers, @body] end if html?(headers) if cl = headers["Content-Length"] headers["Content-Length"] = (cl.to_i + @payload.length).to_s end [status, headers, self] else [status, headers, @body] end [status, headers, (html?(headers) ? self : @body)] end |
#each ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rack/exvo/stats.rb', line 30 def each if @body.is_a?(String) resp = ActionDispatch::Response.new resp.write(@body) @body = resp end @body.each do |chunk| yield(end_of_body?(chunk) ? with_payload(chunk) : chunk) end end |