Class: Textus::Application::Write::Accept::Impl

Inherits:
Object
  • Object
show all
Includes:
Textus::Application::Write::AuthorityGate
Defined in:
lib/textus/application/write/accept.rb

Instance Method Summary collapse

Methods included from Textus::Application::Write::AuthorityGate

#assert_accept_authority!

Constructor Details

#initialize(ctx:, caps:, writer:, hook_context:) ⇒ Impl

Returns a new instance of Impl.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/textus/application/write/accept.rb', line 18

def initialize(ctx:, caps:, writer:, hook_context:)
  @ctx          = ctx
  @caps         = caps
  @manifest     = caps.manifest
  @file_store   = caps.file_store
  @schemas      = caps.schemas
  @writer       = writer
  @events       = caps.events
  @authorizer   = caps.authorizer
  @hook_context = hook_context
end

Instance Method Details

#call(pending_key) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/textus/application/write/accept.rb', line 30

def call(pending_key)
  assert_accept_authority!("accept")

  env = Textus::Application::Read::Get::Impl.new(
    ctx: @ctx, caps: @caps,
  ).call(pending_key)
  proposal = env.meta["proposal"] or raise ProposalError.new("entry has no proposal block: #{pending_key}")
  target = proposal["target_key"] or raise ProposalError.new("proposal missing target_key")
  action = proposal["action"] || "put"

  evaluate_promotion!(env, target)

  case action
  when "put"
    # Nested proposal "frontmatter" — the meta to write to the accepted
    # target. Not related to the removed intake-handler legacy bridge.
    target_meta = env.meta["frontmatter"] || {}
    target_body = env.body
    put_op.call(target, meta: target_meta, body: target_body)
  when "delete"
    delete_op.call(target)
  else
    raise ProposalError.new("unknown action: #{action}")
  end

  delete_op.call(pending_key)

  @events.publish(:proposal_accepted,
                  ctx: @hook_context,
                  key: pending_key,
                  target_key: target)

  { "protocol" => PROTOCOL, "accepted" => pending_key, "target_key" => target, "action" => action }
end