Class: Textus::Write::Put

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

Instance Method Summary collapse

Methods included from Contract::DSL

arg, contract, contract?, response, summary, surfaces, verb

Constructor Details

#initialize(container:, call:) ⇒ Put

Returns a new instance of Put.



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

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

Instance Method Details

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/textus/write/put.rb', line 23

def call(key, meta: nil, body: nil, content: nil, if_etag: nil)
  Textus::Manifest::Data.validate_key!(key)
  mentry = @manifest.resolver.resolve(key).entry
  guard_for(:put, key, if_etag: if_etag).check!(eval_for(:put, target_key: key))

  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