Class: Rack::Angerfist
- Inherits:
-
Object
- Object
- Rack::Angerfist
- Defined in:
- lib/angerfist/angerfist.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #content_type_matches? ⇒ Boolean
- #full_path ⇒ Object
-
#initialize(app, config) ⇒ Angerfist
constructor
A new instance of Angerfist.
- #path_matches? ⇒ Boolean
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
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_path ⇒ Object
35 36 37 |
# File 'lib/angerfist/angerfist.rb', line 35 def full_path (@env['PATH_INFO'] + '?' + @env['QUERY_STRING']).chomp('?') end |
#path_matches? ⇒ 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 |