Class: Rakwik::Tracker

Inherits:
Object
  • Object
show all
Includes:
Rack::Response::Helpers
Defined in:
lib/rakwik/tracker.rb

Constant Summary collapse

DEFAULT =
{
  :track_404 => true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Tracker.



14
15
16
17
18
# File 'lib/rakwik/tracker.rb', line 14

def initialize(app, options = {})
  @app, @options = app, DEFAULT.merge(options)
  missing = [:piwik_url, :site_id, :token_auth].detect{ |e| @options[e].nil? }
  raise "Missing config value: :#{missing}" if missing
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/rakwik/tracker.rb', line 8

def status
  @status
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rakwik/tracker.rb', line 20

def call(env)
  start = Time.now
  @status, @headers, @body = @app.call(env)
  env['rakwik.duration'] = (Time.now - start)*1000
  track Rack::Request.new(env) if track?
  [@status, @headers, @body]
end