Sha256: 370c9429dc3e009e82f89393bf021dfbf2242b3720b5a954ba8dc594a7032dab
Contents?: true
Size: 691 Bytes
Versions: 2
Compression:
Stored size: 691 Bytes
Contents
# frozen_string_literal: true # Rails 4 backward compatibility (Add "simple" ps_before_*_commit callbacks) ActiveRecord::ConnectionAdapters::RealTransaction.class_eval do alias_method :commit_with_before_commit, :commit def commit call_before_commit_records if Rails::VERSION::MAJOR == 4 commit_with_before_commit end private def call_before_commit_records ite = records.uniq ite.each do |record| action = record.previous_changes.include?(:id) ? :create : :update action = :destroy if record.destroyed? callback_name = "ps_before_#{action}_commit".to_sym record.send(callback_name) if record.respond_to?(callback_name) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pub_sub_model_sync-1.0.beta2 | lib/pub_sub_model_sync/initializers/before_commit.rb |
pub_sub_model_sync-1.0.beta1 | lib/pub_sub_model_sync/initializers/before_commit.rb |