Module: RateLimiter::Model::ClassMethods

Defined in:
lib/rate_limiter/model.rb

Overview

Class methods available to models after RateLimiter has been loaded.

Instance Method Summary collapse

Instance Method Details

#rate_limit(options = {}) ⇒ Object

Tell the model to limit creation of records based on an attribute for a given interval of time.

Options:

  • :on - The attribute to limit on. Defaults to :ip_address. Set to an

array to limit on multiple attributes (e.g. :ip_address or :user_id.

  • :interval - The amount of time that must have elapses since the last

record that has the same value as the attribute indicated by the :on option in seconds. Defaults to 1 minute.

  • :if, :unless - Procs that specify the conditions for when record

creation rate limiting should occur.



27
28
29
30
# File 'lib/rate_limiter/model.rb', line 27

def rate_limit(options = {})
  defaults = RateLimiter.config.rate_limit_defaults
  rate_limiter.setup(defaults.merge(options))
end

#rate_limiterObject



32
33
34
# File 'lib/rate_limiter/model.rb', line 32

def rate_limiter
  ModelConfig.new(self)
end