Class: BeanSprout::Transaction
- Inherits:
-
PackagePrivate::PublicInterfaceBase
- Object
- ForwardableDelegate
- PackagePrivate::PublicInterfaceBase
- BeanSprout::Transaction
- Defined in:
- lib/bean_sprout/transaction.rb
Instance Attribute Summary
Attributes inherited from PackagePrivate::PublicInterfaceBase
Instance Method Summary collapse
- #commit ⇒ Object
- #entries ⇒ Object
-
#local? ⇒ Boolean
If this transaction only involves one local currency.
- #revert ⇒ Object
Methods inherited from PackagePrivate::PublicInterfaceBase
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
#commit ⇒ Object
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 |
#entries ⇒ Object
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.
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 |
#revert ⇒ Object
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 |