Class: Textus::Application::Writes::Accept
- Inherits:
-
Object
- Object
- Textus::Application::Writes::Accept
- Defined in:
- lib/textus/application/writes/accept.rb
Instance Method Summary collapse
- #call(pending_key) ⇒ Object
-
#initialize(ctx:, manifest:, file_store:, schemas:, envelope_io:, bus:, authorizer:, hook_context:) ⇒ Accept
constructor
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(ctx:, manifest:, file_store:, schemas:, envelope_io:, bus:, authorizer:, hook_context:) ⇒ Accept
rubocop:disable Metrics/ParameterLists
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/textus/application/writes/accept.rb', line 5 def initialize(ctx:, manifest:, file_store:, schemas:, envelope_io:, bus:, authorizer:, hook_context:) # rubocop:disable Metrics/ParameterLists @ctx = ctx @manifest = manifest @file_store = file_store @schemas = schemas @envelope_io = envelope_io @bus = bus @authorizer = @hook_context = hook_context end |
Instance Method Details
#call(pending_key) ⇒ Object
16 17 18 19 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/application/writes/accept.rb', line 16 def call(pending_key) raise ProposalError.new("only human role can accept proposals; got '#{@ctx.role}'") unless @ctx.role == "human" env = Textus::Application::Reads::Get.new( ctx: @ctx, manifest: @manifest, file_store: @file_store, ).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" evaluate_promotion!(env, target) case action when "put" # Nested proposal "frontmatter" — the meta to write to the accepted # target. Not related to the removed intake-handler legacy bridge. = env.["frontmatter"] || {} target_body = env.body put_op.call(target, meta: , body: target_body) when "delete" delete_op.call(target) else raise ProposalError.new("unknown action: #{action}") end delete_op.call(pending_key) @bus.publish(:proposal_accepted, ctx: @hook_context, key: pending_key, target_key: target) { "protocol" => PROTOCOL, "accepted" => pending_key, "target_key" => target, "action" => action } end |