Class: RateLimiter::Domain::Limiter
- Inherits:
-
Object
- Object
- RateLimiter::Domain::Limiter
- Defined in:
- lib/domain/limiter.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
-
#initialize(route_name, user_id, rate_limit, punishment_factor, limit_period) ⇒ Limiter
constructor
A new instance of Limiter.
- #rate_violated?(records) ⇒ Boolean
- #violation_expired?(violation_records) ⇒ Boolean
- #was_violated?(violation_records) ⇒ Boolean
Constructor Details
#initialize(route_name, user_id, rate_limit, punishment_factor, limit_period) ⇒ Limiter
Returns a new instance of Limiter.
7 8 9 10 11 12 13 14 |
# File 'lib/domain/limiter.rb', line 7 def initialize(route_name, user_id, rate_limit, punishment_factor, limit_period) @identifier = route_name + '-' + user_id @punishment_factor = punishment_factor @limit_period = limit_period @rate_limit = rate_limit @violations = Violations.new(@punishment_factor, @limit_period) @rate_limit = RateLimit.new(@rate_limit, @limit_period) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
16 17 18 |
# File 'lib/domain/limiter.rb', line 16 def identifier @identifier end |
Instance Method Details
#rate_violated?(records) ⇒ Boolean
32 33 34 |
# File 'lib/domain/limiter.rb', line 32 def rate_violated?(records) @rate_limit.exceeded?(records) end |
#violation_expired?(violation_records) ⇒ Boolean
28 29 30 |
# File 'lib/domain/limiter.rb', line 28 def violation_expired?(violation_records) @violations.expired?(violation_records) end |
#was_violated?(violation_records) ⇒ Boolean
18 19 20 21 22 23 24 25 26 |
# File 'lib/domain/limiter.rb', line 18 def was_violated?(violation_records) if @violations.exist?(violation_records) if @violations.apply?(violation_records) return true end end false end |