module ActiveRecord::Transactions::ClassMethods

def after_commit(*args, &block)


after_commit :do_bar_baz, on: [:update, :destroy]
after_commit :do_foo_bar, on: [:create, :update]

after_commit :do_baz, on: :destroy
after_commit :do_bar, on: :update
after_commit :do_foo, on: :create

the +:on+ option:
You can specify that the callback should only be fired by a certain action with

This callback is called after a record has been created, updated, or destroyed.
def after_commit(*args, &block)
  set_options_for_callbacks!(args)
  set_callback(:commit, :after, *args, &block)
end

def after_create_commit(*args, &block)

Shortcut for after_commit :hook, on: :create.
def after_create_commit(*args, &block)
  set_options_for_callbacks!(args, on: :create)
  set_callback(:commit, :after, *args, &block)
end

def after_destroy_commit(*args, &block)

Shortcut for after_commit :hook, on: :destroy.
def after_destroy_commit(*args, &block)
  set_options_for_callbacks!(args, on: :destroy)
  set_callback(:commit, :after, *args, &block)
end

def after_rollback(*args, &block)

Please check the documentation of #after_commit for options.

This callback is called after a create, update, or destroy are rolled back.
def after_rollback(*args, &block)
  set_options_for_callbacks!(args)
  set_callback(:rollback, :after, *args, &block)
end

def after_save_commit(*args, &block)

Shortcut for after_commit :hook, on: [ :create, :update ].
def after_save_commit(*args, &block)
  set_options_for_callbacks!(args, on: [ :create, :update ])
  set_callback(:commit, :after, *args, &block)
end

def after_update_commit(*args, &block)

Shortcut for after_commit :hook, on: :update.
def after_update_commit(*args, &block)
  set_options_for_callbacks!(args, on: :update)
  set_callback(:commit, :after, *args, &block)
end

def assert_valid_transaction_action(actions)

def assert_valid_transaction_action(actions)
  if (actions - ACTIONS).any?
    raise ArgumentError, ":on conditions for after_commit and after_rollback callbacks have to be one of #{ACTIONS}"
  end
end

def before_commit(*args, &block) # :nodoc:

:nodoc:
def before_commit(*args, &block) # :nodoc:
  set_options_for_callbacks!(args)
  set_callback(:before_commit, :before, *args, &block)
end

def set_options_for_callbacks!(args, enforced_options = {})

def set_options_for_callbacks!(args, enforced_options = {})
  options = args.extract_options!.merge!(enforced_options)
  args << options
  if options[:on]
    fire_on = Array(options[:on])
    assert_valid_transaction_action(fire_on)
    options[:if] = [
      -> { transaction_include_any_action?(fire_on) },
      *options[:if]
    ]
  end
end

def transaction(**options, &block)

See the ConnectionAdapters::DatabaseStatements#transaction API docs.
def transaction(**options, &block)
  connection.transaction(**options, &block)
end