Module: CollectiveIdea::Acts::Audited::InstanceMethods

Defined in:
lib/acts_as_audited.rb

Instance Method Summary collapse

Instance Method Details

#audited_attributesObject



156
157
158
# File 'lib/acts_as_audited.rb', line 156

def audited_attributes
  attributes.except(*non_audited_columns)
end

#revision(version) ⇒ Object

Get a specific revision specified by the version number, or :previous



147
148
149
# File 'lib/acts_as_audited.rb', line 147

def revision(version)
  revision_with Audit.reconstruct_attributes(audits_to(version))
end

#revision_at(date_or_time) ⇒ Object



151
152
153
154
# File 'lib/acts_as_audited.rb', line 151

def revision_at(date_or_time)
  audits = self.audits.find(:all, :conditions => ["created_at <= ?", date_or_time])
  revision_with Audit.reconstruct_attributes(audits) unless audits.empty?
end

#revisions(from_version = 1) ⇒ Object

Gets an array of the revisions available

user.revisions.each do |revision|
  user.name
  user.audit_version
end


139
140
141
142
143
144
# File 'lib/acts_as_audited.rb', line 139

def revisions(from_version = 1)
  audits = self.audits.find(:all, :conditions => ['audit_version >= ?', from_version])
  return [] if audits.empty?
  revision = self.audits.find_by_audit_version(from_version).revision
  Audit.reconstruct_attributes(audits) {|attrs| revision.revision_with(attrs) }
end

#save_without_auditingObject

Temporarily turns off auditing while saving.



118
119
120
# File 'lib/acts_as_audited.rb', line 118

def save_without_auditing
  without_auditing { save }
end

#without_auditing(&block) ⇒ Object

Executes the block with the auditing callbacks disabled.

@foo.without_auditing do
  @foo.save
end


128
129
130
# File 'lib/acts_as_audited.rb', line 128

def without_auditing(&block)
  self.class.without_auditing(&block)
end