Class: Textus::Handlers::Write::RejectProposal

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/handlers/write/reject_proposal.rb

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ RejectProposal

Returns a new instance of RejectProposal.



5
6
7
# File 'lib/textus/handlers/write/reject_proposal.rb', line 5

def initialize(container:)
  @container = container
end

Instance Method Details

#call(command, call) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/textus/handlers/write/reject_proposal.rb', line 9

def call(command, call)
  mentry = @container.manifest.resolver.resolve(command.pending_key).entry
  unless mentry.in_proposal_lane?(@container.manifest.policy)
    return Value::Result.failure(:proposal_error,
                                 "reject: '#{command.pending_key}' is not in a proposal zone (zone=#{mentry.lane})")
  end

  reader = Store::Entry::Reader.from(container: @container)
  env = reader.read(command.pending_key)
  proposal = env&.meta&.dig("proposal") or
    return Value::Result.failure(:proposal_error, "entry has no proposal block: #{command.pending_key}")
  target_key = proposal["target_key"]

  writer = Store::Entry::Writer.from(container: @container, call: call)
  writer.delete(command.pending_key, mentry: mentry)
  Value::Result.success("protocol" => Textus::PROTOCOL, "rejected" => command.pending_key, "target_key" => target_key)
end