Class: WhittakerTech::Midas::Ledger::Posting
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- WhittakerTech::Midas::Ledger::Posting
- Includes:
- Bankable
- Defined in:
- app/models/whittaker_tech/midas/ledger/posting.rb
Overview
Ledger::Posting is a single debit or credit line within a balanced
Ledger::Entry. Its amount is stored twice, deliberately: via the standard
Bankable/Coin mechanism (amount, amount_format, amount_in, etc. —
for presentation/conversion parity with the rest of the engine) and
denormalized onto currency_minor directly on this table, which is what
every balance/aggregation query actually reads. This exists so Phase 2
partitioning of this table (by occurred_at) pays off — if the amount
only lived on the joined Coin row, partitioning postings wouldn't help
any query that also needs the amount.
Postings are immutable once created, and may only be added to or removed
from an Entry before that Entry is finalized — see Ledger::Entry.record!
and Ledger::Entry#finalized?.
Instance Method Summary collapse
-
#attach_amount_coin ⇒ Object
Bankable's
has_coindefinesset_amountdirectly on this class (viadefine_methodcalled withselfas the includer), not through a separate module in the ancestor chain — so adef set_amount; super; endbelow would have no ancestor to reach. -
#set_amount(amount:, currency_code:) ⇒ WhittakerTech::Midas::Coin
Overrides Bankable's generated
set_amountto keep the denormalizedcurrency_minorcolumn in sync with the Coin it just attached.
Instance Method Details
#attach_amount_coin ⇒ Object
Bankable's has_coin defines set_amount directly on this class (via
define_method called with self as the includer), not through a
separate module in the ancestor chain — so a def set_amount; super; end below would have no ancestor to reach. Alias the original before
overriding so it can still be called.
32 |
# File 'app/models/whittaker_tech/midas/ledger/posting.rb', line 32 alias attach_amount_coin set_amount |
#set_amount(amount:, currency_code:) ⇒ WhittakerTech::Midas::Coin
Overrides Bankable's generated set_amount to keep the denormalized
currency_minor column in sync with the Coin it just attached. Business
validation of the resulting amount (positive, currency matches entry)
happens in Entry#finalize!, not here — see class comment.
58 59 60 61 62 63 64 |
# File 'app/models/whittaker_tech/midas/ledger/posting.rb', line 58 def set_amount(amount:, currency_code:) ensure_entry_not_finalized! coin = attach_amount_coin(amount:, currency_code:) update_column(:currency_minor, coin.currency_minor) # rubocop:disable Rails/SkipsModelValidations coin end |