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
-
.action(name, options = {}) ⇒ Object
adds a new limited action to the list of actions takes the same paramerers as Limited::Action.new.
-
.identifier(name, symbols) ⇒ Object
adds a new identifier to the list of identifiers to be used by actions.
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
14 15 16 17 18 19 20 21 22 |
# File 'lib/limited/config.rb', line 14 def self.action(name, = {}) raise ArgumentError.new("the options parameter needs to be a hash") unless .is_a?(Hash) limit = [:amount] interval = [:every] || :endless identifier = [:per].is_a?(Symbol) ? Limited::identifiers[[:per]] : [: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
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 |