Sha256: a0a547c7ff9cd49de4b314772ff7ffc5ad37fff83efd0903d7c4888bb51e9faf

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module Mongoid
  module History
    module Attributes
      class Destroy < ::Mongoid::History::Attributes::Base
        def attributes
          @attributes = {}
          trackable.attributes.each { |k, v| @attributes[k] = [format_field(k, v), nil] if trackable_class.tracked_field?(k, :destroy) }
          insert_embeds_one_changes
          insert_embeds_many_changes
          @attributes
        end

        private

        def insert_embeds_one_changes
          trackable_class.tracked_embeds_one
                         .map { |rel| aliased_fields.key(rel) || rel }
                         .each do |rel|
            obj = trackable.send(rel)
            @attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
          end
        end

        def insert_embeds_many_changes
          trackable_class.tracked_embeds_many
                         .map { |rel| aliased_fields.key(rel) || rel }
                         .each do |rel|
            @attributes[rel] = [trackable.send(rel).map { |obj| format_embeds_many_relation(rel, obj.attributes) }, nil]
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mongoid-history-0.8.3 lib/mongoid/history/attributes/destroy.rb
mongoid-history-0.8.2 lib/mongoid/history/attributes/destroy.rb
mongoid-history-0.8.1 lib/mongoid/history/attributes/destroy.rb
mongoid-history-0.8.0 lib/mongoid/history/attributes/destroy.rb
mongoid-history-0.7.0 lib/mongoid/history/attributes/destroy.rb