Sha256: 405df45019b7904678bcac4489a47edafabc5eeb7e6681f292b632330e26f7e5

Contents?: true

Size: 522 Bytes

Versions: 10

Compression:

Stored size: 522 Bytes

Contents

module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Hash #:nodoc:
      module Accessors #:nodoc:
        def insert(key, attrs)
          if key.singular?
            self[key] = attrs unless self[key]
            self[key] = self[key].merge(attrs) if self[key]
          else
            if elements = self[key]
              elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
            else
              self[key] = [attrs]
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongoid-0.9.4 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.9.3 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.9.2 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.9.1 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.9.0 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.8.10 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.8.9 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.8.8 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.8.7 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.8.6 lib/mongoid/extensions/hash/accessors.rb