Class: Insika::Commands::UpdateSettings
- Inherits:
-
Object
- Object
- Insika::Commands::UpdateSettings
- Defined in:
- lib/insika/commands/update_settings.rb
Overview
Control command: merges a patch into the general settings (timeouts/streaming/compaction) and persists it in the SettingsStore. Only what came in the patch changes; the rest (and the defaults) is preserved. Takes effect on the next turn that reads settings. -> Hash (resulting settings).
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(settings_store:, event_stream:) ⇒ UpdateSettings
constructor
A new instance of UpdateSettings.
Constructor Details
#initialize(settings_store:, event_stream:) ⇒ UpdateSettings
Returns a new instance of UpdateSettings.
12 13 14 15 |
# File 'lib/insika/commands/update_settings.rb', line 12 def initialize(settings_store:, event_stream:) @settings_store = settings_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/insika/commands/update_settings.rb', line 17 def call(command) p = AgentPayload.symbolize(command.payload) patch = p[:patch] raise Insika::ValidationError, "patch must be an object" unless patch.nil? || patch.is_a?(Hash) raise Insika::ValidationError, "empty patch" if patch.nil? || patch.empty? settings = @settings_store.update(patch) @event_stream.emit(Insika::Event.new( type: :settings_updated, data: { keys: patch.keys.map(&:to_s) }, meta: { at: Time.now.utc.iso8601 } )) settings end |