class RateLimit::Storage
“Storage” is a jerk class that throws exceptions if you forgot to implement a critical function, welcome to Ruby (no interface) Bucket
tracks the credits for each item. Each bucket has the following parameters:
-
Args :
-
name
-> the name of the item that you allocated the bucket for -
current
-> the current credit limit (which may be larger than max, or more negative than min) -
max
-> the maximum that the bucket will be filled by the regeneration process -
min
-> the minimum that a bucket can go, must be <= 0. -
refill_amount
-> the amount that will be added to the bucket every refill_epoch seconds. -
refill_epoch
-> the number of seconds before the bucket is credited by the regeneration process -
last_refill
-> the timestamp of the last refill -
total_used
-> the total, cumulative credits used for service (so refusals don’t count)
-
-
Returns :
-
a
Bucket
-
-
Raises :
-
ArgumentError
-> if any value is nil or negative
-
Public Instance Methods
retrieves a named bucket
-
Args :
-
name
-> the name of the bucket to be retrieved
-
-
Returns :
-
the bucket matching the name if found, nil otherwise
-
-
Raises :
-
NoMethodError
-> always, because this class is a jerk
-
# File lib/ratelimit/bucketbased.rb, line 53 def get(name) raise NoMethodError end
updates the key fields that need updating into the storage this is often cheaper for certain types of storage than using set()
-
Args :
-
Returns :
-
nil
-
-
Raises :
-
NoMethodError
-> always, because this class is a jerk
-
# File lib/ratelimit/bucketbased.rb, line 76 def update(bucket) raise NoMethodError end