Class: BeanSprout::Transaction

Inherits:
PackagePrivate::PublicInterfaceBase show all
Defined in:
lib/bean_sprout/transaction.rb

Instance Attribute Summary

Attributes inherited from PackagePrivate::PublicInterfaceBase

#other_data

Instance Method Summary collapse

Methods inherited from PackagePrivate::PublicInterfaceBase

#initialize

Methods inherited from ForwardableDelegate

def_default_delegators, def_private_default_delegators, #initialize

Constructor Details

This class inherits a constructor from BeanSprout::PackagePrivate::PublicInterfaceBase

Instance Method Details

#commitObject



60
61
62
63
64
65
66
67
68
# File 'lib/bean_sprout/transaction.rb', line 60

def commit
  begin
    plant
  rescue SproutBunch::NotBalancedError
    raise "Cannot commit an imbalance transaction."
  rescue SproutBunch::IllegalStateError
    raise "Cannot commit a transaction more than once."
  end
end

#entriesObject



80
81
82
83
84
85
86
87
88
# File 'lib/bean_sprout/transaction.rb', line 80

def entries
  sprouts.map do |sprout|
    if block_given?
      yield sprout.to_entry
    else
      sprout.to_entry
    end
  end
end

#local?Boolean

If this transaction only involves one local currency.

Returns:

  • (Boolean)


91
92
93
94
95
96
# File 'lib/bean_sprout/transaction.rb', line 91

def local?
  currency = sprouts[0].bean.currency
  sprouts.inject(true) do |acc, sprout|
    acc && sprout.bean.currency == currency
  end
end

#revertObject



70
71
72
73
74
75
76
77
78
# File 'lib/bean_sprout/transaction.rb', line 70

def revert
  begin
    remove
  rescue SproutBunch::NotBalancedError
    raise "Cannot revert an imbalance transaction."
  rescue SproutBunch::IllegalStateError
    raise "Cannot revert a transaction more than once."
  end
end