Module: Toolx::Core::Operation::TransactionWrapper
- Defined in:
- lib/toolx/core/operation/transaction_wrapper.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepended(base) ⇒ Object
19 20 21 22 23 |
# File 'lib/toolx/core/operation/transaction_wrapper.rb', line 19 def self.prepended(base) class << base prepend ClassMethods end end |
Instance Method Details
#perform(*args, **params) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/toolx/core/operation/transaction_wrapper.rb', line 2 def perform(*args, **params) wrapper = proc do if args.present? || params.present? super else super() end end connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false # rubocop:disable Style/RescueModifier if connected && self.class.transactional? ActiveRecord::Base.transaction(&wrapper) else wrapper.call end end |