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/gcra_limit.rb,
lib/traffic_jam/limit_group.rb,
lib/traffic_jam/configuration.rb,
lib/traffic_jam/rolling_limit.rb,
lib/traffic_jam/lifetime_limit.rb
Defined Under Namespace
Modules: Errors, Scripts Classes: Configuration, GCRALimit, LifetimeLimit, Limit, LimitGroup, RollingLimit
Constant Summary collapse
- SimpleLimit =
alias for backward compatibility
GCRALimit
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.configure {|TrafficJam::Configuration| ... } ⇒ Object
Configure library in a block.
-
.limit(action, value) ⇒ TrafficJam::Limit
Create limit with registed max/period.
-
.reset_all(action: nil) ⇒ nil
Reset all limits associated with the given action.
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/traffic_jam.rb', line 20 def config @config end |
Class Method Details
.configure {|TrafficJam::Configuration| ... } ⇒ Object
Configure library in a block.
25 26 27 |
# File 'lib/traffic_jam.rb', line 25 def configure yield config end |
.limit(action, value) ⇒ TrafficJam::Limit
Create limit with registed max/period.
34 35 36 37 |
# File 'lib/traffic_jam.rb', line 34 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.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/traffic_jam.rb', line 45 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 |