Class: Aloe::LedgerEntry
- Inherits:
-
Struct
- Object
- Struct
- Aloe::LedgerEntry
- Defined in:
- lib/aloe/ledger_entry.rb
Overview
LedgerEntry is use-case class that encompasses the process of moving funds between accounts.
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #create! ⇒ Object
-
#initialize(*args) ⇒ LedgerEntry
constructor
A new instance of LedgerEntry.
Constructor Details
#initialize(*args) ⇒ LedgerEntry
Returns a new instance of LedgerEntry.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/aloe/ledger_entry.rb', line 11 def initialize(*args) super raise Aloe::InvalidAmountError if amount.zero? unless same_currencies? raise Aloe::InvalidCurrencyError.new(debit_account, credit_account, amount.currency) end unless debit_account.open? raise Aloe::InoperableAccountError.new(debit_account) end unless credit_account.open? raise Aloe::InoperableAccountError.new(credit_account) end end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount
9 10 11 |
# File 'lib/aloe/ledger_entry.rb', line 9 def amount @amount end |
#options ⇒ Object
Returns the value of attribute options
9 10 11 |
# File 'lib/aloe/ledger_entry.rb', line 9 def @options end |
Instance Method Details
#create! ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aloe/ledger_entry.rb', line 26 def create! ActiveRecord::Base.transaction do debit_entry = debit_account.create_entry(-amount.cents) credit_entry = credit_account.create_entry(amount.cents) attributes = { credit_entry: credit_entry, debit_entry: debit_entry, category: category }.merge Aloe::Transaction::create! attributes end end |