Class: RedisThrottle::Concurrency
- Inherits:
-
Object
- Object
- RedisThrottle::Concurrency
- Defined in:
- lib/redis_throttle/concurrency.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
private
Compare ‘self` with `other` strategy:.
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns ‘true` if `other` is a Concurrency instance with the same #bucket, #limit, and #ttl.
-
#complexity ⇒ Array(Integer, Integer)
private
Strategy complexity pseudo-score.
-
#hash ⇒ Integer
private
Generates an Integer hash value for this object.
-
#initialize(bucket, limit:, ttl:) ⇒ Concurrency
constructor
A new instance of Concurrency.
Constructor Details
#initialize(bucket, limit:, ttl:) ⇒ Concurrency
Returns a new instance of Concurrency.
22 23 24 25 26 |
# File 'lib/redis_throttle/concurrency.rb', line 22 def initialize(bucket, limit:, ttl:) @bucket = -bucket.to_s @limit = limit.to_i @ttl = ttl.to_i end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/redis_throttle/concurrency.rb', line 7 def bucket @bucket end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/redis_throttle/concurrency.rb', line 11 def limit @limit end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
16 17 18 |
# File 'lib/redis_throttle/concurrency.rb', line 16 def ttl @ttl 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 RedisThrottle::Concurrency nor RateLimit
-
Returns ‘1` if `other` is a RateLimit
-
Returns ‘1` if `other` is a RedisThrottle::Concurrency with lower #limit
-
Returns ‘0` if `other` is a RedisThrottle::Concurrency with the same #limit
-
Returns ‘-1` if `other` is a RedisThrottle::Concurrency with bigger #limit
54 55 56 |
# File 'lib/redis_throttle/concurrency.rb', line 54 def <=>(other) complexity <=> other.complexity if other.respond_to? :complexity end |
#==(other) ⇒ Boolean Also known as: eql?
Returns ‘true` if `other` is a RedisThrottle::Concurrency instance with the same #bucket, #limit, and #ttl.
34 35 36 37 38 39 |
# File 'lib/redis_throttle/concurrency.rb', line 34 def ==(other) return true if equal? other return false unless other.is_a?(self.class) @bucket == other.bucket && @limit == other.limit && @ttl == other.ttl 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.
71 72 73 |
# File 'lib/redis_throttle/concurrency.rb', line 71 def complexity [1, @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.
64 65 66 |
# File 'lib/redis_throttle/concurrency.rb', line 64 def hash @hash ||= [@bucket, @limit, @ttl].hash end |