module PaperTrail
An ActiveRecord extension that tracks changes to your models, for auditing or versioning.
Constants
- E_TIMESTAMP_FIELD_CONFIG
Public Class Methods
# 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
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
# File lib/paper_trail.rb, line 122 def deprecator @deprecator ||= ActiveSupport::Deprecation.new("16.0", "PaperTrail") end
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
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
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
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
Get the PaperTrail
serializer used by all threads. @api public
# File lib/paper_trail.rb, line 99 def serializer PaperTrail.config.serializer end
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
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
@api public
# File lib/paper_trail.rb, line 114 def version VERSION::STRING end