Module: PaperTrail

Extended by:
Cleaner
Defined in:
lib/paper_trail.rb,
lib/paper_trail/config.rb,
lib/paper_trail/errors.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/railtie.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/queries/versions/where_attribute_changes.rb,
lib/paper_trail/queries/versions/where_object_changes_to.rb,
lib/paper_trail/queries/versions/where_object_changes_from.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, Error, InstallGenerator, InvalidOption, MigrationGenerator, ModelConfig, Railtie, RecordHistory, RecordTrail, UnsupportedColumnType, UnsupportedSchema, UpdateItemSubtypeGenerator, Version

Constant Summary collapse

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

.active_record_gte_7_0?Boolean

Returns:

  • (Boolean)


118
119
120
# 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| ... } ⇒ Object Also known as: configure

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

Yields:



106
107
108
109
110
# File 'lib/paper_trail.rb', line 106

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

.enabled=(value) ⇒ Object

Switches PaperTrail on or off, for all threads.



40
41
42
# File 'lib/paper_trail.rb', line 40

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)


47
48
49
# File 'lib/paper_trail.rb', line 47

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



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

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



77
78
79
80
81
82
83
# File 'lib/paper_trail.rb', line 77

def request(options = nil, &block)
  if options.nil? && !block
    Request
  else
    Request.with(options, &block)
  end
end

.serializerObject

Get the PaperTrail serializer used by all threads.



99
100
101
# File 'lib/paper_trail.rb', line 99

def serializer
  PaperTrail.config.serializer
end

.serializer=(value) ⇒ Object

Set the PaperTrail serializer. This setting affects all threads.



93
94
95
# File 'lib/paper_trail.rb', line 93

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

.timestamp_field=(_field_name) ⇒ Object

Set the field which records when a version was created.

Raises:



87
88
89
# File 'lib/paper_trail.rb', line 87

def timestamp_field=(_field_name)
  raise Error, E_TIMESTAMP_FIELD_CONFIG
end

.versionObject



114
115
116
# File 'lib/paper_trail.rb', line 114

def version
  VERSION::STRING
end