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

Defined in:
lib/acts_as_audited_rails3/base.rb

Instance Method Summary collapse

Instance Method Details

#audited_attributesObject



158
159
160
# File 'lib/acts_as_audited_rails3/base.rb', line 158

def audited_attributes
  attributes.except(*non_audited_columns)
end

#revision(version) ⇒ Object

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



149
150
151
# File 'lib/acts_as_audited_rails3/base.rb', line 149

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

#revision_at(date_or_time) ⇒ Object



153
154
155
156
# File 'lib/acts_as_audited_rails3/base.rb', line 153

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.version
end


141
142
143
144
145
146
# File 'lib/acts_as_audited_rails3/base.rb', line 141

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

#save_without_auditingObject

Temporarily turns off auditing while saving.



120
121
122
# File 'lib/acts_as_audited_rails3/base.rb', line 120

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


130
131
132
# File 'lib/acts_as_audited_rails3/base.rb', line 130

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