Class: Textus::Write::Accept
- Inherits:
-
Object
- Object
- Textus::Write::Accept
- Defined in:
- lib/textus/write/accept.rb
Instance Method Summary collapse
- #call(pending_key) ⇒ Object
-
#initialize(container:, call:) ⇒ Accept
constructor
A new instance of Accept.
Constructor Details
#initialize(container:, call:) ⇒ Accept
Returns a new instance of Accept.
4 5 6 7 8 9 10 |
# File 'lib/textus/write/accept.rb', line 4 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/textus/write/accept.rb', line 12 def call(pending_key) env = Textus::Read::Get.new(container: @container, call: @call).call(pending_key) proposal = env.["proposal"] or raise ProposalError.new("entry has no proposal block: #{pending_key}") target = proposal["target_key"] or raise ProposalError.new("proposal missing target_key") action = proposal["action"] || "put" guard.for(:accept, target).check!( Textus::Domain::Policy::Evaluation.new( actor: @call.role, transition: :accept, origin: pending_key, target: target, envelope: env, manifest: @manifest ), ) case action when "put" put_op.call(target, meta: env.["frontmatter"] || {}, body: env.body) when "delete" delete_op.call(target) else raise ProposalError.new("unknown action: #{action}") end delete_op.call(pending_key) @events.publish(:proposal_accepted, ctx: hook_context, key: pending_key, target_key: target) { "protocol" => PROTOCOL, "accepted" => pending_key, "target_key" => target, "action" => action } end |