Class: DoubleEntry::Transfer
- Inherits:
-
Object
- Object
- DoubleEntry::Transfer
- Defined in:
- lib/double_entry/transfer.rb
Defined Under Namespace
Classes: Set
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#from ⇒ Object
Returns the value of attribute from.
-
#meta_requirement ⇒ Object
Returns the value of attribute meta_requirement.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Transfer
constructor
A new instance of Transfer.
- #process!(amount, from, to, code, meta, detail) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Transfer
Returns a new instance of Transfer.
28 29 30 31 |
# File 'lib/double_entry/transfer.rb', line 28 def initialize(attributes) = [] attributes.each { |name, value| send("#{name}=", value) } end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
26 27 28 |
# File 'lib/double_entry/transfer.rb', line 26 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
26 27 28 |
# File 'lib/double_entry/transfer.rb', line 26 def description @description end |
#from ⇒ Object
Returns the value of attribute from.
26 27 28 |
# File 'lib/double_entry/transfer.rb', line 26 def from @from end |
#meta_requirement ⇒ Object
Returns the value of attribute meta_requirement.
26 27 28 |
# File 'lib/double_entry/transfer.rb', line 26 def end |
#to ⇒ Object
Returns the value of attribute to.
26 27 28 |
# File 'lib/double_entry/transfer.rb', line 26 def to @to end |
Instance Method Details
#process!(amount, from, to, code, meta, detail) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/double_entry/transfer.rb', line 33 def process!(amount, from, to, code, , detail) if from.scope_identity == to.scope_identity and from.identifier == to.identifier raise TransferNotAllowed.new end .each do |key| if [key].nil? raise RequiredMetaMissing.new end end Locking.lock_accounts(from, to) do credit, debit = Line.new, Line.new credit_balance = Locking.balance_for_locked_account(from) debit_balance = Locking.balance_for_locked_account(to) credit_balance.update_attribute :balance, credit_balance.balance - amount debit_balance.update_attribute :balance, debit_balance.balance + amount credit.amount, debit.amount = -amount, amount credit.account, debit.account = from, to credit.code, debit.code = code, code credit., debit. = , credit.detail, debit.detail = detail, detail credit.balance, debit.balance = credit_balance.balance, debit_balance.balance credit.partner_account, debit.partner_account = to, from credit.save! debit.partner_id = credit.id debit.save! credit.update_attribute :partner_id, debit.id end end |