module MmNoEmpties::ClassMethods
Public Instance Methods
set(*args)
click to toggle source
# File lib/mm_no_empties.rb, line 16 def set(*args) criteria, updates, options = criteria_and_keys_from_args(args) unset_cmd = {} updates.each do |key, value| updates[key] = keys[key.to_s].set(value) if key?(key) unset_cmd[key] = 1 unless updates[key].present? end set_attr = updates.except(*unset_cmd.keys) update_cmd = {} update_cmd['$set'] = set_attr if set_attr.present? update_cmd['$unset'] = unset_cmd if unset_cmd.present? if options collection.update(criteria, update_cmd, options.merge(:multi => true)) else collection.update(criteria, update_cmd, :multi => true) end end