Class: Insika::Commands::DeleteSystemFile

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/commands/delete_system_file.rb

Overview

Control command: removes a global system file from the SystemFileStore. Idempotent (existed: false). -> { existed: bool }.

Instance Method Summary collapse

Constructor Details

#initialize(system_file_store:, event_stream:) ⇒ DeleteSystemFile

Returns a new instance of DeleteSystemFile.



10
11
12
13
# File 'lib/insika/commands/delete_system_file.rb', line 10

def initialize(system_file_store:, event_stream:)
  @system_files = system_file_store
  @event_stream = event_stream
end

Instance Method Details

#call(command) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/insika/commands/delete_system_file.rb', line 15

def call(command)
  p = AgentPayload.symbolize(command.payload)
  file = AgentPayload.presence(p[:file])
  raise Insika::ValidationError, "file is required" if file.nil?

  existed = @system_files.delete(file)
  @event_stream.emit(Insika::Event.new(
                       type: :system_file_deleted, data: { file: file, existed: existed },
                       meta: { at: Time.now.utc.iso8601 }
                     ))
  { existed: existed }
end