Class: Textus::Write::Put

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

Instance Method Summary collapse

Constructor Details

#initialize(container:, call:) ⇒ Put

Returns a new instance of Put.



4
5
6
7
8
9
10
# File 'lib/textus/write/put.rb', line 4

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

Instance Method Details

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



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

def call(key, meta: nil, body: nil, content: nil, if_etag: nil)
  Textus::Manifest::Data.validate_key!(key)
  mentry = @manifest.resolver.resolve(key).entry
  @authorizer.authorize_write!(mentry, role: @call.role)

  envelope = writer.put(
    key,
    mentry: mentry,
    payload: Textus::Envelope::IO::Writer::Payload.new(
      meta: meta, body: body, content: content,
    ),
    if_etag: if_etag,
  )

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

  envelope
end