Module: TrafficJam

Includes:
Errors
Defined in:
lib/traffic_jam.rb,
lib/traffic_jam/limit.rb,
lib/traffic_jam/errors.rb,
lib/traffic_jam/scripts.rb,
lib/traffic_jam/limit_group.rb,
lib/traffic_jam/configuration.rb

Defined Under Namespace

Modules: Errors, Scripts Classes: Configuration, Limit, LimitGroup

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/traffic_jam.rb', line 18

def config
  @config
end

Class Method Details

.configure {|TrafficJam::Configuration| ... } ⇒ Object

Configure library in a block.



23
24
25
# File 'lib/traffic_jam.rb', line 23

def configure
  yield config
end

.limit(action, value) ⇒ TrafficJam::Limit

Create limit with registed max/period.

Parameters:

  • action (Symbol)

    registered action name

  • value (String)

    limit target value

Returns:



32
33
34
35
# File 'lib/traffic_jam.rb', line 32

def limit(action, value)
  limits = config.limits(action.to_sym)
  TrafficJam::Limit.new(action, value, **limits)
end

.reset_all(action: nil) ⇒ nil

Note:

Not recommended for use in production.

Reset all limits associated with the given action. If action is omitted or nil, this will reset all limits.

Parameters:

  • action (Symbol) (defaults to: nil)

    action to reset limits for

Returns:

  • (nil)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/traffic_jam.rb', line 43

def reset_all(action: nil)
  prefix =
    if action.nil?
      "#{config.key_prefix}:*"
    else
      "#{config.key_prefix}:#{action}:*"
    end
  config.redis.keys(prefix).each do |key|
    config.redis.del(key)
  end
  nil
end