Module: Hecks::Ports::Projection

Defined in:
lib/hecks/ports/projection.rb

Overview

Projection is a read-side port. Its stores are rebuildable consumers of authoritative entries and never participate in command decisions.

Defined Under Namespace

Classes: Queue, Worker

Constant Summary collapse

NAME =
"projection"
VERB =
"projected_by"

Class Method Summary collapse

Class Method Details

.binds_for(registry, domain, aggregate) ⇒ Object



15
16
17
# File 'lib/hecks/ports/projection.rb', line 15

def binds_for(registry, domain, aggregate)
  registry.hecksagon(domain)&.binds_for(aggregate.hecks_name, VERB) || []
end

.worker(registry, domain, aggregate, policy: :refresh) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/hecks/ports/projection.rb', line 19

def worker(registry, domain, aggregate, policy: :refresh)
  bind = binds_for(registry, domain, aggregate).first
  return unless bind

  authoritative = Persistence.repository(registry, domain, aggregate)
  target = Persistence::RepositoryFactory.build(registry, domain, aggregate, bind,
                                                recover: true, settings_verb: VERB)
  Worker.new(authoritative, target, policy: policy)
end