Class: Stats::Middleware::UserAgentTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/stats/middleware/user_agent_tracker.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UserAgentTracker.



8
9
10
11
12
13
14
15
# File 'lib/stats/middleware/user_agent_tracker.rb', line 8

def initialize(app, options = {})
  @app = app
  @redis = options[:redis] || (defined?(REDIS) && REDIS) || nil
  @path_filter = options[:path_filter] || ->(path) { path&.start_with?('/api/') }
  @logger = options[:logger] || (defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : Logger.new(STDOUT))
  @expiry_days = options[:expiry_days] || 31
  @redis_key_prefix = options[:redis_key_prefix] || 'api_requests'
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
# File 'lib/stats/middleware/user_agent_tracker.rb', line 17

def call(env)
  track_request(env) if should_track?(env)
  @app.call(env)
end