Module: PaperTrail

Extended by:
Cleaner
Defined in:
lib/paper_trail.rb,
lib/paper_trail/config.rb,
lib/paper_trail/cleaner.rb,
lib/paper_trail/reifier.rb,
lib/paper_trail/request.rb,
lib/paper_trail/events/base.rb,
lib/paper_trail/model_config.rb,
lib/paper_trail/record_trail.rb,
lib/paper_trail/compatibility.rb,
lib/paper_trail/events/create.rb,
lib/paper_trail/events/update.rb,
lib/paper_trail/events/destroy.rb,
lib/paper_trail/record_history.rb,
lib/paper_trail/version_number.rb,
lib/paper_trail/has_paper_trail.rb,
lib/paper_trail/version_concern.rb,
lib/paper_trail/serializers/json.rb,
lib/paper_trail/serializers/yaml.rb,
lib/paper_trail/frameworks/cucumber.rb,
lib/paper_trail/frameworks/rails/engine.rb,
lib/paper_trail/frameworks/rspec/helpers.rb,
lib/paper_trail/frameworks/rails/controller.rb,
lib/paper_trail/queries/versions/where_object.rb,
lib/generators/paper_trail/migration_generator.rb,
lib/generators/paper_trail/install/install_generator.rb,
lib/paper_trail/queries/versions/where_object_changes.rb,
lib/paper_trail/attribute_serializers/object_attribute.rb,
lib/paper_trail/type_serializers/postgres_array_serializer.rb,
lib/paper_trail/attribute_serializers/object_changes_attribute.rb,
lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb,
lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb,
lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb,
lib/generators/paper_trail/update_item_subtype/update_item_subtype_generator.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, InstallGenerator, MigrationGenerator, ModelConfig, RecordHistory, RecordTrail, UpdateItemSubtypeGenerator, 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/paper_trail.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/paper_trail.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/paper_trail.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/paper_trail.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/paper_trail.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/paper_trail.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/paper_trail.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/paper_trail.rb', line 97

def timestamp_field=(_field_name)
  raise(E_TIMESTAMP_FIELD_CONFIG)
end

.versionObject



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

def version
  VERSION::STRING
end