Class: Textus::Application::Writes::Put

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/application/writes/put.rb

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, bus:) ⇒ Put

Returns a new instance of Put.



5
6
7
8
# File 'lib/textus/application/writes/put.rb', line 5

def initialize(ctx:, bus:)
  @ctx = ctx
  @bus = bus
end

Instance Method Details

#call(key, meta: nil, body: nil, content: nil, if_etag: nil, suppress_events: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/textus/application/writes/put.rb', line 10

def call(key, meta: nil, body: nil, content: nil, if_etag: nil, suppress_events: false)
  @ctx.store.manifest.validate_key!(key)
  mentry, = @ctx.store.manifest.resolve(key)

  unless @ctx.can_write?(mentry.zone)
    raise WriteForbidden.new(key, mentry.zone,
                             writers: @ctx.store.manifest.zone_writers(mentry.zone))
  end

  envelope = @ctx.store.writer.write_envelope_to_disk(
    key,
    mentry: mentry,
    payload: Textus::Store::Writer::Payload.new(meta: meta, body: body, content: content),
    ctx: @ctx,
    if_etag: if_etag,
  )

  unless suppress_events
    @bus.publish(:entry_put,
                 store: @ctx.with_role(@ctx.role),
                 key: key,
                 envelope: envelope,
                 correlation_id: @ctx.correlation_id)
  end

  envelope
end