Class: Pause::Analyzer
- Inherits:
-
Object
- Object
- Pause::Analyzer
- Includes:
- Helper::Timing
- Defined in:
- lib/pause/analyzer.rb
Instance Method Summary collapse
-
#check(action) ⇒ nil, ...
#check(action).
Methods included from Helper::Timing
Instance Method Details
#check(action) ⇒ nil, ...
#check(action)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pause/analyzer.rb', line 13 def check(action) return false if adapter.rate_limited?(action.scope, action.identifier) = period_marker(Pause.config.resolution, Time.now.to_i) set = adapter.key_history(action.scope, action.identifier) action.checks.each do |period_check| start_time = - period_check.period_seconds set.reverse.inject(0) do |sum, element| break if element.ts < start_time sum += element.count if sum >= period_check.max_allowed adapter.rate_limit!(action.scope, action.identifier, period_check.block_ttl) # Note that Time.now is different from period_marker(resolution, Time.now), which # rounds down to the nearest (resolution) seconds return Pause::RateLimitedEvent.new(action, period_check, sum, Time.now.to_i) end sum end end nil end |