class Rack::Angerfist

Public Class Methods

new(app, config) click to toggle source
# File lib/angerfist/angerfist.rb, line 3
def initialize app, config
  @app = app
  @gabba = Gabba::Gabba.new(config[:tracker_id], config[:domain])
  @content_types = config[:content_types]
  @paths = config[:paths]
end

Public Instance Methods

call(env) click to toggle source
# File lib/angerfist/angerfist.rb, line 10
def call env
  @env = env
  status, headers, response = @app.call(@env)

  @headers = Rack::Utils::HeaderHash.new(headers)

  if content_type_matches? && path_matches?
    @gabba.page_view(full_path, full_path)
  end

  [ status, headers, response ]
end
content_type_matches?() click to toggle source
# File lib/angerfist/angerfist.rb, line 23
def content_type_matches?
  return true unless @content_types

  @content_types.include?(@headers['CONTENT-TYPE'])
end
full_path() click to toggle source
# File lib/angerfist/angerfist.rb, line 35
def full_path
  (@env['PATH_INFO'] + '?' + @env['QUERY_STRING']).chomp('?')
end
path_matches?() click to toggle source
# File lib/angerfist/angerfist.rb, line 29
def path_matches?
  return true unless @paths

  @paths.any? { |p| @env['PATH_INFO'].include?(p) }
end