class PaperTrail::Events::Update

See docs in ‘Base`.

@api private

Public Class Methods

new(record, in_after_callback, is_touch, force_changes) click to toggle source
  • is_touch - [boolean] - Used in the two situations that are touch-like:

    • ‘after_touch` we call `RecordTrail#record_update`

  • force_changes - [Hash] - Only used by ‘RecordTrail#update_columns`, because there dirty-tracking is off, so it has to track its own changes.

@api private

Calls superclass method PaperTrail::Events::Base::new
# File lib/paper_trail/events/update.rb, line 17
def initialize(record, in_after_callback, is_touch, force_changes)
  super(record, in_after_callback)
  @is_touch = is_touch
  @force_changes = force_changes
end

Public Instance Methods

changed_notably?() click to toggle source

If it is a touch event, and changed are empty, it is assumed to be implicit ‘touch` mutation, and will a version is created.

See github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e

@api private

# File lib/paper_trail/events/update.rb, line 46
def changed_notably?
  if @is_touch && changes_in_latest_version.empty?
    true
  else
    super
  end
end
data() click to toggle source

Return attributes of nascent ‘Version` record.

@api private

# File lib/paper_trail/events/update.rb, line 26
def data
  data = {
    item: @record,
    event: @record.paper_trail_event || "update",
    whodunnit: PaperTrail.request.whodunnit
  }
  if record_object?
    data[:object] = recordable_object(@is_touch)
  end
  merge_object_changes_into(data)
  merge_item_subtype_into(data)
  merge_metadata_into(data)
end

Private Instance Methods

merge_object_changes_into(data) click to toggle source

@api private

# File lib/paper_trail/events/update.rb, line 57
def merge_object_changes_into(data)
  if record_object_changes?
    changes = @force_changes.nil? ? notable_changes : @force_changes
    data[:object_changes] = prepare_object_changes(changes)
  end
end
record_object_changes?() click to toggle source

‘touch` cannot record `object_changes` because rails’ ‘touch` does not perform dirty-tracking. Specifically, methods from `Dirty`, like `saved_changes`, return the same values before and after `touch`.

See github.com/rails/rails/issues/33429

@api private

# File lib/paper_trail/events/update.rb, line 71
def record_object_changes?
  !@is_touch && super
end