Class: Hecks::Runtime::PolicyInterpreter
- Inherits:
-
Object
- Object
- Hecks::Runtime::PolicyInterpreter
- Defined in:
- lib/hecks/runtime/policy_interpreter.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(registry, door:) ⇒ PolicyInterpreter
constructor
A new instance of PolicyInterpreter.
-
#react(event, domain) ⇒ Object
deliverreturnsnilfor a policy whosewheredid not hold — SILENTLY, the same as a policypolicies_fornever selected at all (anevent_qualifiermiss carries no reaction_log entry either) — so nothing is appended for it.
Constructor Details
#initialize(registry, door:) ⇒ PolicyInterpreter
Returns a new instance of PolicyInterpreter.
14 15 16 17 |
# File 'lib/hecks/runtime/policy_interpreter.rb', line 14 def initialize(registry, door:) @registry = registry @door = door end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
12 13 14 |
# File 'lib/hecks/runtime/policy_interpreter.rb', line 12 def registry @registry end |
Instance Method Details
#react(event, domain) ⇒ Object
deliver returns nil for a policy whose where did not hold —
SILENTLY, the same as a policy policies_for never selected at all
(an event_qualifier miss carries no reaction_log entry either) —
so nothing is appended for it. A for_each policy answers an ARRAY
(one record per matched row) rather than one record ; Array(...)
is wrong here (it would explode a plain record Hash into its own
key/value pairs), so the two shapes are told apart explicitly.
26 27 28 29 30 31 32 33 |
# File 'lib/hecks/runtime/policy_interpreter.rb', line 26 def react(event, domain) policies_for(event).each do |policy, home_domain| result = deliver(policy, event, home_domain) next if result.nil? (result.is_a?(Array) ? result : [result]).each { |record| @registry.reaction_log << record } end end |