Class: Rack::AvvoIgnite

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ AvvoIgnite

Returns a new instance of AvvoIgnite.



4
5
6
7
8
# File 'lib/rack/avvo_ignite.rb', line 4

def initialize(app, options = {})
  @app = app
  @ignite_host = options[:host] || "ia.avvo.com"
  @tracker_code = options[:code]
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/avvo_ignite.rb', line 10

def call(env)
  status, headers, response = @app.call(env)

  if headers['Content-Type'].to_s.include?('text/html') # Only update HTML bodies
    response.each do |part|
      if part.rindex('</body>')
        part.gsub!('</body>', message + '</body>')
        headers['Content-Length'] = (headers['Content-Length'].to_i + message.length).to_s
      end
    end
  end

  [status, headers, response]
end