Module: Limited::Config

Defined in:
lib/limited/config.rb

Overview

defines all the functions which can be used to configure this gem

Class Method Summary collapse

Class Method Details

.action(name, options = {}) ⇒ Object

adds a new limited action to the list of actions takes the same paramerers as Limited::Action.new

raises an ArgumentError if the same name for an action is not unique

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/limited/config.rb', line 14

def self.action(name, options = {})
  raise ArgumentError.new("the options parameter needs to be a hash") unless options.is_a?(Hash)
  limit = options[:amount]
  interval = options[:every] || :endless
  identifier = options[:per].is_a?(Symbol) ? Limited::identifiers[options[:per]] : options[:per]
  action = Limited::Action.new(name, limit, interval, identifier)
  raise ArgumentError.new("action with name :#{name.to_s} has already been added") if Limited.actions.has_key?(name)
  Limited.actions[name] = action
end

.identifier(name, symbols) ⇒ Object

adds a new identifier to the list of identifiers to be used by actions.

raises an ArgumentError if the the name of an identifier has already been taken

Raises:

  • (ArgumentError)


30
31
32
33
34
# File 'lib/limited/config.rb', line 30

def self.identifier(name, symbols)
  identifier = Limited::Actor::Identifier.new *symbols
  raise ArgumentError.new("identifier with name :#{name.to_s} has already been added") if Limited.identifiers.has_key?(name)
  Limited.identifiers[name] = identifier
end