Class: RedisThrottle::RateLimit
- Inherits:
-
Object
- Object
- RedisThrottle::RateLimit
- Defined in:
- lib/redis_throttle/rate_limit.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
private
Compare ‘self` with `other` strategy:.
- #==(other) ⇒ Boolean (also: #eql?)
-
#complexity ⇒ Array(Integer, Integer)
private
Strategy complexity pseudo-score.
-
#hash ⇒ Integer
private
Generates an Integer hash value for this object.
-
#initialize(bucket, limit:, period:) ⇒ RateLimit
constructor
A new instance of RateLimit.
Constructor Details
#initialize(bucket, limit:, period:) ⇒ RateLimit
Returns a new instance of RateLimit.
20 21 22 23 24 |
# File 'lib/redis_throttle/rate_limit.rb', line 20 def initialize(bucket, limit:, period:) @bucket = -bucket.to_s @limit = limit.to_i @period = period.to_i end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/redis_throttle/rate_limit.rb', line 7 def bucket @bucket end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/redis_throttle/rate_limit.rb', line 11 def limit @limit end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
15 16 17 |
# File 'lib/redis_throttle/rate_limit.rb', line 15 def period @period end |
Instance Method Details
#<=>(other) ⇒ -1, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compare ‘self` with `other` strategy:
-
Returns ‘nil` if `other` is neither Concurrency nor RedisThrottle::RateLimit
-
Returns ‘-1` if `other` is a Concurrency
-
Returns ‘1` if `other` is a RedisThrottle::RateLimit with lower #limit
-
Returns ‘0` if `other` is a RedisThrottle::RateLimit with the same #limit
-
Returns ‘-1` if `other` is a RedisThrottle::RateLimit with bigger #limit
52 53 54 |
# File 'lib/redis_throttle/rate_limit.rb', line 52 def <=>(other) complexity <=> other.complexity if other.respond_to? :complexity end |
#==(other) ⇒ Boolean Also known as: eql?
Returns ‘true` if `other` is a RedisThrottle::RateLimit instance with the same #bucket, #limit, and #period.
32 33 34 35 36 37 |
# File 'lib/redis_throttle/rate_limit.rb', line 32 def ==(other) return true if equal? other return false unless other.is_a?(self.class) @bucket == other.bucket && @limit == other.limit && @period == other.period end |
#complexity ⇒ Array(Integer, Integer)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Strategy complexity pseudo-score.
69 70 71 |
# File 'lib/redis_throttle/rate_limit.rb', line 69 def complexity [0, @limit] end |
#hash ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates an Integer hash value for this object.
62 63 64 |
# File 'lib/redis_throttle/rate_limit.rb', line 62 def hash @hash ||= [@bucket, @limit, @period].hash end |