Module: DoubleEntry
- Includes:
- Configurable
- Defined in:
- lib/double_entry.rb,
lib/double_entry/line.rb,
lib/double_entry/errors.rb,
lib/double_entry/account.rb,
lib/double_entry/locking.rb,
lib/double_entry/version.rb,
lib/double_entry/transfer.rb,
lib/double_entry/reporting.rb,
lib/double_entry/configurable.rb,
lib/double_entry/configuration.rb,
lib/double_entry/account_balance.rb,
lib/double_entry/balance_calculator.rb,
lib/double_entry/reporting/aggregate.rb,
lib/double_entry/reporting/day_range.rb,
lib/double_entry/reporting/hour_range.rb,
lib/double_entry/reporting/time_range.rb,
lib/double_entry/reporting/week_range.rb,
lib/double_entry/reporting/year_range.rb,
lib/double_entry/reporting/month_range.rb,
lib/double_entry/validation/line_check.rb,
lib/double_entry/reporting/line_aggregate.rb,
lib/double_entry/reporting/aggregate_array.rb,
lib/double_entry/reporting/time_range_array.rb,
lib/generators/double_entry/install/install_generator.rb
Overview
Keep track of all the monies!
This module provides the public interfaces for everything to do with transferring money around the system.
Defined Under Namespace
Modules: BalanceCalculator, Configurable, Generators, Locking, Reporting, Validation Classes: Account, AccountBalance, AccountIdentifierTooLongError, AccountScopeMismatchError, AccountWouldBeSentNegative, AccountWouldBeSentPositiveError, Configuration, DuplicateAccount, DuplicateTransfer, Line, MismatchedCurrencies, MissingAccountError, ScopeIdentifierTooLongError, Transfer, TransferCodeTooLongError, TransferIsNegative, TransferNotAllowed, UnknownAccount
Constant Summary collapse
- VERSION =
'0.10.1'
Class Method Summary collapse
-
.account(identifier, options = {}) ⇒ DoubleEntry::Account::Instance
Get the particular account instance with the provided identifier and scope.
-
.balance(account, options = {}) ⇒ Money
Get the current or historic balance of an account.
-
.lock_accounts(*accounts) { ... } ⇒ Object
Lock accounts in preparation for transfers.
- .table_name_prefix ⇒ Object private
-
.transfer(amount, options = {}) ⇒ Object
Transfer money from one account to another.
Methods included from Configurable
Class Method Details
.account(identifier, options = {}) ⇒ DoubleEntry::Account::Instance
Get the particular account instance with the provided identifier and scope.
42 43 44 |
# File 'lib/double_entry.rb', line 42 def account(identifier, = {}) Account.account(identifier, ) end |
.balance(account, options = {}) ⇒ Money
Get the current or historic balance of an account.
132 133 134 135 |
# File 'lib/double_entry.rb', line 132 def balance(account, = {}) account = account(account, ) if account.is_a? Symbol BalanceCalculator.calculate(account, ) end |
.lock_accounts(*accounts) { ... } ⇒ Object
Lock accounts in preparation for transfers.
This creates a transaction, and uses database-level locking to ensure that we're the only ones who can transfer to or from the given accounts for the duration of the transaction.
153 154 155 |
# File 'lib/double_entry.rb', line 153 def lock_accounts(*accounts, &block) Locking.lock_accounts(*accounts, &block) end |
.table_name_prefix ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
158 159 160 |
# File 'lib/double_entry.rb', line 158 def table_name_prefix 'double_entry_' end |
.transfer(amount, options = {}) ⇒ Object
Transfer money from one account to another.
Only certain transfers are allowed. Define legal transfers in your configuration file.
If you're doing more than one transfer in one hit, or you're doing other database operations along with your transfer, you'll need to use the lock_accounts method.
78 79 80 |
# File 'lib/double_entry.rb', line 78 def transfer(amount, = {}) Transfer.transfer(amount, ) end |