Class: Ask::TokenUsage::Stores::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/token_usage/stores/store.rb

Overview

The persistence port the wallet engine talks to. The wallet never touches a database — it goes through this small interface, so the engine is testable with Stores::Memory and portable to any backend.

Implementations must be safe under concurrent access: two wallets mutating the same owner must never corrupt the balance.

Direct Known Subclasses

Memory

Instance Method Summary collapse

Instance Method Details

#append(owner, entry) ⇒ Object

Persist entry (an unpersisted LedgerEntry) for owner and return the persisted copy (with id/created_at). Must be called inside with_lock.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/ask/token_usage/stores/store.rb', line 33

def append(owner, entry)
  raise NotImplementedError
end

#balance(owner) ⇒ Object

Current balance (Integer) for owner, or 0.

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/ask/token_usage/stores/store.rb', line 15

def balance(owner)
  raise NotImplementedError
end

#entries(owner, kind: nil, since: nil) ⇒ Object

Ledger entries for owner, oldest first, filtered by kind and time.

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/ask/token_usage/stores/store.rb', line 20

def entries(owner, kind: nil, since: nil)
  raise NotImplementedError
end

#with_lock(owner) ⇒ Object

Yields once with exclusive access to +owner+'s balance. All read-check-write sequences must happen inside this block.

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/ask/token_usage/stores/store.rb', line 26

def with_lock(owner)
  raise NotImplementedError
end

#write_balance(owner, balance) ⇒ Object

Persist the owner's cached balance. Must be called inside with_lock.

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/ask/token_usage/stores/store.rb', line 38

def write_balance(owner, balance)
  raise NotImplementedError
end