Class: Textus::Application::Writes::Delete

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

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, bus:) ⇒ Delete

Returns a new instance of Delete.



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

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

Instance Method Details

#call(key, 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
# File 'lib/textus/application/writes/delete.rb', line 10

def call(key, 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

  @ctx.store.writer.delete_envelope_from_disk(
    key, if_etag: if_etag, as: @ctx.role,
         correlation_id: @ctx.correlation_id
  )

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

  { "protocol" => Textus::PROTOCOL, "ok" => true, "key" => key, "deleted" => true }
end