mongo-parser-rb 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,7 +91,12 @@ module MongoParserRB
91
91
  # the specified field does not exist on a document.
92
92
  return true if !value_for_field && !@field.in_document?(document)
93
93
 
94
- value_for_field != @arguments
94
+ if value_for_field.kind_of?(Array) &&
95
+ !@arguments.kind_of?(Array)
96
+ !value_for_field.include?(@arguments)
97
+ else
98
+ value_for_field != @arguments
99
+ end
95
100
  when :$nin
96
101
  if value_for_field.kind_of?(Array)
97
102
  (value_for_field & @arguments).length.zero?
@@ -108,6 +113,9 @@ module MongoParserRB
108
113
  when :$eq
109
114
  if @arguments.kind_of?(Regexp)
110
115
  !!(value_for_field =~ @arguments)
116
+ elsif value_for_field.kind_of?(Array) &&
117
+ !@arguments.kind_of?(Array)
118
+ value_for_field.include?(@arguments)
111
119
  else
112
120
  value_for_field == @arguments
113
121
  end
@@ -1,3 +1,3 @@
1
1
  module MongoParserRB
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -175,4 +175,20 @@ class QueryTest < MiniTest::Unit::TestCase
175
175
  refute query.matches_document?(:date_key => Time.new(1996,2,13,0,0,0))
176
176
  end
177
177
 
178
+ def test_eq_as_in_substitute
179
+ query = MongoParserRB::Query.parse(:array_key => 1)
180
+ assert query.matches_document?(:array_key => [1,2])
181
+
182
+ query = MongoParserRB::Query.parse(:array_key => [1])
183
+ refute query.matches_document?(:array_key => [1,2])
184
+ end
185
+
186
+ def test_ne_as_nin_substitue
187
+ query = MongoParserRB::Query.parse(:array_key => {:$ne => 1})
188
+ assert query.matches_document?(:array_key => [2,3])
189
+
190
+ query = MongoParserRB::Query.parse(:array_key => {:$ne => [1]})
191
+ assert query.matches_document?(:array_key => [1,2])
192
+ end
193
+
178
194
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-parser-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Parse and evaluate mongo queries in Ruby
15
15
  email:
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 1.8.25
57
+ rubygems_version: 1.8.23
58
58
  signing_key:
59
59
  specification_version: 3
60
60
  summary: Parse and evaluate mongo queries in Ruby