Class: PaperTrail::Events::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_trails/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

RAILS_GTE_5_1 =

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.

::ActiveRecord.gem_version >= ::Gem::Version.new("5.1.0.beta1")

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.



28
29
30
31
# File 'lib/mongo_trails/events/base.rb', line 28

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)


38
39
40
41
42
43
44
45
# File 'lib/mongo_trails/events/base.rb', line 38

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