Module: Audited::Auditor::AuditedInstanceMethods
- Defined in:
- lib/audited/auditor.rb
Overview
if polymorphic, then [:polymorphic,“title”,
col of self to be displayed as comment,[:commentable_type,:commentable_id]]
opts format for notifiably_audited method/gem
notifiably_audited alert_for: [[[:assigned_to],
"Re-assigned",
"This product has been reassigned",
[:user,:email]],
[[:color,:score],
"Color/Score Changed",
"Color/Score value is changed"],
[[:product_status_id],
"Status Changed",
"Status of this product is changed",
[:product_status,:name]]],
associated_with: :product_status,
title: :name,
create_comment: "New <<here>> has been created",
update_comment: "Custom: Values of <<here>> has been updated"
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
notifiably_audited alert_for: [[:polymorphic,
nil,
:content,
[:commentable_type,:commentable_id]]]
alert_to :
The column of the target_object that has the user_id to send the notification to.(receiver_id of the Audit record)
alert_for :
Takes array of arrays as an argument. Every array in the main array corresponds to one or group of columns update and how to notify. Following is the index wise explanation of the arrays.
-
Column name or Column names
-
Title of the notification(title column of the Audit record)
-
Description of the notification(audit_comment column of the Audit record)
-
If the column name is a foreign key of an belongs_to association, then the model_name of the associated model and the column of the model to be displayed in title is specified
title :
Takes 1 column name or a method name of the target object as an argument, in order to prompt the title of the target object wherever needed in the notification
create_comment :
Default audit_comment for create action
update_comment :
Default audit_comment for update action
*************** :polymorphic *************** If this is passed as the first argument of the alert_for option, then it means, the current_model is polymorphic and the target_object is a different model to which the current model is polymorphic to.
In the above case the 4th argument of the alert_for option should be the type and id of the polymorphic model.(Ex: [:commentable_type,commentable_id])
Instance Method Summary collapse
-
#audited_attributes ⇒ Object
List of attributes that are audited.
-
#revision(version) ⇒ Object
Get a specific revision specified by the version number, or
:previous
. -
#revision_at(date_or_time) ⇒ Object
Find the oldest revision recorded prior to the date/time provided.
-
#revisions(from_version = 1) ⇒ Object
Gets an array of the revisions available.
-
#save_without_auditing ⇒ Object
Temporarily turns off auditing while saving.
-
#without_auditing(&block) ⇒ Object
Executes the block with the auditing callbacks disabled.
Instance Method Details
#audited_attributes ⇒ Object
List of attributes that are audited.
237 238 239 |
# File 'lib/audited/auditor.rb', line 237 def audited_attributes attributes.except(*non_audited_columns) end |
#revision(version) ⇒ Object
Get a specific revision specified by the version number, or :previous
226 227 228 |
# File 'lib/audited/auditor.rb', line 226 def revision(version) revision_with Audited.audit_class.reconstruct_attributes(audits_to(version)) end |
#revision_at(date_or_time) ⇒ Object
Find the oldest revision recorded prior to the date/time provided.
231 232 233 234 |
# File 'lib/audited/auditor.rb', line 231 def revision_at(date_or_time) audits = self.audits.up_until(date_or_time) revision_with Audited.audit_class.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
215 216 217 218 219 220 221 222 223 |
# File 'lib/audited/auditor.rb', line 215 def revisions(from_version = 1) audits = self.audits.from_version(from_version) return [] if audits.empty? revisions = [] audits.each do |audit| revisions << audit.revision end revisions end |
#save_without_auditing ⇒ Object
Temporarily turns off auditing while saving.
194 195 196 |
# File 'lib/audited/auditor.rb', line 194 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
204 205 206 |
# File 'lib/audited/auditor.rb', line 204 def without_auditing(&block) self.class.without_auditing(&block) end |