| Module | ActsAsRevisionable::InstanceMethods |
| In: |
lib/acts_as_revisionable.rb
|
Create a revision record based on this record and save it to the database.
# File lib/acts_as_revisionable.rb, line 150
150: def create_revision!
151: revision = RevisionRecord.new(self)
152: revision.save!
153: return revision
154: end
Disable the revisioning behavior inside of a block passed to the method.
# File lib/acts_as_revisionable.rb, line 163
163: def disable_revisioning
164: save_val = @revisions_disabled
165: retval = nil
166: begin
167: @revisions_disabled = true
168: retval = yield if block_given?
169: ensure
170: @revisions_disabled = save_val
171: end
172: return retval
173: end
Restore a revision of the record and return it. The record is not saved to the database. If there is a problem restoring values, errors will be added to the record.
# File lib/acts_as_revisionable.rb, line 108
108: def restore_revision (revision)
109: self.class.restore_revision(self.id, revision)
110: end
Restore a revision of the record and save it along with restored associations.
# File lib/acts_as_revisionable.rb, line 113
113: def restore_revision! (revision)
114: self.class.restore_revision!(self.id, revision)
115: end
Call this method to implement revisioning. The object changes should happen inside the block.
# File lib/acts_as_revisionable.rb, line 118
118: def store_revision
119: if new_record? or @revisions_disabled
120: return yield
121: else
122: retval = nil
123: revision = nil
124: begin
125: RevisionRecord.transaction do
126: read_only = self.class.find(self.id, :readonly => true) rescue nil
127: if read_only
128: revision = read_only.create_revision!
129: truncate_revisions!
130: end
131:
132: disable_revisioning do
133: retval = yield
134: end
135:
136: raise 'rollback_revision' unless errors.empty?
137: end
138: rescue => e
139: # In case the database doesn't support transactions
140: if revision
141: revision.destroy rescue nil
142: end
143: raise e unless e.message == 'rollback_revision'
144: end
145: return retval
146: end
147: end
Truncate the number of revisions kept for this record. Available options are :limit and :minimum_age.
# File lib/acts_as_revisionable.rb, line 157
157: def truncate_revisions! (options = nil)
158: options = {:limit => acts_as_revisionable_options[:limit], :minimum_age => acts_as_revisionable_options[:minimum_age]} unless options
159: RevisionRecord.truncate_revisions(self.class, self.id, options)
160: end