module Mongoid::Contextual::Atomic
Public Instance Methods
add_to_set_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 9 def add_to_set_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$addToSet" => collect_operations(args.first)) else add_to_set_without_mongoid4(*args) end end
bit_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 18 def bit_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$bit" => collect_operations(args.first)) else bit_without_mongoid4(*args) end end
inc_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 27 def inc_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$inc" => collect_operations(args.first)) else inc_without_mongoid4(*args) end end
pop_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 36 def pop_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$pop" => collect_operations(args.first)) else pop_without_mongoid4(*args) end end
pull_all_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 54 def pull_all_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$pullAll" => collect_operations(args.first)) else pull_all_without_mongoid4(*args) end end
pull_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 45 def pull_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$pull" => collect_operations(args.first)) else pull_without_mongoid4(*args) end end
push_all(*args)
click to toggle source
Uses $push + $each rather than $pushAll
# File lib/patches/atomic.rb, line 73 def push_all(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$push" => collect_each_operations(args.first)) else query.update_all("$push" => { database_field_name(args[0]) => { "$each" => Array.wrap(args[1]) } }) end end
push_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 63 def push_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$push" => collect_operations(args.first)) else push_without_mongoid4(*args) end end
rename_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 81 def rename_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) operations = args.first.inject({}) do |ops, (old_name, new_name)| ops[old_name] = new_name.to_s ops end query.update_all("$rename" => collect_operations(operations)) else rename_without_mongoid4(*args) end end
set_with_mongoid4(*args)
click to toggle source
# File lib/patches/atomic.rb, line 94 def set_with_mongoid4(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$set" => collect_operations(args.first)) else set_without_mongoid4(*args) end end
Private Instance Methods
collect_each_operations(ops)
click to toggle source
# File lib/patches/atomic.rb, line 111 def collect_each_operations(ops) ops.each_with_object({}) do |(field, value), operations| operations[database_field_name(field)] = { "$each" => Array.wrap(value).mongoize } end end
collect_operations(ops)
click to toggle source
# File lib/patches/atomic.rb, line 105 def collect_operations(ops) ops.each_with_object({}) do |(field, value), operations| operations[database_field_name(field)] = value.mongoize end end