Class: Rack::YandexMetrika

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/yandex-metrika.rb,
lib/rack/yandex-metrika/version.rb

Constant Summary collapse

DEFAULT =
{ :async => true }
VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of YandexMetrika.

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/rack/yandex-metrika.rb', line 8

def initialize(app, options = {})
  raise ArgumentError, "Counter_id must be set!" unless options[:counter_id] and options[:counter_id] != 0
  @app, @options = app, DEFAULT.merge(options)
end

Instance Method Details

#_call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rack/yandex-metrika.rb', line 15

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

#call(env) ⇒ Object



13
# File 'lib/rack/yandex-metrika.rb', line 13

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