Class: Textus::Action::Reject

Inherits:
WriteVerb show all
Extended by:
Contract::DSL
Defined in:
lib/textus/action/reject.rb

Constant Summary collapse

BURN =
:sync

Instance Method Summary collapse

Methods included from Contract::DSL

arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view

Methods inherited from Base

#args, inherited

Constructor Details

#initialize(pending_key:) ⇒ Reject

Returns a new instance of Reject.



16
17
18
19
# File 'lib/textus/action/reject.rb', line 16

def initialize(pending_key:)
  super()
  @pending_key = pending_key
end

Instance Method Details

#call(container:, call:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/textus/action/reject.rb', line 21

def call(container:, call:)
  run_with_cascade(@pending_key, container:, call:) do
    auth = Textus::Gate::Auth.new(container)
    auth.check_action!(action: :reject, actor: call.role, key: @pending_key)

    mentry = container.manifest.resolver.resolve(@pending_key).entry
    unless mentry.in_proposal_lane?(container.manifest.policy)
      raise ProposalError.new("reject: '#{@pending_key}' is not in a proposal zone (zone=#{mentry.lane})")
    end

    env = Textus::Action::Get.new(key: @pending_key).call(container: container, call: call)
    proposal = env.meta&.dig("proposal") or raise ProposalError.new("entry has no proposal block: #{@pending_key}")
    target_key = proposal["target_key"] or raise ProposalError.new("proposal missing target_key")

    writer(container, call).delete(@pending_key, mentry: mentry)

    container.steps.publish(
      :proposal_rejected,
      ctx: Textus::Step::Context.for(container: container, call: call),
      key: @pending_key,
      target_key: target_key,
    )

    { "protocol" => PROTOCOL, "rejected" => @pending_key, "target_key" => target_key }
  end
end