Class: Textus::Manifest::Rules
- Inherits:
-
Object
- Object
- Textus::Manifest::Rules
- Defined in:
- lib/textus/manifest/rules.rb
Defined Under Namespace
Constant Summary collapse
- PICK_FIELDS =
Every structural member here derives from Schema::FIELD_REGISTRY (WS3), so a new rule field is added in one place. ‘in_pick` selects the fields that participate in the most-specific `for(key)` resolution.
Schema::FIELD_REGISTRY.select { |_, m| m[:in_pick] }.keys.freeze
- EMPTY_SET =
RuleSet.new(**PICK_FIELDS.to_h { |f| [f, nil] })
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Class Method Summary collapse
Instance Method Summary collapse
- #explain(key) ⇒ Object
- #for(key) ⇒ Object
-
#initialize(blocks) ⇒ Rules
constructor
A new instance of Rules.
Constructor Details
#initialize(blocks) ⇒ Rules
Returns a new instance of Rules.
16 17 18 |
# File 'lib/textus/manifest/rules.rb', line 16 def initialize(blocks) @blocks = blocks end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
20 21 22 |
# File 'lib/textus/manifest/rules.rb', line 20 def blocks @blocks end |
Class Method Details
Instance Method Details
#explain(key) ⇒ Object
32 33 34 |
# File 'lib/textus/manifest/rules.rb', line 32 def explain(key) @blocks.select { |b| Textus::Domain::Policy::Matcher.matches?(b.match, key) } end |
#for(key) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/textus/manifest/rules.rb', line 22 def for(key) slots = PICK_FIELDS.to_h { |f| [f, []] } @blocks.each do |b| next unless Textus::Domain::Policy::Matcher.matches?(b.match, key) slots.each_key { |slot| slots[slot] << b if b.public_send(slot) } end RuleSet.new(**slots.to_h { |slot, blocks| [slot, pick(blocks, slot, key)] }) end |