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, AccountWouldBeSentNegative, Configuration, DuplicateAccount, DuplicateTransfer, Line, RequiredMetaMissing, Transfer, TransferIsNegative, TransferNotAllowed, UnknownAccount, UserAccountNotLocked
Constant Summary collapse
- VERSION =
"0.3.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(configuration.accounts, identifier, ) end |
.balance(account, options = {}) ⇒ Money
Get the current or historic balance of an account.
93 94 95 |
# File 'lib/double_entry.rb', line 93 def balance(account, = {}) 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.
113 114 115 |
# File 'lib/double_entry.rb', line 113 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.
118 119 120 |
# File 'lib/double_entry.rb', line 118 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.
79 80 81 |
# File 'lib/double_entry.rb', line 79 def transfer(amount, = {}) Transfer.transfer(configuration.transfers, amount, ) end |