Method: Istox::RateLimit#initialize
- Defined in:
- lib/istox/helpers/rate_limit.rb
#initialize(key, options = {}) ⇒ Ratelimit
Create a Ratelimit object.
Cannot be larger than the bucket_span.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/istox/helpers/rate_limit.rb', line 20 def initialize(key, = {}) @key = key raise ArgumentError, 'Redis object is now passed in via the options hash - options[:redis]' unless .is_a?(Hash) @bucket_span = [:bucket_span] || 600 @bucket_interval = [:bucket_interval] || 5 @bucket_expiry = [:bucket_expiry] || @bucket_span raise ArgumentError, 'Bucket expiry cannot be larger than the bucket span' if @bucket_expiry > @bucket_span @bucket_count = (@bucket_span / @bucket_interval).round raise ArgumentError, 'Cannot have less than 3 buckets' if @bucket_count < 3 @raw_redis = [:redis] end |