Method: MongoMapper::Plugins::Modifiers::ClassMethods#unset

Defined in:
lib/mongo_mapper/plugins/modifiers.rb

#unset(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 27

def unset(*args)
  if args[0].is_a?(Hash)
    criteria, keys = args.shift, args
    options = keys.last.is_a?(Hash) ? keys.pop : {}
  else
    keys, ids = args.partition { |arg| arg.is_a?(Symbol) }
    options = ids.last.is_a?(Hash) ? ids.pop : {}
    criteria = {:id => ids}
  end

  criteria = criteria_hash(criteria).to_hash
  updates = keys.inject({}) { |hash, key| hash[key] = 1; hash }
  modifier_update('$unset', [criteria, updates, options])
end