origin 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -7
- data/lib/origin/optional.rb +37 -1
- data/lib/origin/queryable.rb +1 -1
- data/lib/origin/selectable.rb +26 -0
- data/lib/origin/selector.rb +21 -3
- data/lib/origin/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b18444ac7a70fe5f8b4ffb6cfc3561007018adb
|
4
|
+
data.tar.gz: df43b397e418dbe94ae4435252f73490d4ba8d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d9b33aba3b290a0112d0d8b02d446d881da38de59c612f0da08aede046ed695bffd6b03ff1bf1a6db01c6dd7b146078c538e05f3caedd6118314333816f6e5
|
7
|
+
data.tar.gz: 6e917ba1a28baf310037fac320b9db36ba54aa6ba69868183db13eb30e02db042775ed33ef36a317e209ab7089c3cd31e5dea9abce09f2885755b3fafa85b8b3
|
data/CHANGELOG.md
CHANGED
data/lib/origin/optional.rb
CHANGED
@@ -267,6 +267,42 @@ module Origin
|
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
270
|
+
# Associate a comment with the query.
|
271
|
+
#
|
272
|
+
# @example Add a comment.
|
273
|
+
# optional.comment('slow query')
|
274
|
+
#
|
275
|
+
# @note Set profilingLevel to 2 and the comment will be logged in the profile
|
276
|
+
# collection along with the query.
|
277
|
+
#
|
278
|
+
# @param [ String ] comment The comment to be associated with the query.
|
279
|
+
#
|
280
|
+
# @return [ Optional ] The cloned optional.
|
281
|
+
#
|
282
|
+
# @since 2.2.0
|
283
|
+
def comment(comment = nil)
|
284
|
+
clone.tap do |query|
|
285
|
+
query.options.store(:comment, comment)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Set the cursor type.
|
290
|
+
#
|
291
|
+
# @example Set the cursor type.
|
292
|
+
# optional.cursor_type(:tailable)
|
293
|
+
# optional.cursor_type(:tailable_await)
|
294
|
+
#
|
295
|
+
# @note The cursor can be type :tailable or :tailable_await.
|
296
|
+
#
|
297
|
+
# @param [ Symbol ] type The type of cursor to create.
|
298
|
+
#
|
299
|
+
# @return [ Optional ] The cloned optional.
|
300
|
+
#
|
301
|
+
# @since 2.2.0
|
302
|
+
def cursor_type(type)
|
303
|
+
clone.tap { |query| query.options.store(:cursor_type, type) }
|
304
|
+
end
|
305
|
+
|
270
306
|
private
|
271
307
|
|
272
308
|
# Add a single sort option.
|
@@ -284,7 +320,7 @@ module Origin
|
|
284
320
|
#
|
285
321
|
# @since 1.0.0
|
286
322
|
def add_sort_option(options, field, direction)
|
287
|
-
if driver == :
|
323
|
+
if driver == :mongo1x
|
288
324
|
sorting = (options[:sort] || []).dup
|
289
325
|
sorting.push([ field, direction ])
|
290
326
|
options.store(:sort, sorting)
|
data/lib/origin/queryable.rb
CHANGED
@@ -58,7 +58,7 @@ module Origin
|
|
58
58
|
# @param [ Symbol ] driver The driver being used.
|
59
59
|
#
|
60
60
|
# @since 1.0.0
|
61
|
-
def initialize(aliases = {}, serializers = {}, driver = :
|
61
|
+
def initialize(aliases = {}, serializers = {}, driver = :mongo)
|
62
62
|
@aliases, @driver, @serializers = aliases, driver.to_sym, serializers
|
63
63
|
@options = Options.new(aliases, serializers)
|
64
64
|
@selector = Selector.new(aliases, serializers)
|
data/lib/origin/selectable.rb
CHANGED
@@ -491,6 +491,32 @@ module Origin
|
|
491
491
|
::Integer.evolve(value)
|
492
492
|
end
|
493
493
|
|
494
|
+
# Construct a text search selector.
|
495
|
+
#
|
496
|
+
# @example Construct a text search selector.
|
497
|
+
# selectable.text_search("testing")
|
498
|
+
#
|
499
|
+
# @example Construct a text search selector with options.
|
500
|
+
# selectable.text_search("testing", :$language => "fr")
|
501
|
+
#
|
502
|
+
# @param [ String, Symbol ] terms A string of terms that MongoDB parses
|
503
|
+
# and uses to query the text index.
|
504
|
+
# @param [ Hash ] opts Text search options. See MongoDB documentation
|
505
|
+
# for options.
|
506
|
+
#
|
507
|
+
# @return [ Selectable ] The cloned selectable.
|
508
|
+
#
|
509
|
+
# @since 2.2.0
|
510
|
+
def text_search(terms, opts = nil)
|
511
|
+
clone.tap do |query|
|
512
|
+
if terms
|
513
|
+
criterion = { :$text => { :$search => terms } }
|
514
|
+
criterion[:$text].merge!(opts) if opts
|
515
|
+
query.selector = criterion
|
516
|
+
end
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
494
520
|
# This is the general entry point for most MongoDB queries. This either
|
495
521
|
# creates a standard field: value selection, and expanded selection with
|
496
522
|
# the use of hash methods, or a $where selection if a string is provided.
|
data/lib/origin/selector.rb
CHANGED
@@ -18,7 +18,9 @@ module Origin
|
|
18
18
|
def merge!(other)
|
19
19
|
other.each_pair do |key, value|
|
20
20
|
if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
|
21
|
-
value = self[key.to_s].merge(value)
|
21
|
+
value = self[key.to_s].merge(value) do |_key, old_val, new_val|
|
22
|
+
multi_value?(_key) ? (old_val + new_val).uniq : new_val
|
23
|
+
end
|
22
24
|
end
|
23
25
|
if multi_selection?(key)
|
24
26
|
value = (self[key.to_s] || []).concat(value)
|
@@ -154,7 +156,7 @@ module Origin
|
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
157
|
-
# Determines if the selection is a multi-select, like an $and or $or
|
159
|
+
# Determines if the selection is a multi-select, like an $and or $or or $nor
|
158
160
|
# selection.
|
159
161
|
#
|
160
162
|
# @api private
|
@@ -168,7 +170,23 @@ module Origin
|
|
168
170
|
#
|
169
171
|
# @since 1.0.0
|
170
172
|
def multi_selection?(key)
|
171
|
-
key =~ /\$and|\$or/
|
173
|
+
key =~ /\$and|\$or|\$nor/
|
174
|
+
end
|
175
|
+
|
176
|
+
# Determines if the selection operator takes a list. Returns true for $in and $nin.
|
177
|
+
#
|
178
|
+
# @api private
|
179
|
+
#
|
180
|
+
# @example Does the selection operator take multiple values?
|
181
|
+
# selector.multi_value?("$nin")
|
182
|
+
#
|
183
|
+
# @param [ String ] key The key to check.
|
184
|
+
#
|
185
|
+
# @return [ true, false ] If the key is $in or $nin.
|
186
|
+
#
|
187
|
+
# @since 2.1.1
|
188
|
+
def multi_value?(key)
|
189
|
+
key =~ /\$nin|\$in/
|
172
190
|
end
|
173
191
|
end
|
174
192
|
end
|
data/lib/origin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Origin is a simple DSL for generating MongoDB selectors and options
|
14
14
|
email:
|
@@ -71,8 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: 1.3.6
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project: origin
|
74
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.4.6
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: Simple DSL for MongoDB query generation
|
78
78
|
test_files: []
|
79
|
+
has_rdoc:
|