Class: ActiveHarness::Memory::Postgresql
- Inherits:
-
ActiveHarness::Memory
- Object
- ActiveHarness::Memory
- ActiveHarness::Memory::Postgresql
- Defined in:
- lib/active_harness/memory/adapter/postgresql.rb
Overview
Convenience Memory subclass for PostgreSQL-backed storage.
Requires the âpgâ gem installed by the application:
gem 'pg'
Usage â plain Ruby (adapter owns the connection):
mem = ActiveHarness::Memory::Postgresql.new(
session_id: "user_42",
url: ENV["DATABASE_URL"],
depth: 10
)
mem.load
# ... use ...
mem.close
Usage â Rails (borrow the AR raw connection):
mem = ActiveHarness::Memory::Postgresql.new(
session_id: "user_42",
connection: ActiveRecord::Base.connection.raw_connection
)
Constant Summary
Constants inherited from ActiveHarness::Memory
Instance Attribute Summary
Attributes inherited from ActiveHarness::Memory
Instance Method Summary collapse
-
#initialize(session_id:, namespace: nil, on_trim: nil, **opts) ⇒ Postgresql
constructor
A new instance of Postgresql.
Methods inherited from ActiveHarness::Memory
#clear, #close, #delete, #load, #record, #size, #to_messages, #turns
Constructor Details
#initialize(session_id:, namespace: nil, on_trim: nil, **opts) ⇒ Postgresql
Returns a new instance of Postgresql.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/active_harness/memory/adapter/postgresql.rb', line 194 def initialize(session_id:, namespace: nil, on_trim: nil, **opts) mem_keys = %i[depth enabled read_only async] mem_opts = opts.slice(*mem_keys) pg_opts = opts.reject { |k, _| mem_keys.include?(k) } pg_opts[:namespace] = namespace if namespace pg_opts[:on_trim] = on_trim if on_trim super( session_id: session_id, adapter: Adapter::Postgresql.new(pg_opts), namespace: namespace, on_trim: on_trim, **mem_opts ) end |