Class: Insika::Commands::DeleteArtifact
- Inherits:
-
Object
- Object
- Insika::Commands::DeleteArtifact
- Defined in:
- lib/insika/commands/delete_artifact.rb
Overview
The Studio's delete on the Artifacts tab — a bus command, like every Studio mutation (the Studio never writes a store directly). Idempotent: an unknown id is a no-op, not an error.
Instance Method Summary collapse
-
#call(command) ⇒ Object
-> { deleted: id } | { deleted: nil } (unknown id).
-
#initialize(artifact_store:, event_stream:) ⇒ DeleteArtifact
constructor
A new instance of DeleteArtifact.
Constructor Details
#initialize(artifact_store:, event_stream:) ⇒ DeleteArtifact
Returns a new instance of DeleteArtifact.
11 12 13 14 |
# File 'lib/insika/commands/delete_artifact.rb', line 11 def initialize(artifact_store:, event_stream:) @artifact_store = artifact_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
-> { deleted: id } | { deleted: nil } (unknown id).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/insika/commands/delete_artifact.rb', line 17 def call(command) id = Coercion.presence(command.payload[:id] || command.payload["id"]) raise ValidationError, "id is required" if id.nil? deleted = @artifact_store.delete(id.to_s) if deleted @event_stream.emit(Insika::Event.new( type: :artifact_deleted, data: { id: id.to_s }, meta: { at: Time.now.utc.iso8601 } )) { deleted: id.to_s } else { deleted: nil } end end |