Module: PaperTrail

Extended by:
Cleaner
Defined in:
lib/mongo_trails.rb,
lib/mongo_trails/config.rb,
lib/mongo_trails/cleaner.rb,
lib/mongo_trails/reifier.rb,
lib/mongo_trails/request.rb,
lib/mongo_trails/events/base.rb,
lib/mongo_trails/model_config.rb,
lib/mongo_trails/record_trail.rb,
lib/mongo_trails/compatibility.rb,
lib/mongo_trails/events/create.rb,
lib/mongo_trails/events/update.rb,
lib/mongo_trails/events/destroy.rb,
lib/mongo_trails/record_history.rb,
lib/mongo_trails/version_number.rb,
lib/mongo_trails/has_paper_trail.rb,
lib/mongo_trails/version_concern.rb,
lib/mongo_trails/serializers/json.rb,
lib/mongo_trails/serializers/yaml.rb,
lib/mongo_trails/frameworks/cucumber.rb,
lib/mongo_trails/mongo_support/version.rb,
lib/mongo_trails/frameworks/rails/engine.rb,
lib/mongo_trails/frameworks/rspec/helpers.rb,
lib/mongo_trails/frameworks/rails/controller.rb,
lib/mongo_trails/queries/versions/where_object.rb,
lib/mongo_trails/queries/versions/where_object_changes.rb,
lib/mongo_trails/attribute_serializers/object_attribute.rb,
lib/mongo_trails/type_serializers/postgres_array_serializer.rb,
lib/mongo_trails/attribute_serializers/object_changes_attribute.rb,
lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb,
lib/mongo_trails/attribute_serializers/attribute_serializer_factory.rb

Overview

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

Defined Under Namespace

Modules: AttributeSerializers, Cleaner, Compatibility, Cucumber, Events, Model, Queries, RSpec, Rails, Reifier, Request, Serializers, TypeSerializers, VERSION, VersionConcern Classes: Config, ModelConfig, RecordHistory, RecordTrail, Version

Constant Summary collapse

E_RAILS_NOT_LOADED =
<<-EOS.squish.freeze
  PaperTrail has been loaded too early, before rails is loaded. This can
  happen when another gem defines the ::Rails namespace, then PT is loaded,
  all before rails is loaded. You may want to reorder your Gemfile, or defer
  the loading of PT by using `require: false` and a manual require elsewhere.
EOS
E_TIMESTAMP_FIELD_CONFIG =
<<-EOS.squish.freeze
  PaperTrail.timestamp_field= has been removed, without replacement. It is no
  longer configurable. The timestamp column in the versions table must now be
  named created_at.
EOS

Class Method Summary collapse

Methods included from Cleaner

clean_versions!

Class Method Details

.config {|@config| ... } ⇒ Object Also known as: configure

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 PaperTrail’s global configuration object, a singleton. These settings affect all threads.

Yields:



116
117
118
119
120
# File 'lib/mongo_trails.rb', line 116

def config
  @config ||= PaperTrail::Config.instance
  yield @config if block_given?
  @config
end

.enabled=(value) ⇒ Object

Switches PaperTrail on or off, for all threads.



50
51
52
# File 'lib/mongo_trails.rb', line 50

def enabled=(value)
  PaperTrail.config.enabled = value
end

.enabled?Boolean

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

Returns:

  • (Boolean)


57
58
59
# File 'lib/mongo_trails.rb', line 57

def enabled?
  !!PaperTrail.config.enabled
end

.gem_versionObject

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

Added in 7.0.0



67
68
69
# File 'lib/mongo_trails.rb', line 67

def gem_version
  ::Gem::Version.new(VERSION::STRING)
end

.request(options = nil, &block) ⇒ Object

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 :)



87
88
89
90
91
92
93
# 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

.serializerObject

Get the PaperTrail serializer used by all threads.



109
110
111
# File 'lib/mongo_trails.rb', line 109

def serializer
  PaperTrail.config.serializer
end

.serializer=(value) ⇒ Object

Set the PaperTrail serializer. This setting affects all threads.



103
104
105
# File 'lib/mongo_trails.rb', line 103

def serializer=(value)
  PaperTrail.config.serializer = value
end

.timestamp_field=(_field_name) ⇒ Object

Set the field which records when a version was created.



97
98
99
# File 'lib/mongo_trails.rb', line 97

def timestamp_field=(_field_name)
  raise(E_TIMESTAMP_FIELD_CONFIG)
end

.versionObject



123
124
125
# File 'lib/mongo_trails.rb', line 123

def version
  VERSION::STRING
end