Class: Ask::Tokens::Stores::Store
- Inherits:
-
Object
- Object
- Ask::Tokens::Stores::Store
- Defined in:
- lib/ask/tokens/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
Instance Method Summary collapse
-
#append(owner, entry) ⇒ Object
Persist
entry(an unpersisted LedgerEntry) forownerand return the persisted copy (with id/created_at). -
#balance(owner) ⇒ Object
Current balance (Integer) for
owner, or 0. -
#entries(owner, kind: nil, since: nil) ⇒ Object
Ledger entries for
owner, oldest first, filtered by kind and time. -
#with_lock(owner) ⇒ Object
Yields once with exclusive access to +owner+'s balance.
-
#write_balance(owner, balance) ⇒ Object
Persist the owner's cached balance.
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.
33 34 35 |
# File 'lib/ask/tokens/stores/store.rb', line 33 def append(owner, entry) raise NotImplementedError end |
#balance(owner) ⇒ Object
Current balance (Integer) for owner, or 0.
15 16 17 |
# File 'lib/ask/tokens/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.
20 21 22 |
# File 'lib/ask/tokens/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.
26 27 28 |
# File 'lib/ask/tokens/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.
38 39 40 |
# File 'lib/ask/tokens/stores/store.rb', line 38 def write_balance(owner, balance) raise NotImplementedError end |