Class: Textus::Application::Writes::Reject

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/application/writes/reject.rb

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, envelope_io:) ⇒ Reject

Returns a new instance of Reject.



5
6
7
8
# File 'lib/textus/application/writes/reject.rb', line 5

def initialize(ctx:, envelope_io:)
  @ctx = ctx
  @envelope_io = envelope_io
end

Instance Method Details

#call(pending_key) ⇒ Object

Raises:



10
11
12
13
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/reject.rb', line 10

def call(pending_key)
  raise ProposalError.new("only human role can reject proposals; got '#{@ctx.role}'") unless @ctx.role == "human"

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

  env = Textus::Application::Reads::Get.new(ctx: @ctx).call(pending_key)
  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")

  Textus::Application::Writes::Delete.new(ctx: @ctx, envelope_io: @envelope_io).call(pending_key, suppress_events: true)

  @ctx.bus.publish(:proposal_rejected,
                   store: @ctx.with_role(@ctx.role),
                   key: pending_key,
                   target_key: target_key,
                   correlation_id: @ctx.correlation_id)

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