diff --git a/CHANGELOG.md b/CHANGELOG.md index da89ca3..d79d62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +#### 0.3.1 + +* Use Array#wrap with `$each` method to be safe. + #### 0.3.0 * Replace `$pushAll` with `$push + $each`. diff --git a/lib/patches/atomic.rb b/lib/patches/atomic.rb index 532b9d4..20f3e62 100644 --- a/lib/patches/atomic.rb +++ b/lib/patches/atomic.rb @@ -74,7 +74,7 @@ def push_all(*args) if args.length == 1 && args.first.is_a?(Hash) query.update_all("$push" => collect_operations(args.first, true)) else - query.update_all("$push" => { database_field_name(args[0]) => { "$each" => args[1] } }) + query.update_all("$push" => { database_field_name(args[0]) => { "$each" => Array.wrap(args[1]) } }) end end @@ -104,7 +104,7 @@ def set_with_mongoid4(*args) def collect_operations(ops, use_each = false) ops.inject({}) do |operations, (field, value)| - operations[database_field_name(field)] = use_each ? { '$each' => value.mongoize } : value.mongoize + operations[database_field_name(field)] = use_each ? { '$each' => Array.wrap(value.mongoize) } : value.mongoize operations end end @@ -123,7 +123,7 @@ def persist end def operation(modifier) - { modifier => { path => value.is_a?(Array) ? { "$each" => value } : value}} + { modifier => { path => { "$each" => Array.wrap(value) } } } end end @@ -359,7 +359,7 @@ def execute_batch_insert(docs, operation, use_each = false) inserts = pre_process_batch_insert(docs) if insertable? collection.find(selector).update( - positionally(selector, operation => { path => use_each ? { '$each' => inserts } : inserts }) + positionally(selector, operation => { path => use_each ? { '$each' => Array.wrap(inserts) } : inserts }) ) post_process_batch_insert(docs) end diff --git a/lib/version.rb b/lib/version.rb index d37f9e0..540defc 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,3 +1,3 @@ module MongoidMonkey - VERSION = '0.3.0' + VERSION = '0.3.1' end