Class: Insika::Commands::RestoreConcept
- Inherits:
-
Object
- Object
- Insika::Commands::RestoreConcept
- Defined in:
- lib/insika/commands/restore_concept.rb
Overview
Control command: restores an old version of a concept as the current
content (a new write — linear history, like RestoreSystemFile).
-> { name, agent, tenant, updated_at }.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(knowledge_store:, event_stream:) ⇒ RestoreConcept
constructor
A new instance of RestoreConcept.
Constructor Details
#initialize(knowledge_store:, event_stream:) ⇒ RestoreConcept
Returns a new instance of RestoreConcept.
11 12 13 14 |
# File 'lib/insika/commands/restore_concept.rb', line 11 def initialize(knowledge_store:, event_stream:) @knowledge_store = knowledge_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/insika/commands/restore_concept.rb', line 16 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? raise Insika::ValidationError, "version is required" if p[:version].nil? rec = @knowledge_store.restore(agent, name, p[:version], tenant: tenant) @event_stream.emit(Insika::Event.new( type: :knowledge_learned, data: { name: name, agent: agent }, meta: { at: Time.now.utc.iso8601 } )) { name: name, agent: agent, tenant: tenant, updated_at: rec["updated_at"] } end |