Module: Neo4j::Core::TxMethods

Instance Method Summary collapse

Instance Method Details

#tx_methods(*methods) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/neo4j-core/helpers.rb', line 4

def tx_methods(*methods)
  methods.each do |method|
    tx_method = "#{method}_in_tx"
    send(:alias_method, tx_method, method)
    send(:define_method, method) do |*args, &block|
      session = args.last.is_a?(Neo4j::Session) ? args.pop : Neo4j::Session.current!

      Neo4j::Transaction.run(session.auto_commit?) { send(tx_method, *args, &block) }
    end
  end
end