Sha256: 0bba05b481dca155e7e4f1c893b44267761f6b84afdebe0e963974dbffee522e
Contents?: true
Size: 1.05 KB
Versions: 200
Compression:
Stored size: 1.05 KB
Contents
# EffectiveAfterCommit # # Execute code after the ActiveRecord transaction has committed # Inspired by https://github.com/Envek/after_commit_everywhere # # This is automatically included into ActiveRecord::Base # # after_commit { MyMailer.welcome.deliver_later } module EffectiveAfterCommit extend ActiveSupport::Concern module Base def after_commit(connection: self.class.connection, &callback) Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback) end def before_commit(connection: self.class.connection, &callback) raise(NotImplementedError, "#{__method__} works only with Rails 5.0+") if ActiveRecord::VERSION::MAJOR < 5 Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback) end def after_rollback(connection: self.class.connection, &callback) raise('expected a block') unless block_given? Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback) end end end
Version data entries
200 entries across 200 versions & 1 rubygems