Class: Chokepoint::TimeWindow
- Defined in:
- lib/chokepoint/time_window.rb
Instance Attribute Summary
Attributes inherited from Limiter
Instance Method Summary collapse
-
#allowed?(context) ⇒ Boolean
Returns ‘true` if fewer than the maximum number of requests permitted for the current window of time have been made.
Methods inherited from Limiter
#blacklisted?, #initialize, #throttle, #whitelisted?
Constructor Details
This class inherits a constructor from Chokepoint::Limiter
Instance Method Details
#allowed?(context) ⇒ Boolean
Returns ‘true` if fewer than the maximum number of requests permitted for the current window of time have been made.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/chokepoint/time_window.rb', line 10 def allowed?(context) count = cache_get(key = cache_key(context)).to_i + 1 rescue 1 allowed = count <= max_per_window.to_i begin cache_set(key, count) allowed rescue => e allowed = true end end |