Class: Aloe::LedgerEntry

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

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(, ,
      amount.currency)
  end
  unless .open?
    raise Aloe::InoperableAccountError.new()
  end
  unless .open?
    raise Aloe::InoperableAccountError.new()
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount

Returns:

  • (Object)

    the current value of amount



9
10
11
# File 'lib/aloe/ledger_entry.rb', line 9

def amount
  @amount
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



9
10
11
# File 'lib/aloe/ledger_entry.rb', line 9

def options
  @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 = .create_entry(-amount.cents)
    credit_entry = .create_entry(amount.cents)
    attributes = { credit_entry: credit_entry,
                   debit_entry: debit_entry,
                   category: category }.merge options
    Aloe::Transaction::create! attributes
  end
end