Module: Aloe::Ledger
Overview
Ledger is the façade interface to the account. When manipulating accounts (eg. creating transactions between accounts) you should use the Ledger and not the underlying models.
Instance Attribute Summary collapse
-
#account_scope ⇒ Object
writeonly
Sets the attribute account_scope.
Instance Method Summary collapse
-
#create_entry(amount, options) ⇒ Aloe::Transaction
Creates entry in the ledger.
-
#default_currency ⇒ String
Return the default currency that gets used when no currency is specified.
-
#find_account(owner, currency = default_currency) ⇒ Aloe::Account?
Returns an account for given owner.
-
#find_accounts(owner, currency = nil) ⇒ Aloe::Account?
Returns accounts for a given owner.
Instance Attribute Details
#account_scope=(value) ⇒ Object
Sets the attribute account_scope
14 15 16 |
# File 'lib/aloe/ledger.rb', line 14 def account_scope=(value) @account_scope = value end |
Instance Method Details
#create_entry(amount, options) ⇒ Aloe::Transaction
Creates entry in the ledger.
Creates entries in both credit and debit account and linking transaction between those two entries. Credit and debit accounts and given amount have to be in the same currency otherwise an exception is raised.
50 51 52 |
# File 'lib/aloe/ledger.rb', line 50 def create_entry(amount, ) Aloe::LedgerEntry.new(amount, ).create! end |
#default_currency ⇒ String
Return the default currency that gets used when no currency is specified.
57 58 59 |
# File 'lib/aloe/ledger.rb', line 57 def default_currency Money.default_currency.to_s end |
#find_account(owner, currency = default_currency) ⇒ Aloe::Account?
Returns an account for given owner.
22 23 24 |
# File 'lib/aloe/ledger.rb', line 22 def find_account(owner, currency = default_currency) scope_for_owner(owner).currency(currency.to_s).first end |
#find_accounts(owner, currency = nil) ⇒ Aloe::Account?
Returns accounts for a given owner.
32 33 34 35 |
# File 'lib/aloe/ledger.rb', line 32 def find_accounts(owner, currency = nil) scope = scope_for_owner(owner) currency ? scope.currency(currency) : scope end |