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
62 63 64 65 66 67 68 69 70 |
# File 'lib/bean_sprout/transaction.rb', line 62 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/bean_sprout/transaction.rb', line 82 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.
93 94 95 96 97 98 |
# File 'lib/bean_sprout/transaction.rb', line 93 def local? currency = sprouts[0].bean.currency sprouts.inject(true) do |acc, sprout| acc && sprout.bean.currency == currency end end |
#revert ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/bean_sprout/transaction.rb', line 72 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 |