Module | CollectiveIdea::Acts::Audited::InstanceMethods |
In: |
lib/acts_as_audited.rb
|
# File lib/acts_as_audited.rb, line 155 155: def audited_attributes 156: attributes.except(*non_audited_columns) 157: end
# File lib/acts_as_audited.rb, line 150 150: def revision_at(date_or_time) 151: audits = self.audits.find(:all, :conditions => ["created_at <= ?", date_or_time]) 152: revision_with Audit.reconstruct_attributes(audits) unless audits.empty? 153: end
Gets an array of the revisions available
user.revisions.each do |revision| user.name user.version end
# File lib/acts_as_audited.rb, line 138 138: def revisions(from_version = 1) 139: audits = self.audits.find(:all, :conditions => ['version >= ?', from_version]) 140: return [] if audits.empty? 141: revision = self.audits.find_by_version(from_version).revision 142: Audit.reconstruct_attributes(audits) {|attrs| revision.revision_with(attrs) } 143: end
Temporarily turns off auditing while saving.
# File lib/acts_as_audited.rb, line 117 117: def save_without_auditing 118: without_auditing { save } 119: end
Executes the block with the auditing callbacks disabled.
@foo.without_auditing do @foo.save end
# File lib/acts_as_audited.rb, line 127 127: def without_auditing(&block) 128: self.class.without_auditing(&block) 129: end
# File lib/acts_as_audited.rb, line 161 161: def revision_with(attributes) 162: returning self.dup do |revision| 163: revision.send :instance_variable_set, '@attributes', self.attributes_before_type_cast 164: Audit.assign_revision_attributes(revision, attributes) 165: 166: # Remove any association proxies so that they will be recreated 167: # and reference the correct object for this revision. The only way 168: # to determine if an instance variable is a proxy object is to 169: # see if it responds to certain methods, as it forwards almost 170: # everything to its target. 171: for ivar in revision.instance_variables 172: proxy = revision.instance_variable_get ivar 173: if !proxy.nil? and proxy.respond_to? :proxy_respond_to? 174: revision.instance_variable_set ivar, nil 175: end 176: end 177: end 178: end