Class: Textus::Handlers::Write::AcceptProposal
- Inherits:
-
Object
- Object
- Textus::Handlers::Write::AcceptProposal
- Defined in:
- lib/textus/handlers/write/accept_proposal.rb
Instance Method Summary collapse
- #call(command, call) ⇒ Object
-
#initialize(container:) ⇒ AcceptProposal
constructor
A new instance of AcceptProposal.
Constructor Details
#initialize(container:) ⇒ AcceptProposal
Returns a new instance of AcceptProposal.
5 6 7 |
# File 'lib/textus/handlers/write/accept_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 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/textus/handlers/write/accept_proposal.rb', line 9 def call(command, call) reader = Store::Entry::Reader.from(container: @container) env = reader.read(command.pending_key) proposal = env&.&.dig("proposal") or return Value::Result.failure(:proposal_error, "entry has no proposal block: #{command.pending_key}") target = proposal["target_key"] or return Value::Result.failure(:proposal_error, "proposal missing target_key") action = proposal["action"] || "put" writer = Store::Entry::Writer.from(container: @container, call: call) case action when "put" mentry = @container.manifest.resolver.resolve(target).entry writer.put( target, mentry: mentry, payload: Textus::Value::Payload.new(meta: env.["_meta"] || {}, body: env.body, content: nil) ) when "delete" writer.delete(target) else return Value::Result.failure(:proposal_error, "unknown action: #{action}") end writer.delete(command.pending_key) Value::Result.success("protocol" => Textus::PROTOCOL, "accepted" => command.pending_key, "target_key" => target, "action" => action, "cascade_key" => target) end |