Class: Engram::Persistence
- Inherits:
-
Object
- Object
- Engram::Persistence
- Defined in:
- lib/engram/persistence.rb
Overview
Applies persistence hooks and policy consistently before writing records.
Instance Method Summary collapse
- #add(record, scope: record.scope) ⇒ Object
-
#initialize(store:, embedder:, before_persist: Engram.config.before_persist, persistence_policy: Engram.config.persistence_policy) ⇒ Persistence
constructor
A new instance of Persistence.
- #update(scope:, id:, record:) ⇒ Object
Constructor Details
#initialize(store:, embedder:, before_persist: Engram.config.before_persist, persistence_policy: Engram.config.persistence_policy) ⇒ Persistence
Returns a new instance of Persistence.
6 7 8 9 10 11 12 |
# File 'lib/engram/persistence.rb', line 6 def initialize(store:, embedder:, before_persist: Engram.config.before_persist, persistence_policy: Engram.config.persistence_policy) @store = store @embedder = @before_persist = before_persist @persistence_policy = persistence_policy end |
Instance Method Details
#add(record, scope: record.scope) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/engram/persistence.rb', line 14 def add(record, scope: record.scope) record = prepare(record) if record && record.scope != scope raise Engram::Error, "cannot move memory across scopes" end @store.add(record) if record end |
#update(scope:, id:, record:) ⇒ Object
22 23 24 25 |
# File 'lib/engram/persistence.rb', line 22 def update(scope:, id:, record:) record = prepare(record) @store.update(scope: scope, id: id, record: record) if record end |