Class: Hecks::Runtime::DependencyPlanning::Analyzer
- Inherits:
-
Object
- Object
- Hecks::Runtime::DependencyPlanning::Analyzer
- Defined in:
- lib/hecks/runtime/dependency_planning.rb
Constant Summary collapse
- STATEFUL_MUTATIONS =
%i[append increment decrement multiply clamp remove].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(aggregate, command) ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize(aggregate, command) ⇒ Analyzer
Returns a new instance of Analyzer.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/hecks/runtime/dependency_planning.rb', line 67 def initialize(aggregate, command) @aggregate = aggregate @command = command @owner_fields = aggregate.attributes.to_set(&:name) @owner_fields << aggregate.lifecycle.field.to_sym if aggregate.lifecycle @payload_fields = command.attributes.to_set(&:name) @state_reads = Set.new @payload_reads = Set.new @writes = Set.new @known_writes = Set.new @unresolved = Set.new end |
Class Method Details
.call(aggregate:, command:) ⇒ Object
65 |
# File 'lib/hecks/runtime/dependency_planning.rb', line 65 def self.call(aggregate:, command:) = new(aggregate, command).call |
Instance Method Details
#call ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hecks/runtime/dependency_planning.rb', line 80 def call analyze_initial_state analyze_mutations analyze_lifecycle analyze_rules(command.givens, phase: :before) analyze_rules(command.ensures, phase: :after) analyze_rules(aggregate.invariants, phase: :after) add_preservation_reads complete = unresolved.empty? && owner_fields.subset?(known_writes) independent = complete && state_reads.empty? Plan.new( read_set: sorted(state_reads), write_set: sorted(writes), payload_read_set: sorted(payload_reads), complete_state: complete, state_independent: independent, unresolved_dependencies: unresolved.to_a.sort.freeze ).freeze end |