module PaperTrail

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

Constants

E_RAILS_NOT_LOADED
E_TIMESTAMP_FIELD_CONFIG

Public Class Methods

config() { |config| ... } click to toggle source

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

# File lib/mongo_trails.rb, line 116
def config
  @config ||= PaperTrail::Config.instance
  yield @config if block_given?
  @config
end
Also aliased as: configure
configure()
Alias for: config
enabled=(value) click to toggle source

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

# File lib/mongo_trails.rb, line 50
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/mongo_trails.rb, line 57
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/mongo_trails.rb, line 67
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/mongo_trails.rb, line 87
def request(options = nil, &block)
  if options.nil? && !block_given?
    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/mongo_trails.rb, line 109
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/mongo_trails.rb, line 103
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/mongo_trails.rb, line 97
def timestamp_field=(_field_name)
  raise(E_TIMESTAMP_FIELD_CONFIG)
end
version() click to toggle source
# File lib/mongo_trails.rb, line 123
def version
  VERSION::STRING
end