Module: PaperTrail::Model::InstanceMethods
- Defined in:
- lib/paper_trail/has_paper_trail.rb
Overview
Wrap the following methods in a module so we can include them only in the ActiveRecord models that declare `has_paper_trail`.
Instance Method Summary (collapse)
-
- (Boolean) live?
Returns true if this instance is the current, live one; returns false if this instance came from a previous version.
-
- (Object) next_version
Returns the object (not a Version) as it became next.
-
- (Object) originator
Returns who put the object into its current state.
-
- (Object) previous_version
Returns the object (not a Version) as it was most recently.
-
- (Object) version_at(timestamp)
Returns the object (not a Version) as it was at the given timestamp.
Instance Method Details
- (Boolean) live?
Returns true if this instance is the current, live one; returns false if this instance came from a previous version.
61 62 63 |
# File 'lib/paper_trail/has_paper_trail.rb', line 61 def live? version.nil? end |
- (Object) next_version
Returns the object (not a Version) as it became next.
85 86 87 88 89 90 |
# File 'lib/paper_trail/has_paper_trail.rb', line 85 def next_version # NOTE: if self (the item) was not reified from a version, i.e. it is the # "live" item, we return nil. Perhaps we should return self instead? subsequent_version = version ? version.next : nil subsequent_version.reify if subsequent_version end |
- (Object) originator
Returns who put the object into its current state.
66 67 68 |
# File 'lib/paper_trail/has_paper_trail.rb', line 66 def originator versions.last.try :whodunnit end |
- (Object) previous_version
Returns the object (not a Version) as it was most recently.
79 80 81 82 |
# File 'lib/paper_trail/has_paper_trail.rb', line 79 def previous_version last_version = version ? version.previous : versions.last last_version.try :reify end |
- (Object) version_at(timestamp)
Returns the object (not a Version) as it was at the given timestamp.
71 72 73 74 75 76 |
# File 'lib/paper_trail/has_paper_trail.rb', line 71 def version_at() # Because a version stores how its object looked *before* the change, # we need to look for the first version created *after* the timestamp. version = versions.first :conditions => ['created_at > ?', ], :order => 'created_at ASC, id ASC' version ? version.reify : self end |