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

Version Path
effective_resources-2.27.2 app/models/concerns/effective_after_commit.rb
effective_resources-2.27.1 app/models/concerns/effective_after_commit.rb
effective_resources-2.27.0 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.5 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.4 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.3 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.2 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.1 app/models/concerns/effective_after_commit.rb
effective_resources-2.26.0 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.16 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.15 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.14 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.13 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.12 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.11 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.10 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.9 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.8 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.7 app/models/concerns/effective_after_commit.rb
effective_resources-2.25.6 app/models/concerns/effective_after_commit.rb