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:, envelope_io:) ⇒ Put

Returns a new instance of Put.



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

def initialize(ctx:, envelope_io:)
  @ctx = ctx
  @envelope_io = envelope_io
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
# 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.manifest.validate_key!(key)
  mentry = @ctx.manifest.resolve(key).entry

  @ctx.authorize_write!(mentry)

  envelope = @envelope_io.write(
    key,
    mentry: mentry,
    payload: Textus::Application::Writes::EnvelopeIO::Payload.new(meta: meta, body: body, content: content),
    if_etag: if_etag,
  )

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

  envelope
end