Class: PaperTrail::Events::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail/events/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

We refer to times in the lifecycle of a record as “events”. There are three events:

  • create

    • ‘after_create` we call `RecordTrail#record_create`

  • update

    • ‘after_update` we call `RecordTrail#record_update`

    • ‘after_touch` we call `RecordTrail#record_update`

    • ‘RecordTrail#save_with_version` calls `RecordTrail#record_update`

    • ‘RecordTrail#update_columns` is also referred to as an update, though it uses `RecordTrail#record_update_columns` rather than `RecordTrail#record_update`

  • destroy

    • ‘before_destroy` or `after_destroy` we call `RecordTrail#record_destroy`

The value inserted into the ‘event` column of the versions table can also be overridden by the user, with `paper_trail_event`.

Direct Known Subclasses

Create, Destroy, Update

Constant Summary collapse

E_FORBIDDEN_METADATA_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<-EOS.squish
  Forbidden metadata key: %s. As of PT 14, the following metadata keys are
  forbidden: %s
EOS
FORBIDDEN_METADATA_KEYS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[
  created_at
  id
  item_id
  item_subtype
  item_type
  updated_at
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(record, in_after_callback) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



39
40
41
42
# File 'lib/paper_trail/events/base.rb', line 39

def initialize(record, in_after_callback)
  @record = record
  @in_after_callback = in_after_callback
end

Instance Method Details

#changed_notably?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines whether it is appropriate to generate a new version instance. A timestamp-only update (e.g. only ‘updated_at` changed) is considered notable unless an ignored attribute was also changed.

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/paper_trail/events/base.rb', line 49

def changed_notably?
  if ignored_attr_has_changed?
    timestamps = @record.send(:timestamp_attributes_for_update_in_model).map(&:to_s)
    (notably_changed - timestamps).any?
  else
    notably_changed.any?
  end
end