Class: RailsAuditLog::PaperTrailCompat::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_audit_log/paper_trail_compat.rb

Overview

Proxy providing the PaperTrail instance API surface backed by AuditLogEntry records.

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:

  • record (ActiveRecord::Base)

    the record this proxy wraps



39
40
41
# File 'lib/rails_audit_log/paper_trail_compat.rb', line 39

def initialize(record)
  @record = record
end

Instance Method Details

#originatorString?

Display name of the actor who made the most recent change, as stored in whodunnit_snapshot.

Returns:

  • (String, nil)


62
63
64
# File 'lib/rails_audit_log/paper_trail_compat.rb', line 62

def originator
  version&.whodunnit_snapshot
end

#previous_versionActiveRecord::Base?

Reconstructs the record’s state before the most recent change. Returns nil for newly created records (no prior state exists).

Returns:

  • (ActiveRecord::Base, nil)

    an unpersisted instance; or nil



54
55
56
# File 'lib/rails_audit_log/paper_trail_compat.rb', line 54

def previous_version
  version&.reify
end

#versionAuditLogEntry?

The most recent AuditLogEntry for the record.

Returns:



46
47
48
# File 'lib/rails_audit_log/paper_trail_compat.rb', line 46

def version
  @record.audit_log_entries.order(id: :desc).first
end

#version_at(timestamp) ⇒ ActiveRecord::Base?

Reconstructs the record’s state as it was at timestamp. Delegates to RailsAuditLog.version_at.

Parameters:

  • timestamp (Time)

Returns:

  • (ActiveRecord::Base, nil)

    an unpersisted instance; or nil



71
72
73
# File 'lib/rails_audit_log/paper_trail_compat.rb', line 71

def version_at(timestamp)
  RailsAuditLog.version_at(@record, timestamp)
end