module RateLimiter

Extend your ActiveRecord models with the ability to limit the rate at which they are saved.

Constants

VERSION

Public Class Methods

config() { |config| ... } click to toggle source

Return the RateLimiter singleton configuration object. This is for all threads.

# File lib/rate_limiter.rb, line 16
def config
  @config ||= Config.instance
  yield @config if block_given?
  @config
end
Also aliased as: configure
configure()
Alias for: config
enabled=(value) click to toggle source

Switches RateLimiter on or off, for all threads.

# File lib/rate_limiter.rb, line 24
def enabled=(value)
  config.enabled = value
end
enabled?() click to toggle source

Returns `true` if RateLimiter is on, `false if it is off. This is for all threads.

# File lib/rate_limiter.rb, line 30
def enabled?
  config.enabled
end
request(options = nil, &block) click to toggle source

Gets the options local to the current request.

If given a block the options passed in are set, the block is executed, previous options are restored, and the return value of the block is returned.

# File lib/rate_limiter.rb, line 39
def request(options = nil, &block)
  if options.nil? && !block_given?
    Request
  else
    Request.with(options, &block)
  end
end