Class: Stats::Middleware::UserAgentTracker
- Inherits:
-
Object
- Object
- Stats::Middleware::UserAgentTracker
- Defined in:
- lib/stats/middleware/user_agent_tracker.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ UserAgentTracker
constructor
A new instance of UserAgentTracker.
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, = {}) @app = app @redis = [:redis] || (defined?(REDIS) && REDIS) || nil @path_filter = [:path_filter] || ->(path) { path&.start_with?('/api/') } @logger = [:logger] || (defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : Logger.new(STDOUT)) @expiry_days = [:expiry_days] || 31 @redis_key_prefix = [: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 |