Sha256: 8583de2d61cea6f52d2496f5ae87236722435c4cbc03b75b6bf11bda3a7de6d9

Contents?: true

Size: 611 Bytes

Versions: 7

Compression:

Stored size: 611 Bytes

Contents

module Audited
  module Adapters
    module MongoMapper
      class AuditedChanges < ::Hash
        def self.from_mongo(changes)
          changes.is_a?(Hash) ? new.replace(changes) : changes
        end

        def self.to_mongo(changes)
          if changes.is_a?(Hash)
            changes.inject({}) do |memo, (key, value)|
              memo[key] = if value.is_a?(Array)
                value.map{|v| v.class.to_mongo(v) }
              else
                value
              end
              memo
            end
          else
            changes
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
audited-mongo_mapper-4.2.2 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-4.2.1 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-4.2.0 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-4.0.0 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-4.0.0.rc1 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-3.0.0 lib/audited/adapters/mongo_mapper/audited_changes.rb
audited-mongo_mapper-3.0.0.rc2 lib/audited/adapters/mongo_mapper/audited_changes.rb