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:, manifest:, envelope_io:, bus:, authorizer:, hook_context:) ⇒ Put

Returns a new instance of Put.



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

def initialize(ctx:, manifest:, envelope_io:, bus:, authorizer:, hook_context:)
  @ctx          = ctx
  @manifest     = manifest
  @envelope_io  = envelope_io
  @bus          = bus
  @authorizer   = authorizer
  @hook_context = hook_context
end

Instance Method Details

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



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

def call(key, meta: nil, body: nil, content: nil, if_etag: nil)
  @manifest.validate_key!(key)
  mentry = @manifest.resolver.resolve(key).entry

  @authorizer.authorize_write!(mentry, role: @ctx.role)

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

  @bus.publish(:entry_put,
               ctx: @hook_context,
               key: key,
               envelope: envelope)

  envelope
end