Class: Labkit::RateLimit::Config::Document
- Inherits:
-
Object
- Object
- Labkit::RateLimit::Config::Document
- Defined in:
- lib/labkit/rate_limit/config/document.rb
Overview
Document is what Loader#load returns: the merged contract and the rules of the rate limits file, per limiter, as Rule objects a Limiter can use. It is immutable; a host builds a new one to reload.
Defined Under Namespace
Classes: Limiter
Instance Attribute Summary collapse
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
-
.empty ⇒ Object
A document with no limiters: every host default applies unchanged.
Instance Method Summary collapse
-
#available_properties(name) ⇒ Array<Symbol>
The properties a rule of this limiter may use.
-
#default_rules(name) ⇒ Array<Rule>
The contract's default rules, document order.
-
#initialize(limiters, warnings) ⇒ Document
constructor
A new instance of Document.
- #limiter?(name) ⇒ Boolean
-
#limiters ⇒ Array<String>
Every limiter the contract declares.
-
#override_rules(name) ⇒ Array<Rule>
The file rules for this limiter, document order.
-
#protected_rules(name) ⇒ Array<String>
Default rule names no override may replace.
Constructor Details
#initialize(limiters, warnings) ⇒ Document
Returns a new instance of Document.
22 23 24 25 |
# File 'lib/labkit/rate_limit/config/document.rb', line 22 def initialize(limiters, warnings) @limiters = limiters.freeze @warnings = warnings.freeze end |
Instance Attribute Details
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
13 14 15 |
# File 'lib/labkit/rate_limit/config/document.rb', line 13 def warnings @warnings end |
Class Method Details
.empty ⇒ Object
A document with no limiters: every host default applies unchanged.
16 17 18 |
# File 'lib/labkit/rate_limit/config/document.rb', line 16 def self.empty new({}, []) end |
Instance Method Details
#available_properties(name) ⇒ Array<Symbol>
Returns the properties a rule of this limiter may use.
37 38 39 |
# File 'lib/labkit/rate_limit/config/document.rb', line 37 def available_properties(name) slice(name)&.properties || [] end |
#default_rules(name) ⇒ Array<Rule>
Returns the contract's default rules, document order.
47 48 49 |
# File 'lib/labkit/rate_limit/config/document.rb', line 47 def default_rules(name) slice(name)&.default_rules || [] end |
#limiter?(name) ⇒ Boolean
27 28 29 |
# File 'lib/labkit/rate_limit/config/document.rb', line 27 def limiter?(name) @limiters.key?(name.to_s) end |
#limiters ⇒ Array<String>
Returns every limiter the contract declares.
32 33 34 |
# File 'lib/labkit/rate_limit/config/document.rb', line 32 def limiters @limiters.keys end |
#override_rules(name) ⇒ Array<Rule>
Returns the file rules for this limiter, document order.
42 43 44 |
# File 'lib/labkit/rate_limit/config/document.rb', line 42 def override_rules(name) slice(name)&.override_rules || [] end |
#protected_rules(name) ⇒ Array<String>
Returns default rule names no override may replace.
52 53 54 |
# File 'lib/labkit/rate_limit/config/document.rb', line 52 def protected_rules(name) slice(name)&.protected_rules || [] end |