Class: Rack::Angerfist

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

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Angerfist

Returns a new instance of Angerfist.



3
4
5
6
7
8
# 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

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# 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?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/angerfist/angerfist.rb', line 23

def content_type_matches?
  return true unless @content_types

  @content_types.include?(@headers['CONTENT-TYPE'])
end

#full_pathObject



35
36
37
# File 'lib/angerfist/angerfist.rb', line 35

def full_path
  (@env['PATH_INFO'] + '?' + @env['QUERY_STRING']).chomp('?')
end

#path_matches?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/angerfist/angerfist.rb', line 29

def path_matches?
  return true unless @paths

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