Module: RevertiblePaperTrail::Version
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/revertible_paper_trail/version.rb
Instance Method Summary collapse
- #active_item ⇒ Object
- #current_item ⇒ Object
- #previous_item ⇒ Object
- #revert ⇒ Object
- #versions ⇒ Object
Instance Method Details
#active_item ⇒ Object
19 20 21 22 |
# File 'lib/revertible_paper_trail/version.rb', line 19 def active_item # Take current item or reify latest version item || versions.last.reify end |
#current_item ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/revertible_paper_trail/version.rb', line 24 def current_item return nil if event == 'destroy' if self.next self.next.reify else # Use active item as it should exist self.item end end |
#previous_item ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/revertible_paper_trail/version.rb', line 35 def previous_item case event when "create" nil when "update" current_item.previous_version when "destroy" reify end end |
#revert ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/revertible_paper_trail/version.rb', line 5 def revert case event when "create" # Do nothing if item already destroyed again return unless self.item self.item.destroy when "update" self.reify.save when "destroy" self.reify.save end end |
#versions ⇒ Object
46 47 48 |
# File 'lib/revertible_paper_trail/version.rb', line 46 def versions sibling_versions end |