Class: Rack::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/track.rb

Defined Under Namespace

Classes: PixelSet

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ Track

Returns a new instance of Track.



3
4
5
6
# File 'lib/rack/track.rb', line 3

def initialize(app, &block)
  @app = app
  @rules = Rack::Track::PixelSet.new &block
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/track.rb', line 8

def call(env)
  request = Rack::Request.new(env)
  status, headers, response = @app.call(env)
  
  if /^text\/html/ =~ headers["Content-Type"]
    response_body = ""
    response.each { |p| response_body += p }
    response = [@rules.apply(request, response_body)] if response_body.include? "</body>"
    headers["Content-Length"] = get_length(response)
  end
  [status, headers, response]
end

#each(&block) ⇒ Object



21
22
# File 'lib/rack/track.rb', line 21

def each(&block)
end