Module: Audited::Audit::ClassMethods
- Defined in:
- lib/audited/audit.rb
Instance Method Summary collapse
-
#as_user(user, &block) ⇒ Object
All audits made during the block called will be recorded as made by
user
. - #assign_revision_attributes(record, attributes) ⇒ Object
-
#audited_classes ⇒ Object
Returns the list of classes that are being audited.
- #reconstruct_attributes(audits) ⇒ Object
- #setup_audit ⇒ Object
Instance Method Details
#as_user(user, &block) ⇒ Object
All audits made during the block called will be recorded as made by user
. This method is hopefully threadsafe, making it ideal for background operations that require audit information.
34 35 36 37 38 39 |
# File 'lib/audited/audit.rb', line 34 def as_user(user, &block) Thread.current[:audited_user] = user yield ensure Thread.current[:audited_user] = nil end |
#assign_revision_attributes(record, attributes) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/audited/audit.rb', line 52 def assign_revision_attributes(record, attributes) attributes.each do |attr, val| record = record.dup if record.frozen? if record.respond_to?("#{attr}=") record.attributes.has_key?(attr.to_s) ? record[attr] = val : record.send("#{attr}=", val) end end record end |
#audited_classes ⇒ Object
Returns the list of classes that are being audited
27 28 29 |
# File 'lib/audited/audit.rb', line 27 def audited_classes audited_class_names.map(&:constantize) end |
#reconstruct_attributes(audits) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/audited/audit.rb', line 42 def reconstruct_attributes(audits) attributes = {} result = audits.collect do |audit| attributes.merge!(audit.new_attributes).merge!(:version => audit.version) yield attributes if block_given? end block_given? ? result : attributes end |
#setup_audit ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/audited/audit.rb', line 9 def setup_audit belongs_to :auditable, :polymorphic => true belongs_to :user, :polymorphic => true belongs_to :associated, :polymorphic => true before_create :set_version_number, :set_audit_user # senthil 30jan2018: Commenting out because no notifications as of now # after_save :notify cattr_accessor :audited_class_names self.audited_class_names = Set.new attr_accessible :action, :audited_changes, :comment, :associated, :receiver_id, :checked, :meta,:title end |