Sha256: 502257a6133c704ef9257945e1779752a0900b5a42aba695fc227422277d1403

Contents?: true

Size: 999 Bytes

Versions: 1

Compression:

Stored size: 999 Bytes

Contents

module Journaled::RelationChangeProtection
  def update_all(updates, force: false)
    unless force || !@klass.respond_to?(:journaled_attribute_names) || @klass.journaled_attribute_names.empty?
      conflicting_journaled_attribute_names = @klass.journaled_attribute_names & updates.keys.map(&:to_sym)
      raise(<<~ERROR) if conflicting_journaled_attribute_names.present?
        #update_all aborted by Journaled::Changes due to journaled attributes:

          #{conflicting_journaled_attribute_names.join(', ')}

        Invoke #update_all with additional arg `{ force: true }` to override and skip journaling.
      ERROR
    end
    super(updates)
  end

  def delete_all(force: false)
    if force || !@klass.respond_to?(:journaled_attribute_names) || @klass.journaled_attribute_names.empty?
      super()
    else
      raise(<<~ERROR)
        #delete_all aborted by Journaled::Changes.

        Invoke #delete_all(force: true) to override and skip journaling.
      ERROR
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
journaled-2.0.0.rc1 lib/journaled/relation_change_protection.rb