Module: ActsAsRevisionable::ClassMethods
- Defined in:
- lib/acts_as_revisionable.rb
Instance Method Summary collapse
-
#empty_trash(max_age) ⇒ Object
Delete all revision records for deleted items that are older than the specified maximum age in seconds.
-
#last_revision(id) ⇒ Object
Get the last revision for a specified id.
-
#restore_last_revision(id) ⇒ Object
Load the last revision for a record with the specified id.
-
#restore_last_revision!(id) ⇒ Object
Load the last revision for a record with the specified id and save it to the database.
-
#restore_revision(id, revision_number) ⇒ Object
Load a revision for a record with a particular id.
-
#restore_revision!(id, revision_number) ⇒ Object
Load a revision for a record with a particular id and save it to the database.
-
#revision(id, revision_number) ⇒ Object
Get a revision for a specified id.
-
#revisionable_associations(options = ) ⇒ Object
Returns a hash structure used to identify the revisioned associations.
Instance Method Details
#empty_trash(max_age) ⇒ Object
Delete all revision records for deleted items that are older than the specified maximum age in seconds.
121 122 123 |
# File 'lib/acts_as_revisionable.rb', line 121 def empty_trash(max_age) RevisionRecord.empty_trash(self, max_age) end |
#last_revision(id) ⇒ Object
Get the last revision for a specified id.
59 60 61 |
# File 'lib/acts_as_revisionable.rb', line 59 def last_revision(id) RevisionRecord.last_revision(self, id) end |
#restore_last_revision(id) ⇒ Object
Load the last revision for a record with the specified id. Associations added since the revision was created will still be in the restored record. If you want to save a revision with associations properly, use restore_last_revision!
86 87 88 89 |
# File 'lib/acts_as_revisionable.rb', line 86 def restore_last_revision(id) revision_record = last_revision(id) return revision_record.restore if revision_record end |
#restore_last_revision!(id) ⇒ Object
Load the last revision for a record with the specified id and save it to the database. You should always use this method to save a revision if it has associations.
93 94 95 96 97 98 99 100 101 |
# File 'lib/acts_as_revisionable.rb', line 93 def restore_last_revision!(id) record = restore_last_revision(id) if record record.store_revision do save_restorable_associations(record, revisionable_associations) end end return record end |
#restore_revision(id, revision_number) ⇒ Object
Load a revision for a record with a particular id. Associations added since the revision was created will still be in the restored record. If you want to save a revision with associations properly, use restore_revision!
66 67 68 69 |
# File 'lib/acts_as_revisionable.rb', line 66 def restore_revision(id, revision_number) revision_record = revision(id, revision_number) return revision_record.restore if revision_record end |
#restore_revision!(id, revision_number) ⇒ Object
Load a revision for a record with a particular id and save it to the database. You should always use this method to save a revision if it has associations.
73 74 75 76 77 78 79 80 81 |
# File 'lib/acts_as_revisionable.rb', line 73 def restore_revision!(id, revision_number) record = restore_revision(id, revision_number) if record record.store_revision do save_restorable_associations(record, revisionable_associations) end end return record end |
#revision(id, revision_number) ⇒ Object
Get a revision for a specified id.
54 55 56 |
# File 'lib/acts_as_revisionable.rb', line 54 def revision(id, revision_number) RevisionRecord.find_revision(self, id, revision_number) end |
#revisionable_associations(options = ) ⇒ Object
Returns a hash structure used to identify the revisioned associations.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/acts_as_revisionable.rb', line 104 def revisionable_associations( = [:associations]) return nil unless = [] unless .kind_of?(Array) associations = {} .each do |association| if association.kind_of?(Symbol) associations[association] = true elsif association.kind_of?(Hash) association.each_pair do |key, value| associations[key] = revisionable_associations(value) end end end return associations end |