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/configurable.rb,
lib/double_entry/configuration.rb,
lib/double_entry/line_metadata.rb,
lib/double_entry/account_balance.rb,
lib/double_entry/balance_calculator.rb,
lib/double_entry/validation/line_check.rb,
lib/double_entry/validation/account_fixer.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, Validation Classes: Account, AccountBalance, AccountIdentifierTooLongError, AccountWouldBeSentNegative, AccountWouldBeSentPositiveError, Configuration, DoubleEntryError, DuplicateAccount, DuplicateTransfer, Line, LineMetadata, MismatchedCurrencies, MissingAccountError, Railtie, ScopeIdentifierTooLongError, Transfer, TransferCodeTooLongError, TransferIsNegative, TransferNotAllowed, UnknownAccount
Constant Summary collapse
- VERSION =
'2.0.0'
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 = {}) ⇒ [Line, Line]
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.
51 52 53 |
# File 'lib/double_entry.rb', line 51 def account(identifier, = {}) Account.account(identifier, ) end |
.balance(account, options = {}) ⇒ Money
Get the current or historic balance of an account.
142 143 144 145 |
# File 'lib/double_entry.rb', line 142 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.
163 164 165 |
# File 'lib/double_entry.rb', line 163 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.
168 169 170 |
# File 'lib/double_entry.rb', line 168 def table_name_prefix 'double_entry_' end |
.transfer(amount, options = {}) ⇒ [Line, Line]
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.
88 89 90 |
# File 'lib/double_entry.rb', line 88 def transfer(amount, = {}) Transfer.transfer(amount, ) end |