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/model_config.rb,
lib/paper_trail/record_trail.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/sinatra.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/version_association_concern.rb,
lib/generators/paper_trail/install_generator.rb,
lib/paper_trail/attribute_serializers/object_attribute.rb,
lib/paper_trail/attribute_serializers/object_changes_attribute.rb,
lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb,
lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb,
lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb,
lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb
Overview
An ActiveRecord extension that tracks changes to your models, for auditing or versioning.
Defined Under Namespace
Modules: AttributeSerializers, Cleaner, Cucumber, Model, RSpec, Rails, Reifier, Serializers, Sinatra, VERSION, VersionAssociationConcern, VersionConcern Classes: Config, InstallGenerator, ModelConfig, RecordHistory, RecordTrail, Version, VersionAssociation
Class Method Summary collapse
-
.active_record_protected_attributes? ⇒ Boolean
Returns a boolean indicating whether “protected attibutes” should be configured, e.g.
- .clear_transaction_id ⇒ Object private
-
.config {|@config| ... } ⇒ Object
(also: configure)
private
Returns PaperTrail’s configuration object.
-
.controller_info ⇒ Object
Returns any information from the controller that you want PaperTrail to store.
-
.controller_info=(value) ⇒ Object
Sets any information from the controller that you want PaperTrail to store.
-
.enabled=(value) ⇒ Object
Switches PaperTrail on or off.
-
.enabled? ⇒ Boolean
Returns ‘true` if PaperTrail is on, `false` otherwise.
-
.enabled_for_controller=(value) ⇒ Object
Sets whether PaperTrail is enabled or disabled for the current request.
-
.enabled_for_controller? ⇒ Boolean
Returns ‘true` if PaperTrail is enabled for the request, `false` otherwise.
-
.enabled_for_model(model, value) ⇒ Object
Sets whether PaperTrail is enabled or disabled for this model in the current request.
-
.enabled_for_model?(model) ⇒ Boolean
Returns ‘true` if PaperTrail is enabled for this model in the current request, `false` otherwise.
-
.paper_trail_store ⇒ Object
private
Thread-safe hash to hold PaperTrail’s data.
- .serialized_attributes? ⇒ Boolean
- .serializer ⇒ Object
-
.serializer=(value) ⇒ Object
Getter and Setter for PaperTrail Serializer.
-
.timestamp_field ⇒ Object
Returns the field which records when a version was created.
-
.timestamp_field=(field_name) ⇒ Object
Set the field which records when a version was created.
- .transaction? ⇒ Boolean
- .transaction_id ⇒ Object
- .transaction_id=(id) ⇒ Object
- .version ⇒ Object
-
.whodunnit ⇒ Object
Returns who is reponsible for any changes that occur.
-
.whodunnit=(value) ⇒ Object
Sets who is responsible for any changes that occur.
Methods included from Cleaner
Class Method Details
.active_record_protected_attributes? ⇒ Boolean
Returns a boolean indicating whether “protected attibutes” should be configured, e.g. attr_accessible, mass_assignment_sanitizer, whitelist_attributes, etc.
130 131 132 133 |
# File 'lib/paper_trail.rb', line 130 def active_record_protected_attributes? @active_record_protected_attributes ||= ::ActiveRecord::VERSION::MAJOR < 4 || !!defined?(ProtectedAttributes) end |
.clear_transaction_id ⇒ Object
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.
20 21 22 |
# File 'lib/paper_trail.rb', line 20 def clear_transaction_id self.transaction_id = nil end |
.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 configuration object.
159 160 161 162 163 |
# File 'lib/paper_trail.rb', line 159 def config @config ||= PaperTrail::Config.instance yield @config if block_given? @config end |
.controller_info ⇒ Object
Returns any information from the controller that you want PaperTrail to store.
See ‘PaperTrail::Rails::Controller#info_for_paper_trail`.
111 112 113 |
# File 'lib/paper_trail.rb', line 111 def controller_info paper_trail_store[:controller_info] end |
.controller_info=(value) ⇒ Object
Sets any information from the controller that you want PaperTrail to store. By default this is set automatically by a before filter.
102 103 104 |
# File 'lib/paper_trail.rb', line 102 def controller_info=(value) paper_trail_store[:controller_info] = value end |
.enabled=(value) ⇒ Object
Switches PaperTrail on or off.
26 27 28 |
# File 'lib/paper_trail.rb', line 26 def enabled=(value) PaperTrail.config.enabled = value end |
.enabled? ⇒ Boolean
Returns ‘true` if PaperTrail is on, `false` otherwise. PaperTrail is enabled by default.
33 34 35 |
# File 'lib/paper_trail.rb', line 33 def enabled? !!PaperTrail.config.enabled end |
.enabled_for_controller=(value) ⇒ Object
Sets whether PaperTrail is enabled or disabled for the current request.
47 48 49 |
# File 'lib/paper_trail.rb', line 47 def enabled_for_controller=(value) paper_trail_store[:request_enabled_for_controller] = value end |
.enabled_for_controller? ⇒ Boolean
Returns ‘true` if PaperTrail is enabled for the request, `false` otherwise.
See ‘PaperTrail::Rails::Controller#paper_trail_enabled_for_controller`.
55 56 57 |
# File 'lib/paper_trail.rb', line 55 def enabled_for_controller? !!paper_trail_store[:request_enabled_for_controller] end |
.enabled_for_model(model, value) ⇒ Object
Sets whether PaperTrail is enabled or disabled for this model in the current request.
62 63 64 |
# File 'lib/paper_trail.rb', line 62 def enabled_for_model(model, value) paper_trail_store[:"enabled_for_#{model}"] = value end |
.enabled_for_model?(model) ⇒ Boolean
Returns ‘true` if PaperTrail is enabled for this model in the current request, `false` otherwise.
69 70 71 |
# File 'lib/paper_trail.rb', line 69 def enabled_for_model?(model) !!paper_trail_store.fetch(:"enabled_for_#{model}", true) end |
.paper_trail_store ⇒ Object
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.
Thread-safe hash to hold PaperTrail’s data. Initializing with needed default values.
153 154 155 |
# File 'lib/paper_trail.rb', line 153 def paper_trail_store RequestStore.store[:paper_trail] ||= { request_enabled_for_controller: true } end |
.serialized_attributes? ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/paper_trail.rb', line 37 def serialized_attributes? ActiveSupport::Deprecation.warn( "PaperTrail.serialized_attributes? is deprecated without replacement " + "and always returns false." ) false end |
.serializer ⇒ Object
122 123 124 |
# File 'lib/paper_trail.rb', line 122 def serializer PaperTrail.config.serializer end |
.serializer=(value) ⇒ Object
Getter and Setter for PaperTrail Serializer
117 118 119 |
# File 'lib/paper_trail.rb', line 117 def serializer=(value) PaperTrail.config.serializer = value end |
.timestamp_field ⇒ Object
Returns the field which records when a version was created.
81 82 83 |
# File 'lib/paper_trail.rb', line 81 def PaperTrail.config. end |
.timestamp_field=(field_name) ⇒ Object
Set the field which records when a version was created.
75 76 77 |
# File 'lib/paper_trail.rb', line 75 def (field_name) PaperTrail.config. = field_name end |
.transaction? ⇒ Boolean
136 137 138 |
# File 'lib/paper_trail.rb', line 136 def transaction? ::ActiveRecord::Base.connection.open_transactions > 0 end |
.transaction_id ⇒ Object
141 142 143 |
# File 'lib/paper_trail.rb', line 141 def transaction_id paper_trail_store[:transaction_id] end |
.transaction_id=(id) ⇒ Object
146 147 148 |
# File 'lib/paper_trail.rb', line 146 def transaction_id=(id) paper_trail_store[:transaction_id] = id end |
.whodunnit ⇒ Object
Returns who is reponsible for any changes that occur.
95 96 97 |
# File 'lib/paper_trail.rb', line 95 def whodunnit paper_trail_store[:whodunnit] end |
.whodunnit=(value) ⇒ Object
Sets who is responsible for any changes that occur. You would normally use this in a migration or on the console, when working with models directly. In a controller it is set automatically to the ‘current_user`.
89 90 91 |
# File 'lib/paper_trail.rb', line 89 def whodunnit=(value) paper_trail_store[:whodunnit] = value end |