module Rlimiter

Module which is single-instantiated in the application via :init.

Inherit the below class for custom implementations of any storage clients.

Constants

CLIENTS

At the moment only redis client is supported.

VERSION

:nocov:

Attributes

client[R]

Public Class Methods

current_count(*params) click to toggle source

Returns the current hit count.

# File lib/rlimiter.rb, line 47
def current_count(*params)
  client.current_count(*params)
end
init(params) click to toggle source

One time initializes the client which is to be used throughout the application. The value of params variable will change depending on the storage client to be initialized.

@param [Hash] params @return [Rlimiter::Client]

# File lib/rlimiter.rb, line 23
def init(params)
  case params[:client]
  when 'redis'
    @client = RedisClient.new(params)
  else
    raise InvalidClientError, "Valid clients are #{CLIENTS.join(',')}"
  end
end
limit(*params) click to toggle source

Register a hit to the client.

# File lib/rlimiter.rb, line 37
def limit(*params)
  client.limit(*params)
end
next_in(*params) click to toggle source

Returns when the next hit will be accepted

# File lib/rlimiter.rb, line 42
def next_in(*params)
  client.next_in(*params)
end