Class: Insika::Commands::RejectHarvest
- Inherits:
-
Object
- Object
- Insika::Commands::RejectHarvest
- Defined in:
- lib/insika/commands/reject_harvest.rb
Overview
— the operator's dismissal: a candidate that is NOT yet
gated can be rejected by a human directly (a human may always outvote
the miner). The thin wrapper over mark_rejected.
Instance Method Summary collapse
-
#call(command) ⇒ Object
payload: { candidate_id:, operator?, note? } -> Candidate (rejected).
-
#initialize(harvest_store:, event_stream:) ⇒ RejectHarvest
constructor
A new instance of RejectHarvest.
Constructor Details
#initialize(harvest_store:, event_stream:) ⇒ RejectHarvest
Returns a new instance of RejectHarvest.
11 12 13 14 |
# File 'lib/insika/commands/reject_harvest.rb', line 11 def initialize(harvest_store:, event_stream:) @harvest_store = harvest_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
payload: { candidate_id:, operator?, note? } -> Candidate (rejected)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/insika/commands/reject_harvest.rb', line 18 def call(command) p = AgentPayload.symbolize(command.payload) candidate_id = AgentPayload.presence(p[:candidate_id]) raise Insika::ValidationError, "candidate_id is required" if candidate_id.nil? candidate = @harvest_store.find_candidate(candidate_id) || (raise Insika::NotFoundError, "harvest candidate not found: #{candidate_id}") operator = (AgentPayload.presence(p[:operator]) || command.[:operator] || "operator").to_s rejected = @harvest_store.mark_rejected(candidate.id, operator: operator, note: p[:note]) @event_stream.emit(Insika::Event.new( type: :harvest_rejected, data: { candidate_id: candidate.id, agent: candidate.agent, operator: operator }, meta: { at: Time.now.utc.iso8601 } )) rejected end |