Class: Rack::Piwik

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

Constant Summary collapse

DEFAULT =
{}

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Piwik.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/rack/piwik.rb', line 9

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



17
18
19
20
21
22
23
# File 'lib/rack/piwik.rb', line 17

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



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

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