Class: Labkit::RateLimit::Rule
- Inherits:
-
Data
- Object
- Data
- Labkit::RateLimit::Rule
- Defined in:
- lib/labkit/rate_limit/rule.rb
Overview
Rule is a value object describing a single rate limit rule. name - stable identifier used in Redis keys and log entries match - hash of identifier key/value pairs that must all match for
the rule to apply; empty hash matches any identifier
limit - request threshold; may be a callable (resolved per check) period - window in seconds; may be a callable (resolved per check) action - :block (enforce) or :log (count and log, but do not block) characteristics - identifier keys used to build the compound Redis counter key
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#characteristics ⇒ Object
readonly
Returns the value of attribute characteristics.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
-
#initialize(name:, limit:, period:, characteristics:, match: {}, action: :block) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(name:, limit:, period:, characteristics:, match: {}, action: :block) ⇒ Rule
Returns a new instance of Rule.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/labkit/rate_limit/rule.rb', line 14 def initialize(name:, limit:, period:, characteristics:, match: {}, action: :block) super( name: name.to_s.tr(":", "_"), match: match.transform_keys(&:to_sym).freeze, limit: limit, period: period, action: action.to_sym, characteristics: Array(characteristics).map(&:to_sym).freeze ) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def action @action end |
#characteristics ⇒ Object (readonly)
Returns the value of attribute characteristics
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def characteristics @characteristics end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def limit @limit end |
#match ⇒ Object (readonly)
Returns the value of attribute match
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def match @match end |
#name ⇒ Object (readonly)
Returns the value of attribute name
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def name @name end |
#period ⇒ Object (readonly)
Returns the value of attribute period
13 14 15 |
# File 'lib/labkit/rate_limit/rule.rb', line 13 def period @period end |