Module: PaperTrail::Model::ClassMethods
- Defined in:
- lib/paper_trail/has_paper_trail.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#has_paper_trail(options = {}) ⇒ Object
Declare this in your model to track every create, update, and destroy.
- #paper_trail ⇒ Object
- #paper_trail_deprecate(new_method, old_method = nil) ⇒ Object private
- #paper_trail_enabled_for_model? ⇒ Boolean deprecated Deprecated.
- #paper_trail_off! ⇒ Object deprecated Deprecated.
- #paper_trail_on! ⇒ Object deprecated Deprecated.
- #paper_trail_on_create ⇒ Object deprecated Deprecated.
- #paper_trail_on_destroy(*args) ⇒ Object deprecated Deprecated.
- #paper_trail_on_update ⇒ Object deprecated Deprecated.
- #paper_trail_version_class ⇒ Object deprecated Deprecated.
Instance Method Details
#has_paper_trail(options = {}) ⇒ Object
Declare this in your model to track every create, update, and destroy. Each version of the model is available in the versions association.
Options:
-
:on - The events to track (optional; defaults to all of them). Set to an array of
:create,:update,:destroyas desired. -
:class_name - The name of a custom Version class. This class should inherit from
PaperTrail::Version. -
:ignore - An array of attributes for which a new
Versionwill not be created if only they change. It can also aceept a Hash as an argument where the key is the attribute to ignore (aStringorSymbol), which will only be ignored if the value is aProcwhich returns truthily. -
:if, :unless - Procs that allow to specify conditions when to save versions for an object.
-
:only - Inverse of
ignore. A newVersionwill be created only for these attributes if supplied it can also aceept a Hash as an argument where the key is the attribute to track (aStringorSymbol), which will only be counted if the value is aProcwhich returns truthily. -
:skip - Fields to ignore completely. As with
ignore, updates to these fields will not create a newVersion. In addition, these fields will not be included in the serialized versions of the object whenever a newVersionis created. -
:meta - A hash of extra data to store. You must add a column to the
versionstable for each key. Values are objects or procs (which are called withself, i.e. the model with the paper trail). SeePaperTrail::Controller.info_for_paper_trailfor how to store data from the controller. -
:versions - The name to use for the versions association. Default is
:versions. -
:version - The name to use for the method which returns the version the instance was reified from. Default is
:version. -
:save_changes - Whether or not to save changes to the object_changes column if it exists. Default is true
-
:join_tables - If the model has a has_and_belongs_to_many relation with an unpapertrailed model, passing the name of the association to the join_tables option will paper trail the join table but not save the other model, allowing reification of the association but with the other models latest state (if the other model is paper trailed, this option does nothing)
64 65 66 |
# File 'lib/paper_trail/has_paper_trail.rb', line 64 def has_paper_trail( = {}) paper_trail.setup() end |
#paper_trail ⇒ Object
69 70 71 |
# File 'lib/paper_trail/has_paper_trail.rb', line 69 def paper_trail ::PaperTrail::ModelConfig.new(self) end |
#paper_trail_deprecate(new_method, old_method = nil) ⇒ 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.
74 75 76 77 78 |
# File 'lib/paper_trail/has_paper_trail.rb', line 74 def paper_trail_deprecate(new_method, old_method = nil) old = old_method.nil? ? new_method : old_method msg = format("Use paper_trail.%s instead of %s", new_method, old) ::ActiveSupport::Deprecation.warn(msg, caller(2)) end |
#paper_trail_enabled_for_model? ⇒ Boolean
111 112 113 114 |
# File 'lib/paper_trail/has_paper_trail.rb', line 111 def paper_trail_enabled_for_model? paper_trail_deprecate "enabled?", "paper_trail_enabled_for_model?" paper_trail.enabled? end |
#paper_trail_off! ⇒ Object
99 100 101 102 |
# File 'lib/paper_trail/has_paper_trail.rb', line 99 def paper_trail_off! paper_trail_deprecate "disable", "paper_trail_off!" paper_trail.disable end |
#paper_trail_on! ⇒ Object
105 106 107 108 |
# File 'lib/paper_trail/has_paper_trail.rb', line 105 def paper_trail_on! paper_trail_deprecate "enable", "paper_trail_on!" paper_trail.enable end |
#paper_trail_on_create ⇒ Object
93 94 95 96 |
# File 'lib/paper_trail/has_paper_trail.rb', line 93 def paper_trail_on_create paper_trail_deprecate "on_create", "paper_trail_on_create" paper_trail.on_create end |
#paper_trail_on_destroy(*args) ⇒ Object
81 82 83 84 |
# File 'lib/paper_trail/has_paper_trail.rb', line 81 def paper_trail_on_destroy(*args) paper_trail_deprecate "on_destroy", "paper_trail_on_destroy" paper_trail.on_destroy(*args) end |
#paper_trail_on_update ⇒ Object
87 88 89 90 |
# File 'lib/paper_trail/has_paper_trail.rb', line 87 def paper_trail_on_update paper_trail_deprecate "on_update", "paper_trail_on_update" paper_trail.on_update end |
#paper_trail_version_class ⇒ Object
117 118 119 120 |
# File 'lib/paper_trail/has_paper_trail.rb', line 117 def paper_trail_version_class paper_trail_deprecate "version_class", "paper_trail_version_class" paper_trail.version_class end |