Class: DoubleEntry::AccountBalance
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DoubleEntry::AccountBalance
- Defined in:
- lib/double_entry/account_balance.rb
Overview
Account balance records cache the current balance for each account. They also provide a database representation of an account that we can use to do DB level locking.
See DoubleEntry::Locking for more info on locking.
Account balances are created on demand when transfers occur.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_account(account, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/double_entry/account_balance.rb', line 33 def self.find_by_account(account, = {}) scope = where(:scope => account.scope_identity, :account => account.identifier.to_s) scope = scope.lock(true) if [:lock] scope.first end |
Instance Method Details
#account ⇒ Object
29 30 31 |
# File 'lib/double_entry/account_balance.rb', line 29 def account DoubleEntry.account(self[:account].to_sym, :scope => self[:scope]) end |
#account=(account) ⇒ Object
23 24 25 26 27 |
# File 'lib/double_entry/account_balance.rb', line 23 def account=(account) self[:account] = account.identifier.to_s self[:scope] = account.scope_identity account end |
#balance ⇒ Object
15 16 17 |
# File 'lib/double_entry/account_balance.rb', line 15 def balance self[:balance] && Money.new(self[:balance], currency) end |
#balance=(money) ⇒ Object
19 20 21 |
# File 'lib/double_entry/account_balance.rb', line 19 def balance=(money) self[:balance] = (money && money.fractional) end |