class TrafficJam::Configuration

Configuration for TrafficJam library.

@see TrafficJam#configure

Constants

OPTIONS

Public Class Methods

new(options = {}) click to toggle source
# File lib/traffic_jam/configuration.rb, line 17
def initialize(options = {})
  OPTIONS.each do |option|
    self.send("#{option}=", options[option])
  end
end

Public Instance Methods

limits(action) click to toggle source

Get registered limit parameters for an action.

@see register @param action [Symbol] action name @return [Hash] max and period parameters in a hash @raise [TrafficJam::LimitNotFound] if action is not registered

# 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) click to toggle source

Get the limit cap registered to an action.

@see register @return [Integer] limit cap

# File lib/traffic_jam/configuration.rb, line 38
def max(action)
  limits(action)[:max]
end
period(action) click to toggle source

Get the limit period registered to an action.

@see register @return [Integer] limit period in seconds

# File lib/traffic_jam/configuration.rb, line 46
def period(action)
  limits(action)[:period]
end
register(action, max, period) click to toggle source

Register a default cap and period with an action name. For use with {TrafficJam.limit}.

@param action [Symbol] action name @param max [Integer] limit cap @param period [Fixnum] limit period in seconds

# File lib/traffic_jam/configuration.rb, line 29
def register(action, max, period)
  @limits ||= {}
  @limits[action.to_sym] = { max: max, period: period }
end