Module: Gexp::Mongoid::Transaction

Defined in:
lib/gexp/mongoid/transaction.rb

Defined Under Namespace

Classes: Base, Instance, Observer

Constant Summary collapse

SYSTEM_FIELDS =
[
  :_updated,
  :_version,
  :_transaction_id,
]

Class Method Summary collapse

Class Method Details

.transactionObject



80
81
82
# File 'lib/gexp/mongoid/transaction.rb', line 80

def transaction
  @transaction
end

.with(*objects, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gexp/mongoid/transaction.rb', line 62

def with(*objects, &block)

  begin
    self.start_transaction(objects)
    block.call self
    Observer.finish_transaction!
    self.transaction.objects.map(&:save)
    self.end_transaction
  rescue => e
    raise
  ensure
    if @transaction
      @transaction.delete unless @transaction.deleted?
    end
  end

end