Module: Journaled::Changes

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/journaled/changes.rb

Instance Method Summary collapse

Instance Method Details

#delete(force: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/journaled/changes.rb', line 30

def delete(force: false)
  if force || self.class.journaled_attribute_names.empty?
    super()
  else
    raise(<<~ERROR)
      #delete aborted by Journaled::Changes.

      Call #destroy instead to ensure journaling or invoke #delete(force: true)
      to override and skip journaling.
    ERROR
  end
end

#update_columns(attributes, force: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/concerns/journaled/changes.rb', line 43

def update_columns(attributes, force: false)
  unless force || self.class.journaled_attribute_names.empty?
    conflicting_journaled_attribute_names = self.class.journaled_attribute_names & attributes.keys.map(&:to_sym)
    raise(<<~ERROR) if conflicting_journaled_attribute_names.present?
      #update_columns aborted by Journaled::Changes due to journaled attributes:

        #{conflicting_journaled_attribute_names.join(', ')}

      Call #update instead to ensure journaling or invoke #update_columns
      with additional arg `{ force: true }` to override and skip journaling.
    ERROR
  end
  super(attributes)
end