Class: Rack::Piwik

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

Constant Summary collapse

DEFAULT =
{
    :disable_cookies => false
}

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Piwik.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/rack/piwik.rb', line 11

def initialize(app, options = {})
  raise ArgumentError, "piwik_url must be present" unless options[:piwik_url] and !options[:piwik_url].empty?
  raise ArgumentError, "piwik_id must be present" unless options[:piwik_id] and !options[:piwik_id].to_s.empty?

  @app, @options = app, DEFAULT.merge(options)
end

Instance Method Details

#_call(env) ⇒ Object



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

def _call(env)
  @status, @headers, @response = @app.call(env)
  return [@status, @headers, @response] unless html?
  response = Rack::Response.new([], @status, @headers)
  @response.each { |fragment| response.write inject(fragment) }
  response.finish
end

#call(env) ⇒ Object



18
# File 'lib/rack/piwik.rb', line 18

def call(env); dup._call(env); end