Class: PaperTrailHistory::VersionDecorator
- Inherits:
-
Object
- Object
- PaperTrailHistory::VersionDecorator
- Defined in:
- app/models/paper_trail_history/version_decorator.rb
Overview
Decorator for PaperTrail::Version objects providing formatted display methods
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #can_restore? ⇒ Boolean
- #changed_attributes ⇒ Object
- #event_class ⇒ Object
- #event_label ⇒ Object
- #formatted_created_at ⇒ Object
-
#initialize(version) ⇒ VersionDecorator
constructor
A new instance of VersionDecorator.
- #item_display_name ⇒ Object
- #whodunnit_display ⇒ Object
Constructor Details
#initialize(version) ⇒ VersionDecorator
Returns a new instance of VersionDecorator.
12 13 14 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 12 def initialize(version) @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 6 def version @version end |
Class Method Details
.decorate(version) ⇒ Object
16 17 18 19 20 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 16 def self.decorate(version) return version if version.is_a?(VersionDecorator) new(version) end |
.decorate_collection(versions) ⇒ Object
22 23 24 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 22 def self.decorate_collection(versions) versions.map { |version| decorate(version) } end |
Instance Method Details
#can_restore? ⇒ Boolean
72 73 74 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 72 def can_restore? version.event != 'create' end |
#changed_attributes ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 60 def changed_attributes return [] unless changeset changeset.map do |attr, (old_val, new_val)| { attribute: attr, old_value: format_value(old_val), new_value: format_value(new_val) } end end |
#event_class ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 43 def event_class case version.event when 'create' 'success' when 'update' 'warning' when 'destroy' 'danger' else 'info' end end |
#event_label ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 30 def event_label case version.event when 'create' I18n.t('paper_trail_history.events.created') when 'update' I18n.t('paper_trail_history.events.updated') when 'destroy' I18n.t('paper_trail_history.events.deleted') else version.event.humanize end end |
#formatted_created_at ⇒ Object
26 27 28 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 26 def formatted_created_at version.created_at.strftime('%B %d, %Y at %I:%M %p') end |
#item_display_name ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 76 def item_display_name if version.item version.item.try(:name) || version.item.try(:title) || "#{version.item_type} ##{version.item_id}" else "#{version.item_type} ##{version.item_id} (deleted)" end end |
#whodunnit_display ⇒ Object
56 57 58 |
# File 'app/models/paper_trail_history/version_decorator.rb', line 56 def whodunnit_display version.whodunnit || I18n.t('paper_trail_history.actors.system') end |