Module: Komando::Persistence::ActiveRecord
- Defined in:
- lib/komando/persistence/active_record.rb
Overview
Wraps command executions within a database transaction.
Class Method Summary collapse
-
.included(base) ⇒ Object
Insinuates this module within Command.
Instance Method Summary collapse
-
#logger ⇒ Object
Uses the same Logger instance as ActiveRecord.
-
#run_with_transaction! ⇒ Object
Wraps a command execution within a database transactions.
-
#wrap_transaction ⇒ Object
Does the actual work of wrapping in a transaction.
Class Method Details
.included(base) ⇒ Object
Insinuates this module within Command.
12 13 14 |
# File 'lib/komando/persistence/active_record.rb', line 12 def self.included(base) base.send :alias_method_chain, :run!, :transaction end |
Instance Method Details
#logger ⇒ Object
Uses the same Logger instance as ActiveRecord.
59 60 61 |
# File 'lib/komando/persistence/active_record.rb', line 59 def logger ::ActiveRecord::Base.logger end |
#run_with_transaction! ⇒ Object
Wraps a command execution within a database transactions. This method delegates actual transaction semantics to #wrap_transaction. This method is renamed as Command##run! during inclusion.
19 20 21 22 23 |
# File 'lib/komando/persistence/active_record.rb', line 19 def run_with_transaction! wrap_transaction do run_without_transaction! end end |
#wrap_transaction ⇒ Object
Does the actual work of wrapping in a transaction. The default is to wrap using ActiveRecord::Base#transaction.
52 53 54 55 56 |
# File 'lib/komando/persistence/active_record.rb', line 52 def wrap_transaction ::ActiveRecord::Base.transaction do yield end end |