mongomatic 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mongomatic.rb CHANGED
@@ -29,6 +29,7 @@ module Mongomatic
29
29
  end
30
30
  end
31
31
 
32
+ require "#{File.dirname(__FILE__)}/mongomatic/util"
32
33
  require "#{File.dirname(__FILE__)}/mongomatic/m_hash"
33
34
  require "#{File.dirname(__FILE__)}/mongomatic/cursor"
34
35
  require "#{File.dirname(__FILE__)}/mongomatic/modifiers"
@@ -1,6 +1,7 @@
1
1
  module Mongomatic
2
2
  class Base
3
3
  include Mongomatic::Modifiers
4
+ include Mongomatic::Util
4
5
 
5
6
  class << self
6
7
  # Returns this models own db attribute if set, otherwise will return Mongomatic.db
@@ -44,7 +44,7 @@ module Mongomatic
44
44
  raise(UnexpectedFieldType)
45
45
  end
46
46
 
47
- val = Array(val)
47
+ val = create_array(val)
48
48
  op = { "$pushAll" => { mongo_field => val } }
49
49
  res = true
50
50
 
@@ -101,14 +101,14 @@ module Mongomatic
101
101
  raise(UnexpectedFieldType)
102
102
  end
103
103
 
104
- op = { "$pullAll" => { mongo_field => Array(val) } }
104
+ op = { "$pullAll" => { mongo_field => create_array(val) } }
105
105
  res = true
106
106
 
107
107
  safe == true ? res = update!({}, op) : update({}, op)
108
108
 
109
109
  if res
110
110
  hash[field] ||= []
111
- Array(val).each do |v|
111
+ create_array(val).each do |v|
112
112
  hash[field].delete(v)
113
113
  end; true
114
114
  end
@@ -215,7 +215,7 @@ module Mongomatic
215
215
 
216
216
  if res
217
217
  hash[field] ||= []
218
- Array(val).each do |v|
218
+ create_array(val).each do |v|
219
219
  hash[field] << v unless hash[field].include?(v)
220
220
  end
221
221
  true
@@ -0,0 +1,7 @@
1
+ module Mongomatic
2
+ module Util
3
+ def create_array(val)
4
+ val.is_a?(Array) ? val : [val]
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 4
9
- version: 0.5.4
8
+ - 5
9
+ version: 0.5.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Myles
@@ -99,6 +99,7 @@ files:
99
99
  - lib/mongomatic/expectations/present.rb
100
100
  - lib/mongomatic/m_hash.rb
101
101
  - lib/mongomatic/modifiers.rb
102
+ - lib/mongomatic/util.rb
102
103
  - LICENSE
103
104
  - README.rdoc
104
105
  - test/helper.rb