Sha256: de9c3778e1311d0af2c361649ff84adef8e29b2852c70c9c044de1834aa7f880
Contents?: true
Size: 722 Bytes
Versions: 2
Compression:
Stored size: 722 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_without_before_commit, :commit def commit call_before_commit_records if PubSubModelSync::Config.enable_rails4_before_commit commit_without_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.1 | lib/pub_sub_model_sync/initializers/before_commit.rb |
pub_sub_model_sync-1.0 | lib/pub_sub_model_sync/initializers/before_commit.rb |