class Mongoid::AuditLog::Changes
Attributes
model[R]
Public Class Methods
ch_ch_ch_ch_ch_changes()
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 7 def self.ch_ch_ch_ch_ch_changes puts "turn and face the strange changes" end
clean_fields(*disallowed_fields)
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 25 def self.clean_fields(*disallowed_fields) options = disallowed_fields.extract_options! unless options.has_key?(:from) raise ArgumentError, ':from is a required argument' end changes = options[:from] if changes.is_a?(Hash) changes.except(*disallowed_fields).inject({}) do |memo, t| key, value = *t memo.merge!(key => clean_fields(*disallowed_fields, :from => value)) end elsif changes.is_a?(Enumerable) changes.map { |c| clean_fields(*disallowed_fields, :from => c) } else changes end end
extract_from(value)
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 11 def self.extract_from(value) if value.is_a?(Hash) raise ArgumentError, 'does not support hashes' elsif value.is_a?(Enumerable) changes = value.map do |model| Mongoid::AuditLog::Changes.new(model).all end changes.reject(&:blank?) else Mongoid::AuditLog::Changes.new(value).all end end
new(model)
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 46 def initialize(model) @model = model end
Public Instance Methods
all()
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 50 def all @all ||= if model.blank? || !model.changed? {} else result = model.changes result.merge!(embedded_changes) unless embedded_changes.empty? Mongoid::AuditLog::Changes.clean_fields('_id', 'updated_at', :from => result) end end
Also aliased as: read
Private Instance Methods
embedded_changes()
click to toggle source
# File lib/mongoid/audit_log/changes.rb, line 63 def embedded_changes @embedded_changes ||= model.embedded_relations.inject({}) do |memo, t| name = t.first embedded = model.send(name) changes = Mongoid::AuditLog::Changes.extract_from(embedded) if embedded.present? && changes.present? memo[name] = changes end memo end end