Class: Textus::Write::Delete

Inherits:
Object
  • Object
show all
Extended by:
Contract::DSL
Defined in:
lib/textus/write/delete.rb

Instance Method Summary collapse

Methods included from Contract::DSL

arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view

Constructor Details

#initialize(container:, call:) ⇒ Delete

‘call` already returns a wire hash ok, key, deleted; identity response.



17
18
19
20
21
22
# File 'lib/textus/write/delete.rb', line 17

def initialize(container:, call:)
  @container    = container
  @call         = call
  @manifest     = container.manifest
  @events       = container.events
end

Instance Method Details

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/textus/write/delete.rb', line 24

def call(key, if_etag: nil, suppress_events: false)
  Textus::Manifest::Data.validate_key!(key)
  mentry = @manifest.resolver.resolve(key).entry

  guard_for(:delete, key, if_etag: if_etag).check!(eval_for(:delete, target_key: key))

  writer.delete(key, mentry: mentry, if_etag: if_etag)

  unless suppress_events
    @events.publish(:entry_deleted,
                    ctx: hook_context,
                    key: key)
  end

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