Class: Textus::Write::Reject

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

Instance Method Summary collapse

Methods included from Contract::DSL

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

Constructor Details

#initialize(container:, call:) ⇒ Reject

Returns a new instance of Reject.



12
13
14
15
16
17
18
# File 'lib/textus/write/reject.rb', line 12

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

Instance Method Details

#call(pending_key) ⇒ Object



20
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
47
48
49
# File 'lib/textus/write/reject.rb', line 20

def call(pending_key)
  guard.for(:reject, pending_key).check!(
    Textus::Domain::Policy::Evaluation.new(
      actor: @call.role, transition: :reject, origin: pending_key,
      target: pending_key, envelope: nil, manifest: @manifest
    ),
  )

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

  env = Textus::Read::Get.new(
    container: @container, call: @call,
  ).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")

  delete_op.call(pending_key, suppress_events: true)

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

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