Module: Shared::HasPapertrail
- Extended by:
- ActiveSupport::Concern
- Included in:
- AssertedDistribution, CollectingEvent, CollectionObject, Content, ControlledVocabularyTerm, FieldOccurrence, GeographicItem, Loan, Namespace, Otu, Person, PreparationType, Repository, Sequence, Serial, Source, TaxonName
- Defined in:
- app/models/concerns/shared/has_papertrail.rb
Overview
Shared code for models using PaperTrail
Instance Method Summary collapse
-
#attribute_updated(attribute) ⇒ DateTime
Returns the update time of the object’s attribute.
-
#attribute_updater(attribute) ⇒ Integer
Returns the updater’s ID of the object’s attribute.
- #detect_version(attribute) ⇒ Object private
Instance Method Details
#attribute_updated(attribute) ⇒ DateTime
Returns the update time of the object’s attribute
28 29 30 31 32 33 |
# File 'app/models/concerns/shared/has_papertrail.rb', line 28 def attribute_updated(attribute) if version = detect_version(attribute) return version.created_at end versions.first&.reify&.updated_at || updated_at end |
#attribute_updater(attribute) ⇒ Integer
Returns the updater’s ID of the object’s attribute
17 18 19 20 21 22 |
# File 'app/models/concerns/shared/has_papertrail.rb', line 17 def attribute_updater(attribute) if version = detect_version(attribute) return version.whodunnit.to_i end versions.first&.reify&.updated_by_id || updated_by_id end |
#detect_version(attribute) ⇒ Object (private)
37 38 39 40 41 |
# File 'app/models/concerns/shared/has_papertrail.rb', line 37 def detect_version(attribute) versions.reverse.detect do |version| version.reify&.send(attribute) != send(attribute) end end |