module PaperTrail

An ActiveRecord extension that tracks changes to your models, for auditing or versioning.

Constants

E_TIMESTAMP_FIELD_CONFIG

Public Class Methods

active_record_gte_7_0?() click to toggle source
# File lib/paper_trail.rb, line 118
def active_record_gte_7_0?
  @active_record_gte_7_0 ||= ::ActiveRecord.gem_version >= ::Gem::Version.new("7.0.0")
end
config() { |config| ... } click to toggle source

Returns PaperTrail’s global configuration object, a singleton. These settings affect all threads. @api public

# File lib/paper_trail.rb, line 106
def config
  @config ||= PaperTrail::Config.instance
  yield @config if block_given?
  @config
end
Also aliased as: configure
configure()
Alias for: config
deprecator() click to toggle source
# File lib/paper_trail.rb, line 122
def deprecator
  @deprecator ||= ActiveSupport::Deprecation.new("16.0", "PaperTrail")
end
enabled=(value) click to toggle source

Switches PaperTrail on or off, for all threads. @api public

# File lib/paper_trail.rb, line 40
def enabled=(value)
  PaperTrail.config.enabled = value
end
enabled?() click to toggle source

Returns ‘true` if PaperTrail is on, `false` otherwise. This is the on/off switch that affects all threads. Enabled by default. @api public

# File lib/paper_trail.rb, line 47
def enabled?
  !!PaperTrail.config.enabled
end
gem_version() click to toggle source

Returns PaperTrail’s ‘::Gem::Version`, convenient for comparisons. This is recommended over `::PaperTrail::VERSION::STRING`.

Added in 7.0.0

@api public

# File lib/paper_trail.rb, line 57
def gem_version
  ::Gem::Version.new(VERSION::STRING)
end
request(options = nil, &block) click to toggle source

Set variables for the current request, eg. whodunnit.

All request-level variables are now managed here, as of PT 9. Having the word “request” right there in your application code will remind you that these variables only affect the current request, not all threads.

Given a block, temporarily sets the given ‘options`, executes the block, and returns the value of the block.

Without a block, this currently just returns ‘PaperTrail::Request`. However, please do not use `PaperTrail::Request` directly. Currently, `Request` is a `Module`, but in the future it is quite possible we may make it a `Class`. If we make such a choice, we will not provide any warning and will not treat it as a breaking change. You’ve been warned :)

@api public

# File lib/paper_trail.rb, line 77
def request(options = nil, &block)
  if options.nil? && !block
    Request
  else
    Request.with(options, &block)
  end
end
serializer() click to toggle source

Get the PaperTrail serializer used by all threads. @api public

# File lib/paper_trail.rb, line 99
def serializer
  PaperTrail.config.serializer
end
serializer=(value) click to toggle source

Set the PaperTrail serializer. This setting affects all threads. @api public

# File lib/paper_trail.rb, line 93
def serializer=(value)
  PaperTrail.config.serializer = value
end
timestamp_field=(_field_name) click to toggle source

Set the field which records when a version was created. @api public

# File lib/paper_trail.rb, line 87
def timestamp_field=(_field_name)
  raise Error, E_TIMESTAMP_FIELD_CONFIG
end
version() click to toggle source

@api public

# File lib/paper_trail.rb, line 114
def version
  VERSION::STRING
end