Module: PaperTrail::VersionConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Version
- Defined in:
- lib/paper_trail/version_concern.rb
Overview
Originally, PaperTrail did not provide this module, and all of this functionality was in PaperTrail::Version. That model still exists (and is used by most apps) but by moving the functionality to this module, people can include this concern instead of sub-classing the Version model.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#changeset ⇒ Object
Returns what changed in this version of the item.
-
#index ⇒ Object
Returns an integer representing the chronological position of the version among its siblings (see
sibling_versions). - #next ⇒ Object
- #object_deserialized ⇒ Object private
- #originator ⇒ Object
-
#paper_trail_originator ⇒ Object
Returns who put the item into the state stored in this version.
- #previous ⇒ Object
-
#reify(options = {}) ⇒ Object
Restore the item from this version.
- #sibling_versions(reload = false) ⇒ Object
-
#terminator ⇒ Object
(also: #version_author)
Returns who changed the item from the state it had in this version.
Instance Method Details
#changeset ⇒ Object
Returns what changed in this version of the item. ‘ActiveModel::Dirty#changes`. returns nil if your versions table does not have an object_changes text column.
236 237 238 239 |
# File 'lib/paper_trail/version_concern.rb', line 236 def changeset return nil unless self.class.column_names.include? "object_changes" @changeset ||= load_changeset end |
#index ⇒ Object
Returns an integer representing the chronological position of the version among its siblings (see sibling_versions). The “create” event, for example, has an index of 0.
277 278 279 |
# File 'lib/paper_trail/version_concern.rb', line 277 def index @index ||= RecordHistory.new(sibling_versions, self.class).index(self) end |
#next ⇒ Object
265 266 267 |
# File 'lib/paper_trail/version_concern.rb', line 265 def next @next ||= sibling_versions.subsequent(self).first end |
#object_deserialized ⇒ 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.
191 192 193 194 195 196 197 |
# File 'lib/paper_trail/version_concern.rb', line 191 def object_deserialized if self.class.object_col_is_json? object else PaperTrail.serializer.load(object) end end |
#originator ⇒ Object
246 247 248 249 |
# File 'lib/paper_trail/version_concern.rb', line 246 def originator ::ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." paper_trail_originator end |
#paper_trail_originator ⇒ Object
Returns who put the item into the state stored in this version.
242 243 244 |
# File 'lib/paper_trail/version_concern.rb', line 242 def paper_trail_originator @paper_trail_originator ||= previous.try(:whodunnit) end |
#previous ⇒ Object
269 270 271 |
# File 'lib/paper_trail/version_concern.rb', line 269 def previous @previous ||= sibling_versions.preceding(self).first end |
#reify(options = {}) ⇒ Object
Restore the item from this version.
Optionally this can also restore all :has_one and :has_many (including has_many :through) associations as they were “at the time”, if they are also being versioned by PaperTrail.
Options:
-
:has_one
-
true- Also reify has_one associations. -
‘false - Default.
-
-
:has_many
-
true- Also reify has_many and has_many :through associations. -
false- Default.
-
-
:mark_for_destruction
-
true- Mark the has_one/has_many associations that did not exist in the reified version for destruction, instead of removing them. -
false- Default. Useful for persisting the reified version.
-
-
:dup
-
false- Default. -
true- Always create a new object instance. Useful for comparing two versions of the same object.
-
-
:unversioned_attributes
-
:nil- Default. Attributes undefined in version record are set to nil in reified record. -
:preserve- Attributes undefined in version record are not modified.
-
226 227 228 229 230 231 |
# File 'lib/paper_trail/version_concern.rb', line 226 def reify( = {}) return nil if object.nil? without_identity_map do ::PaperTrail::Reifier.reify(self, ) end end |
#sibling_versions(reload = false) ⇒ Object
258 259 260 261 262 263 |
# File 'lib/paper_trail/version_concern.rb', line 258 def sibling_versions(reload = false) if reload || @sibling_versions.nil? @sibling_versions = self.class.with_item_keys(item_type, item_id) end @sibling_versions end |
#terminator ⇒ Object Also known as:
Returns who changed the item from the state it had in this version. This is an alias for whodunnit.
253 254 255 |
# File 'lib/paper_trail/version_concern.rb', line 253 def terminator @terminator ||= whodunnit end |