Class: Insika::Commands::DeleteConcept
- Inherits:
-
Object
- Object
- Insika::Commands::DeleteConcept
- Defined in:
- lib/insika/commands/delete_concept.rb
Overview
Control command: removes a learned concept from the KnowledgeStore. -> { name, agent, tenant, deleted: true }.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(knowledge_store:, event_stream:) ⇒ DeleteConcept
constructor
A new instance of DeleteConcept.
Constructor Details
#initialize(knowledge_store:, event_stream:) ⇒ DeleteConcept
Returns a new instance of DeleteConcept.
10 11 12 13 |
# File 'lib/insika/commands/delete_concept.rb', line 10 def initialize(knowledge_store:, event_stream:) @knowledge_store = knowledge_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/insika/commands/delete_concept.rb', line 15 def call(command) p = AgentPayload.symbolize(command.payload) name = AgentPayload.presence(p[:name]) agent = AgentPayload.presence(p[:agent]) tenant = AgentPayload.presence(p[:tenant]) raise Insika::ValidationError, "name is required" if name.nil? raise Insika::ValidationError, "agent is required" if agent.nil? deleted = @knowledge_store.delete(agent, name, tenant: tenant) raise Insika::NotFoundError, "concept '#{name}' not found for agent '#{agent}'" unless deleted @event_stream.emit(Insika::Event.new( type: :knowledge_deleted, data: { name: name, agent: agent }, meta: { at: Time.now.utc.iso8601 } )) { name: name, agent: agent, tenant: tenant, deleted: true } end |