Class: DoubleEntry::AccountBalance

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
EncapsulateAsMoney
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



22
23
24
25
26
# File 'lib/double_entry/account_balance.rb', line 22

def self.(, options = {})
  scope = where(:scope => .scope_identity, :account => .identifier.to_s)
  scope = scope.lock(true) if options[:lock]
  scope.first
end

Instance Method Details

#account=(account) ⇒ Object



16
17
18
19
20
# File 'lib/double_entry/account_balance.rb', line 16

def account=()
  self[:account] = .identifier.to_s
  self[:scope] = .scope_identity
  
end