class BeanSprout::Transaction

Public Instance Methods

commit() click to toggle source
# 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() { |to_entry| ... } click to toggle source
# 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?() click to toggle source

If this transaction only involves one local currency.

# 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() click to toggle source
# 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