Class: Stats::Middleware::IpTracker
- Inherits:
-
Object
- Object
- Stats::Middleware::IpTracker
- Defined in:
- lib/stats/middleware/ip_tracker.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ IpTracker
constructor
A new instance of IpTracker.
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, = {}) @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 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 |