Class: Rack::YandexMetrika
- Inherits:
-
Object
- Object
- Rack::YandexMetrika
- 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
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ YandexMetrika
constructor
A new instance of YandexMetrika.
Constructor Details
#initialize(app, options = {}) ⇒ YandexMetrika
Returns a new instance of YandexMetrika.
8 9 10 11 |
# File 'lib/rack/yandex-metrika.rb', line 8 def initialize(app, = {}) raise ArgumentError, "Counter_id must be set!" unless [:counter_id] and [:counter_id] != 0 @app, @options = app, DEFAULT.merge() 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 |