This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class RateLimiter | |
class Error < StandardError; end | |
class UnknownIntervalError < RateLimiter::Error; end | |
class WaitTimeError < RateLimiter::Error; end | |
attr_reader :bucket_name, :interval, :maximum_wait_time, :rate, :redis | |
def initialize(bucket_name, options = {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# @see https://gist.github.com/commitshappen/5928740df2e01f256778c2dbd14364a5 for the RateLimiter | |
module RateLimitable | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def rate_limiter(bucket_name, global: {}, local: {}) |