class Mongoid::AuditLog::Entry
Public Instance Methods
audited()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 65 def audited return nil if audited_type.blank? || audited_id.blank? if for_embedded_doc? lookup_from_document_path else audited_type.constantize.where(id: audited_id).first end end
for_embedded_doc?()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 61 def for_embedded_doc? document_path.try(:length).to_i > 1 end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/mongoid/audit_log/entry.rb, line 102 def method_missing(sym, *args, &block) key = sym.to_s if model_attributes.present? && model_attributes.has_key?(key) model_attributes[key] else super end end
modifier()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 42 def modifier @modifier ||= if modifier_id.blank? nil else klass = Mongoid::AuditLog.modifier_class_name.constantize klass.find(modifier_id) rescue nil end end
modifier=(modifier)
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 51 def modifier=(modifier) self.modifier_id = if modifier.present? && modifier.respond_to?(:id) modifier.id else modifier end @modifier = modifier end
respond_to?(sym, *args)
click to toggle source
Calls superclass method
# File lib/mongoid/audit_log/entry.rb, line 97 def respond_to?(sym, *args) key = sym.to_s (model_attributes.present? && model_attributes.has_key?(key)) || super end
restorable?()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 93 def restorable? destroy? && !restored? && Restore.new(self).valid? end
restore!()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 86 def restore! raise Restore::InvalidRestore if restored? || !destroy? Restore.new(self).perform update_attributes!(:restored => true) end
root()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 75 def root root = document_path.first return audited if root.blank? if for_embedded_doc? root['class_name'].constantize.where(id: root['id']).first else audited end end
valid?(*)
click to toggle source
Calls superclass method
# File lib/mongoid/audit_log/entry.rb, line 34 def valid?(*) result = super if result && modifier.blank? self.modifier = Mongoid::AuditLog.current_modifier end result end
Private Instance Methods
document_path_matches?(path, object)
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 134 def document_path_matches?(path, object) object.class.name == path['class_name'] && object.id == path['id'] end
lookup_from_document_path()
click to toggle source
# File lib/mongoid/audit_log/entry.rb, line 114 def lookup_from_document_path return nil if document_path.blank? document_path.reduce(root) do |current, path| relation_match = if document_path_matches?(path, current) current elsif current.respond_to?(:detect) current.detect do |model| document_path_matches?(path, model) end end if path['relation'].blank? || relation_match.blank? return relation_match else relation_match.send(path['relation']) end end end