Class: Rollie::RateLimiter
- Inherits:
-
Object
- Object
- Rollie::RateLimiter
- Defined in:
- lib/rollie/rate_limiter.rb
Instance Method Summary collapse
-
#initialize(key, options = {}) ⇒ RateLimiter
constructor
A new instance of RateLimiter.
- #within_limit ⇒ Object
Constructor Details
#initialize(key, options = {}) ⇒ RateLimiter
Returns a new instance of RateLimiter.
5 6 7 8 9 |
# File 'lib/rollie/rate_limiter.rb', line 5 def initialize(key, = {}) @key = "#{options[:namespace]}#{key}" @limit = [:limit] || 25 @interval = ([:interval] || 1000) * 1000 end |
Instance Method Details
#within_limit ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rollie/rate_limiter.rb', line 11 def within_limit raise ArgumentError, "requires a block" unless block_given? Rollie.redis do |conn| status = inc(conn) unless status.exceeded? yield end status end end |