Module: Mongoid::Extensions::Hash::Accessors

Included in:
Hash
Defined in:
lib/mongoid/extensions/hash/accessors.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#insert(key, attrs) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/mongoid/extensions/hash/accessors.rb', line 5

def insert(key, attrs)
  store(key, attrs) if key.singular?
  if key.plural?
    if elements = fetch(key, nil)
      elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
    else
      store(key, [attrs])
    end
  end
end