Class: TrafficJam::Configuration
- Inherits:
-
Object
- Object
- TrafficJam::Configuration
- Defined in:
- lib/traffic_jam/configuration.rb
Overview
Configuration for TrafficJam library.
Constant Summary collapse
- OPTIONS =
%i( key_prefix hash_length redis )
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#limits(action) ⇒ Hash
Get registered limit parameters for an action.
-
#max(action) ⇒ Integer
Get the limit cap registered to an action.
-
#period(action) ⇒ Integer
Get the limit period registered to an action.
-
#register(action, max, period) ⇒ Object
Register a default cap and period with an action name.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 |
# File 'lib/traffic_jam/configuration.rb', line 17 def initialize( = {}) OPTIONS.each do |option| self.send("#{option}=", [option]) end end |
Instance Method Details
#limits(action) ⇒ Hash
Get registered limit parameters for an action.
56 57 58 59 60 61 |
# File 'lib/traffic_jam/configuration.rb', line 56 def limits(action) @limits ||= {} limits = @limits[action.to_sym] raise TrafficJam::LimitNotFound.new(action) if limits.nil? limits end |
#max(action) ⇒ Integer
Get the limit cap registered to an action.
38 39 40 |
# File 'lib/traffic_jam/configuration.rb', line 38 def max(action) limits(action)[:max] end |
#period(action) ⇒ Integer
Get the limit period registered to an action.
46 47 48 |
# File 'lib/traffic_jam/configuration.rb', line 46 def period(action) limits(action)[:period] end |
#register(action, max, period) ⇒ Object
Register a default cap and period with an action name. For use with TrafficJam.limit.
29 30 31 32 |
# File 'lib/traffic_jam/configuration.rb', line 29 def register(action, max, period) @limits ||= {} @limits[action.to_sym] = { max: max, period: period } end |