Class: WhenAUser::Pageviews

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/whenauser/pageviews.rb

Instance Method Summary collapse

Methods included from Helpers

#actor_for_exception, #clean_backtrace, #from_crawler

Constructor Details

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

Returns a new instance of Pageviews.



11
12
13
14
15
16
17
# File 'lib/whenauser/pageviews.rb', line 11

def initialize(app, options={})
  @app, @options = app, options
  @options[:ignore_crawlers]      ||= WhenAUser.default_ignored_crawlers
  @options[:ignore_if]            ||= lambda { |env| false }
  @options[:ignore_if_controller] ||= 'false'
  @options[:custom_data]          ||= lambda { |env| {} }
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/whenauser/pageviews.rb', line 19

def call(env)
  before = Time.now
  status, headers, response = @app.call(env)
  [status, headers, response]
rescue Exception => e
  status = 500
  raise e
ensure
  after = Time.now
  WhenAUser.send_event event(env, status, after - before) unless should_be_ignored(env)
end