Sha256: 08d588919319f6408bd99da5c16b20a240ad4d3e6b845658055fef07caafe9b0

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 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, no_tx_action: :execute)
    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, no_tx_action: :warn_and_execute)
    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, no_tx_action: :exception)
    end
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
effective_resources-1.9.5 app/models/concerns/effective_after_commit.rb
effective_resources-1.9.4 app/models/concerns/effective_after_commit.rb
effective_resources-1.9.3 app/models/concerns/effective_after_commit.rb
effective_resources-1.9.2 app/models/concerns/effective_after_commit.rb
effective_resources-1.9.1 app/models/concerns/effective_after_commit.rb
effective_resources-1.9.0 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.38 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.37 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.36 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.35 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.34 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.33 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.32 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.31 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.30 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.29 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.28 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.27 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.26 app/models/concerns/effective_after_commit.rb
effective_resources-1.8.25 app/models/concerns/effective_after_commit.rb