Class: Mongoid::AuditLog::Changes
- Inherits:
-
Object
- Object
- Mongoid::AuditLog::Changes
- Defined in:
- lib/mongoid/audit_log/changes.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
- .ch_ch_ch_ch_ch_changes ⇒ Object
- .clean_fields(*disallowed_fields) ⇒ Object
- .extract_from(value) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object (also: #read)
-
#initialize(model) ⇒ Changes
constructor
A new instance of Changes.
Constructor Details
#initialize(model) ⇒ Changes
Returns a new instance of Changes.
46 47 48 |
# File 'lib/mongoid/audit_log/changes.rb', line 46 def initialize(model) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/mongoid/audit_log/changes.rb', line 4 def model @model end |
Class Method Details
.ch_ch_ch_ch_ch_changes ⇒ Object
7 8 9 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mongoid/audit_log/changes.rb', line 25 def self.clean_fields(*disallowed_fields) = disallowed_fields. unless .has_key?(:from) raise ArgumentError, ':from is a required argument' end changes = [: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) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#all ⇒ Object Also known as: read
50 51 52 53 54 55 56 57 58 |
# File 'lib/mongoid/audit_log/changes.rb', line 50 def all @all ||= if model.blank? || !model.changed? {} else result = model.changes result.merge!() unless .empty? Mongoid::AuditLog::Changes.clean_fields('_id', 'updated_at', :from => result) end end |