Class: Stats::Middleware::IpTracker

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of IpTracker.



8
9
10
11
12
13
14
# File 'lib/stats/middleware/ip_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
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
# File 'lib/stats/middleware/ip_tracker.rb', line 16

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