Class: Insika::StoredProfileSource

Inherits:
Object
  • Object
show all
Includes:
Coercion, ProfileSource
Defined in:
lib/insika/profile_source.rb

Overview

Persisted source (Studio): reads/writes profiles in the ConfigStore (scope "agents"). Each fetch reads FRESH from the store — an edit via the Studio takes effect on the next dispatch, without a restart. An in-flight turn keeps the profile it captured (the Commands resolve at the start of #call), so the turn semantics are preserved.

Constant Summary collapse

SCOPE =
"agents"

Instance Method Summary collapse

Methods included from Coercion

blank?, deep_stringify, presence, present?, utf8

Methods included from ProfileSource

#[], coerce

Constructor Details

#initialize(config_store:) ⇒ StoredProfileSource

Returns a new instance of StoredProfileSource.



57
58
59
# File 'lib/insika/profile_source.rb', line 57

def initialize(config_store:)
  @cs = config_store
end

Instance Method Details

#allObject



66
# File 'lib/insika/profile_source.rb', line 66

def all = @cs.all(SCOPE).map { |r| deserialize(r) }

#delete(id) ⇒ Object



75
# File 'lib/insika/profile_source.rb', line 75

def delete(id) = @cs.delete(SCOPE, id.to_s)

#fetch(id) ⇒ Object



61
62
63
64
# File 'lib/insika/profile_source.rb', line 61

def fetch(id)
  record = @cs.get(SCOPE, id.to_s)
  record && deserialize(record)
end

#idsObject



67
# File 'lib/insika/profile_source.rb', line 67

def ids = @cs.keys(SCOPE)

#put(profile) ⇒ Object

Write (used by the :create_agent/:update_agent Commands).



70
71
72
73
# File 'lib/insika/profile_source.rb', line 70

def put(profile)
  @cs.put(SCOPE, profile.id, profile.to_h)
  profile
end