origin 1.0.0.alpha → 1.0.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/origin/extensions/string.rb +2 -1
- data/lib/origin/extensions/symbol.rb +2 -1
- data/lib/origin/extensions/time.rb +12 -0
- data/lib/origin/key.rb +4 -2
- data/lib/origin/mergeable.rb +31 -2
- data/lib/origin/optional.rb +1 -0
- data/lib/origin/selectable.rb +126 -99
- data/lib/origin/version.rb +1 -1
- metadata +3 -3
@@ -53,11 +53,12 @@ module Origin
|
|
53
53
|
# "field".specify(value)
|
54
54
|
#
|
55
55
|
# @param [ Object ] value The value of the criteria.
|
56
|
+
# @param [ true, false ] negating If the selection should be negated.
|
56
57
|
#
|
57
58
|
# @return [ Hash ] The selection.
|
58
59
|
#
|
59
60
|
# @since 1.0.0
|
60
|
-
def specify(value)
|
61
|
+
def specify(value, negating = false)
|
61
62
|
{ self => value }
|
62
63
|
end
|
63
64
|
|
@@ -11,11 +11,12 @@ module Origin
|
|
11
11
|
# :field.specify(value)
|
12
12
|
#
|
13
13
|
# @param [ Object ] value The value of the criteria.
|
14
|
+
# @param [ true, false ] negating If the selection should be negated.
|
14
15
|
#
|
15
16
|
# @return [ Hash ] The selection.
|
16
17
|
#
|
17
18
|
# @since 1.0.0
|
18
|
-
def specify(value)
|
19
|
+
def specify(value, negating = false)
|
19
20
|
{ self => value }
|
20
21
|
end
|
21
22
|
|
@@ -5,6 +5,18 @@ module Origin
|
|
5
5
|
# This module contains additional time behaviour.
|
6
6
|
module Time
|
7
7
|
|
8
|
+
# Evolve the time as a date, UTC midnight.
|
9
|
+
#
|
10
|
+
# @example Evolve the time to a date query format.
|
11
|
+
# time.__evolve_date__
|
12
|
+
#
|
13
|
+
# @return [ Time ] The date at midnight UTC.
|
14
|
+
#
|
15
|
+
# @since 1.0.0
|
16
|
+
def __evolve_date__
|
17
|
+
::Time.utc(year, month, day, 0, 0, 0, 0)
|
18
|
+
end
|
19
|
+
|
8
20
|
# Evolve the time into a utc time.
|
9
21
|
#
|
10
22
|
# @example Evolve the time.
|
data/lib/origin/key.rb
CHANGED
@@ -49,13 +49,15 @@ module Origin
|
|
49
49
|
# key.specify(50)
|
50
50
|
#
|
51
51
|
# @param [ Object ] object The value to be included.
|
52
|
+
# @param [ true, false ] negating If the selection should be negated.
|
52
53
|
#
|
53
54
|
# @return [ Hash ] The raw MongoDB selector.
|
54
55
|
#
|
55
56
|
# @since 1.0.0
|
56
|
-
def specify(object)
|
57
|
+
def specify(object, negating = false)
|
57
58
|
value = block ? block[object] : object
|
58
|
-
|
59
|
+
expression = { operator => expanded ? { expanded => value } : value }
|
60
|
+
{ name.to_s => negating ? { "$not" => expression } : expression }
|
59
61
|
end
|
60
62
|
|
61
63
|
# Get the key as raw Mongo sorting options.
|
data/lib/origin/mergeable.rb
CHANGED
@@ -43,6 +43,18 @@ module Origin
|
|
43
43
|
use(:__union__)
|
44
44
|
end
|
45
45
|
|
46
|
+
# Reset the stratgies to nil, used after cloning.
|
47
|
+
#
|
48
|
+
# @example Reset the strategies.
|
49
|
+
# mergeable.reset_strategies!
|
50
|
+
#
|
51
|
+
# @return [ nil ] nil.
|
52
|
+
#
|
53
|
+
# @since 1.0.0
|
54
|
+
def reset_strategies!
|
55
|
+
self.strategy, self.negating = nil, nil
|
56
|
+
end
|
57
|
+
|
46
58
|
private
|
47
59
|
|
48
60
|
# Adds the criterion to the existing selection.
|
@@ -205,7 +217,7 @@ module Origin
|
|
205
217
|
# @api private
|
206
218
|
#
|
207
219
|
# @example Add criterion with a strategy.
|
208
|
-
#
|
220
|
+
# mergeable.with_strategy(:__union__, [ 1, 2, 3 ], "$in")
|
209
221
|
#
|
210
222
|
# @param [ Symbol ] strategy The name of the strategy method.
|
211
223
|
# @param [ Object ] criterion The criterion to add.
|
@@ -218,9 +230,26 @@ module Origin
|
|
218
230
|
selection(criterion) do |selector, field, value|
|
219
231
|
selector.store(
|
220
232
|
field,
|
221
|
-
selector[field].send(strategy,
|
233
|
+
selector[field].send(strategy, prepared(field, operator, value))
|
222
234
|
)
|
223
235
|
end
|
224
236
|
end
|
237
|
+
|
238
|
+
# Get the selection as a prepared selection.
|
239
|
+
#
|
240
|
+
# @example Get the prepared selection.
|
241
|
+
# mergeable.prepared("name", "$all", [ 1, 2 ])
|
242
|
+
#
|
243
|
+
# @param [ String, Symbol ] field The name of the field.
|
244
|
+
# @param [ String ] operator The operator.
|
245
|
+
# @param [ Object ] value The value.
|
246
|
+
#
|
247
|
+
# @return [ Hash ] The prepared selection.
|
248
|
+
#
|
249
|
+
# @since 1.0.0
|
250
|
+
def prepared(field, operator, value)
|
251
|
+
selection = { operator => prepare(field, operator, value) }
|
252
|
+
negating? ? { "$not" => selection } : selection
|
253
|
+
end
|
225
254
|
end
|
226
255
|
end
|
data/lib/origin/optional.rb
CHANGED
data/lib/origin/selectable.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Origin
|
3
3
|
|
4
|
-
# An origin
|
4
|
+
# An origin selectable is selectable, in that it has the ability to select
|
5
5
|
# document from the database. The selectable module brings all functionality
|
6
|
-
# to the
|
6
|
+
# to the selectable that has to do with building MongoDB selectors.
|
7
7
|
module Selectable
|
8
8
|
include Mergeable
|
9
9
|
extend Macroable
|
10
10
|
|
11
|
+
# @attribute [rw] negating If the next spression is negated.
|
11
12
|
# @attribute [rw] selector The query selector.
|
12
|
-
attr_accessor :selector
|
13
|
+
attr_accessor :negating, :selector
|
13
14
|
|
14
15
|
# Add the $all criterion.
|
15
16
|
#
|
16
17
|
# @example Add the criterion.
|
17
|
-
#
|
18
|
+
# selectable.all(field: [ 1, 2 ])
|
18
19
|
#
|
19
20
|
# @example Execute an $all in a where query.
|
20
|
-
#
|
21
|
+
# selectable.where(:field.all => [ 1, 2 ])
|
21
22
|
#
|
22
23
|
# @param [ Hash ] criterion The key value pairs for $all matching.
|
23
24
|
#
|
24
|
-
# @return [ Selectable ] The cloned
|
25
|
+
# @return [ Selectable ] The cloned selectable.
|
25
26
|
#
|
26
27
|
# @since 1.0.0
|
27
28
|
def all(criterion = nil)
|
@@ -33,12 +34,12 @@ module Origin
|
|
33
34
|
# Add the $and criterion.
|
34
35
|
#
|
35
36
|
# @example Add the criterion.
|
36
|
-
#
|
37
|
+
# selectable.and({ field: value }, { other: value })
|
37
38
|
#
|
38
39
|
# @param [ Array<Hash> ] criterion Multiple key/value pair matches that
|
39
40
|
# all must match to return results.
|
40
41
|
#
|
41
|
-
# @return [ Selectable ] The cloned
|
42
|
+
# @return [ Selectable ] The cloned selectable.
|
42
43
|
#
|
43
44
|
# @since 1.0.0
|
44
45
|
def and(*criterion)
|
@@ -49,14 +50,14 @@ module Origin
|
|
49
50
|
# Add the range selection.
|
50
51
|
#
|
51
52
|
# @example Match on results within a single range.
|
52
|
-
#
|
53
|
+
# selectable.between(field: 1..2)
|
53
54
|
#
|
54
55
|
# @example Match on results between multiple ranges.
|
55
|
-
#
|
56
|
+
# selectable.between(field: 1..2, other: 5..7)
|
56
57
|
#
|
57
58
|
# @param [ Hash ] criterion Multiple key/range pairs.
|
58
59
|
#
|
59
|
-
# @return [ Selectable ] The cloned
|
60
|
+
# @return [ Selectable ] The cloned selectable.
|
60
61
|
#
|
61
62
|
# @since 1.0.0
|
62
63
|
def between(criterion = nil)
|
@@ -71,20 +72,20 @@ module Origin
|
|
71
72
|
# Select with an $elemMatch.
|
72
73
|
#
|
73
74
|
# @example Add criterion for a single match.
|
74
|
-
#
|
75
|
+
# selectable.elem_match(field: { name: "value" })
|
75
76
|
#
|
76
77
|
# @example Add criterion for multiple matches.
|
77
|
-
#
|
78
|
+
# selectable.elem_match(
|
78
79
|
# field: { name: "value" },
|
79
80
|
# other: { name: "value"}
|
80
81
|
# )
|
81
82
|
#
|
82
83
|
# @example Execute an $elemMatch in a where query.
|
83
|
-
#
|
84
|
+
# selectable.where(:field.elem_match => { name: "value" })
|
84
85
|
#
|
85
86
|
# @param [ Hash ] criterion The field/match pairs.
|
86
87
|
#
|
87
|
-
# @return [ Selectable ] The cloned
|
88
|
+
# @return [ Selectable ] The cloned selectable.
|
88
89
|
#
|
89
90
|
# @since 1.0.0
|
90
91
|
def elem_match(criterion = nil)
|
@@ -95,17 +96,17 @@ module Origin
|
|
95
96
|
# Add the $exists selection.
|
96
97
|
#
|
97
98
|
# @example Add a single selection.
|
98
|
-
#
|
99
|
+
# selectable.exists(field: true)
|
99
100
|
#
|
100
101
|
# @example Add multiple selections.
|
101
|
-
#
|
102
|
+
# selectable.exists(field: true, other: false)
|
102
103
|
#
|
103
104
|
# @example Execute an $exists in a where query.
|
104
|
-
#
|
105
|
+
# selectable.where(:field.exists => true)
|
105
106
|
#
|
106
107
|
# @param [ Hash ] criterion The field/boolean existence checks.
|
107
108
|
#
|
108
|
-
# @return [ Selectable ] The cloned
|
109
|
+
# @return [ Selectable ] The cloned selectable.
|
109
110
|
#
|
110
111
|
# @since 1.0.0
|
111
112
|
def exists(criterion = nil)
|
@@ -120,14 +121,14 @@ module Origin
|
|
120
121
|
# Add the $gt criterion to the selector.
|
121
122
|
#
|
122
123
|
# @example Add the $gt criterion.
|
123
|
-
#
|
124
|
+
# selectable.gt(age: 60)
|
124
125
|
#
|
125
126
|
# @example Execute an $gt in a where query.
|
126
|
-
#
|
127
|
+
# selectable.where(:field.gt => 10)
|
127
128
|
#
|
128
129
|
# @param [ Hash ] criterion The field/value pairs to check.
|
129
130
|
#
|
130
|
-
# @return [ Selectable ] The cloned
|
131
|
+
# @return [ Selectable ] The cloned selectable.
|
131
132
|
#
|
132
133
|
# @since 1.0.0
|
133
134
|
def gt(criterion = nil)
|
@@ -138,14 +139,14 @@ module Origin
|
|
138
139
|
# Add the $gte criterion to the selector.
|
139
140
|
#
|
140
141
|
# @example Add the $gte criterion.
|
141
|
-
#
|
142
|
+
# selectable.gte(age: 60)
|
142
143
|
#
|
143
144
|
# @example Execute an $gte in a where query.
|
144
|
-
#
|
145
|
+
# selectable.where(:field.gte => 10)
|
145
146
|
#
|
146
147
|
# @param [ Hash ] criterion The field/value pairs to check.
|
147
148
|
#
|
148
|
-
# @return [ Selectable ] The cloned
|
149
|
+
# @return [ Selectable ] The cloned selectable.
|
149
150
|
#
|
150
151
|
# @since 1.0.0
|
151
152
|
def gte(criterion = nil)
|
@@ -153,20 +154,20 @@ module Origin
|
|
153
154
|
end
|
154
155
|
key :gte, :override, "$gte"
|
155
156
|
|
156
|
-
# Adds the $in selection to the
|
157
|
+
# Adds the $in selection to the selectable.
|
157
158
|
#
|
158
159
|
# @example Add $in selection on an array.
|
159
|
-
#
|
160
|
+
# selectable.in(age: [ 1, 2, 3 ])
|
160
161
|
#
|
161
162
|
# @example Add $in selection on a range.
|
162
|
-
#
|
163
|
+
# selectable.in(age: 18..24)
|
163
164
|
#
|
164
165
|
# @example Execute an $in in a where query.
|
165
|
-
#
|
166
|
+
# selectable.where(:field.in => [ 1, 2, 3 ])
|
166
167
|
#
|
167
168
|
# @param [ Hash ] criterion The field/value criterion pairs.
|
168
169
|
#
|
169
|
-
# @return [ Selectable ] The cloned
|
170
|
+
# @return [ Selectable ] The cloned selectable.
|
170
171
|
#
|
171
172
|
# @since 1.0.0
|
172
173
|
def in(criterion = nil)
|
@@ -178,14 +179,14 @@ module Origin
|
|
178
179
|
# Add the $lt criterion to the selector.
|
179
180
|
#
|
180
181
|
# @example Add the $lt criterion.
|
181
|
-
#
|
182
|
+
# selectable.lt(age: 60)
|
182
183
|
#
|
183
184
|
# @example Execute an $lt in a where query.
|
184
|
-
#
|
185
|
+
# selectable.where(:field.lt => 10)
|
185
186
|
#
|
186
187
|
# @param [ Hash ] criterion The field/value pairs to check.
|
187
188
|
#
|
188
|
-
# @return [ Selectable ] The cloned
|
189
|
+
# @return [ Selectable ] The cloned selectable.
|
189
190
|
#
|
190
191
|
# @since 1.0.0
|
191
192
|
def lt(criterion = nil)
|
@@ -196,14 +197,14 @@ module Origin
|
|
196
197
|
# Add the $lte criterion to the selector.
|
197
198
|
#
|
198
199
|
# @example Add the $lte criterion.
|
199
|
-
#
|
200
|
+
# selectable.lte(age: 60)
|
200
201
|
#
|
201
202
|
# @example Execute an $lte in a where query.
|
202
|
-
#
|
203
|
+
# selectable.where(:field.lte => 10)
|
203
204
|
#
|
204
205
|
# @param [ Hash ] criterion The field/value pairs to check.
|
205
206
|
#
|
206
|
-
# @return [ Selectable ] The cloned
|
207
|
+
# @return [ Selectable ] The cloned selectable.
|
207
208
|
#
|
208
209
|
# @since 1.0.0
|
209
210
|
def lte(criterion = nil)
|
@@ -211,31 +212,31 @@ module Origin
|
|
211
212
|
end
|
212
213
|
key :lte, :override, "$lte"
|
213
214
|
|
214
|
-
# Add a $maxDistance selection to the
|
215
|
+
# Add a $maxDistance selection to the selectable.
|
215
216
|
#
|
216
217
|
# @example Add the $maxDistance selection.
|
217
|
-
#
|
218
|
+
# selectable.max_distance(location: 10)
|
218
219
|
#
|
219
220
|
# @param [ Hash ] criterion The field/distance pairs.
|
220
221
|
#
|
221
|
-
# @return [ Selectable ] The cloned
|
222
|
+
# @return [ Selectable ] The cloned selectable.
|
222
223
|
#
|
223
224
|
# @since 1.0.0
|
224
225
|
def max_distance(criterion = nil)
|
225
226
|
__add__(criterion, "$maxDistance")
|
226
227
|
end
|
227
228
|
|
228
|
-
# Adds $mod selection to the
|
229
|
+
# Adds $mod selection to the selectable.
|
229
230
|
#
|
230
231
|
# @example Add the $mod selection.
|
231
|
-
#
|
232
|
+
# selectable.mod(field: [ 10, 1 ])
|
232
233
|
#
|
233
234
|
# @example Execute an $mod in a where query.
|
234
|
-
#
|
235
|
+
# selectable.where(:field.mod => [ 10, 1 ])
|
235
236
|
#
|
236
237
|
# @param [ Hash ] criterion The field/mod selections.
|
237
238
|
#
|
238
|
-
# @return [ Selectable ] The cloned
|
239
|
+
# @return [ Selectable ] The cloned selectable.
|
239
240
|
#
|
240
241
|
# @since 1.0.0
|
241
242
|
def mod(criterion = nil)
|
@@ -243,17 +244,17 @@ module Origin
|
|
243
244
|
end
|
244
245
|
key :mod, :override, "$mod"
|
245
246
|
|
246
|
-
# Adds $ne selection to the
|
247
|
+
# Adds $ne selection to the selectable.
|
247
248
|
#
|
248
249
|
# @example Query for a value $ne to something.
|
249
|
-
#
|
250
|
+
# selectable.ne(field: 10)
|
250
251
|
#
|
251
252
|
# @example Execute an $ne in a where query.
|
252
|
-
#
|
253
|
+
# selectable.where(:field.ne => "value")
|
253
254
|
#
|
254
255
|
# @param [ Hash ] criterion The field/ne selections.
|
255
256
|
#
|
256
|
-
# @return [ Selectable ] The cloned
|
257
|
+
# @return [ Selectable ] The cloned selectable.
|
257
258
|
#
|
258
259
|
# @since 1.0.0
|
259
260
|
def ne(criterion = nil)
|
@@ -265,14 +266,14 @@ module Origin
|
|
265
266
|
# Adds a $near criterion to a geo selection.
|
266
267
|
#
|
267
268
|
# @example Add the $near selection.
|
268
|
-
#
|
269
|
+
# selectable.near(location: [ 23.1, 12.1 ])
|
269
270
|
#
|
270
271
|
# @example Execute an $near in a where query.
|
271
|
-
#
|
272
|
+
# selectable.where(:field.near => [ 23.2, 12.1 ])
|
272
273
|
#
|
273
274
|
# @param [ Hash ] criterion The field/location pair.
|
274
275
|
#
|
275
|
-
# @return [ Selectable ] The cloned
|
276
|
+
# @return [ Selectable ] The cloned selectable.
|
276
277
|
#
|
277
278
|
# @since 1.0.0
|
278
279
|
def near(criterion = nil)
|
@@ -283,14 +284,14 @@ module Origin
|
|
283
284
|
# Adds a $nearSphere criterion to a geo selection.
|
284
285
|
#
|
285
286
|
# @example Add the $nearSphere selection.
|
286
|
-
#
|
287
|
+
# selectable.near_sphere(location: [ 23.1, 12.1 ])
|
287
288
|
#
|
288
289
|
# @example Execute an $nearSphere in a where query.
|
289
|
-
#
|
290
|
+
# selectable.where(:field.near_sphere => [ 10.11, 3.22 ])
|
290
291
|
#
|
291
292
|
# @param [ Hash ] criterion The field/location pair.
|
292
293
|
#
|
293
|
-
# @return [ Selectable ] The cloned
|
294
|
+
# @return [ Selectable ] The cloned selectable.
|
294
295
|
#
|
295
296
|
# @since 1.0.0
|
296
297
|
def near_sphere(criterion = nil)
|
@@ -298,20 +299,20 @@ module Origin
|
|
298
299
|
end
|
299
300
|
key :near_sphere, :override, "$nearSphere"
|
300
301
|
|
301
|
-
# Adds the $nin selection to the
|
302
|
+
# Adds the $nin selection to the selectable.
|
302
303
|
#
|
303
304
|
# @example Add $nin selection on an array.
|
304
|
-
#
|
305
|
+
# selectable.nin(age: [ 1, 2, 3 ])
|
305
306
|
#
|
306
307
|
# @example Add $nin selection on a range.
|
307
|
-
#
|
308
|
+
# selectable.nin(age: 18..24)
|
308
309
|
#
|
309
310
|
# @example Execute an $nin in a where query.
|
310
|
-
#
|
311
|
+
# selectable.where(:field.nin => [ 1, 2, 3 ])
|
311
312
|
#
|
312
313
|
# @param [ Hash ] criterion The field/value criterion pairs.
|
313
314
|
#
|
314
|
-
# @return [ Selectable ] The cloned
|
315
|
+
# @return [ Selectable ] The cloned selectable.
|
315
316
|
#
|
316
317
|
# @since 1.0.0
|
317
318
|
def nin(criterion = nil)
|
@@ -320,28 +321,52 @@ module Origin
|
|
320
321
|
alias :not_in :nin
|
321
322
|
key :nin, :intersect, "$nin"
|
322
323
|
|
323
|
-
# Adds $nor selection to the
|
324
|
+
# Adds $nor selection to the selectable.
|
324
325
|
#
|
325
326
|
# @example Add the $nor selection.
|
326
|
-
#
|
327
|
+
# selectable.nor(field: 1, field: 2)
|
327
328
|
#
|
328
329
|
# @param [ Array ] criterion An array of hash criterion.
|
329
330
|
#
|
330
|
-
# @return [ Selectable ] The cloned
|
331
|
+
# @return [ Selectable ] The cloned selectable.
|
331
332
|
#
|
332
333
|
# @since 1.0.0
|
333
334
|
def nor(*criterion)
|
334
335
|
__multi__(criterion, "$nor")
|
335
336
|
end
|
336
337
|
|
337
|
-
#
|
338
|
+
# Is the current selectable negating the next selection?
|
339
|
+
#
|
340
|
+
# @example Is the selectable negating?
|
341
|
+
# selectable.negating?
|
342
|
+
#
|
343
|
+
# @return [ true, false ] If the selectable is negating.
|
344
|
+
#
|
345
|
+
# @since 1.0.0
|
346
|
+
def negating?
|
347
|
+
!!negating
|
348
|
+
end
|
349
|
+
|
350
|
+
# Negate the next selection.
|
351
|
+
#
|
352
|
+
# @example Negate the selection.
|
353
|
+
# selectable.not.in(field: [ 1, 2 ])
|
354
|
+
#
|
355
|
+
# @return [ Selectable ] The negated selectable.
|
356
|
+
#
|
357
|
+
# @since 1.0.0
|
358
|
+
def not
|
359
|
+
tap { |query| query.negating = true }
|
360
|
+
end
|
361
|
+
|
362
|
+
# Adds $or selection to the selectable.
|
338
363
|
#
|
339
364
|
# @example Add the $or selection.
|
340
|
-
#
|
365
|
+
# selectable.or(field: 1, field: 2)
|
341
366
|
#
|
342
367
|
# @param [ Array ] criterion An array of hash criterion.
|
343
368
|
#
|
344
|
-
# @return [ Selectable ] The cloned
|
369
|
+
# @return [ Selectable ] The cloned selectable.
|
345
370
|
#
|
346
371
|
# @since 1.0.0
|
347
372
|
def or(*criterion)
|
@@ -352,17 +377,17 @@ module Origin
|
|
352
377
|
# Add a $size selection for array fields.
|
353
378
|
#
|
354
379
|
# @example Add the $size selection.
|
355
|
-
#
|
380
|
+
# selectable.with_size(field: 5)
|
356
381
|
#
|
357
382
|
# @note This method is named #with_size not to conflict with any existing
|
358
383
|
# #size method on enumerables or symbols.
|
359
384
|
#
|
360
385
|
# @example Execute an $size in a where query.
|
361
|
-
#
|
386
|
+
# selectable.where(:field.with_size => 10)
|
362
387
|
#
|
363
388
|
# @param [ Hash ] criterion The field/size pairs criterion.
|
364
389
|
#
|
365
|
-
# @return [ Selectable ] The cloned
|
390
|
+
# @return [ Selectable ] The cloned selectable.
|
366
391
|
#
|
367
392
|
# @since 1.0.0
|
368
393
|
def with_size(criterion = nil)
|
@@ -374,19 +399,19 @@ module Origin
|
|
374
399
|
::Integer.evolve(value)
|
375
400
|
end
|
376
401
|
|
377
|
-
# Adds a $type selection to the
|
402
|
+
# Adds a $type selection to the selectable.
|
378
403
|
#
|
379
404
|
# @example Add the $type selection.
|
380
|
-
#
|
405
|
+
# selectable.with_type(field: 15)
|
381
406
|
#
|
382
407
|
# @example Execute an $type in a where query.
|
383
|
-
#
|
408
|
+
# selectable.where(:field.with_type => 15)
|
384
409
|
#
|
385
410
|
# @note http://vurl.me/PGOU contains a list of all types.
|
386
411
|
#
|
387
412
|
# @param [ Hash ] criterion The field/type pairs.
|
388
413
|
#
|
389
|
-
# @return [ Selectable ] The cloned
|
414
|
+
# @return [ Selectable ] The cloned selectable.
|
390
415
|
#
|
391
416
|
# @since 1.0.0
|
392
417
|
def with_type(criterion = nil)
|
@@ -403,31 +428,31 @@ module Origin
|
|
403
428
|
# the use of hash methods, or a $where selection if a string is provided.
|
404
429
|
#
|
405
430
|
# @example Add a standard selection.
|
406
|
-
#
|
431
|
+
# selectable.where(name: "syd")
|
407
432
|
#
|
408
433
|
# @example Add a javascript selection.
|
409
|
-
#
|
434
|
+
# selectable.where("this.name == 'syd'")
|
410
435
|
#
|
411
436
|
# @param [ String, Hash ] criterion The javascript or standard selection.
|
412
437
|
#
|
413
|
-
# @return [ Selectable ] The cloned
|
438
|
+
# @return [ Selectable ] The cloned selectable.
|
414
439
|
#
|
415
440
|
# @since 1.0.0
|
416
441
|
def where(criterion = nil)
|
417
442
|
criterion.is_a?(String) ? js_query(criterion) : expr_query(criterion)
|
418
443
|
end
|
419
444
|
|
420
|
-
# Adds the $within/$box selection to the
|
445
|
+
# Adds the $within/$box selection to the selectable.
|
421
446
|
#
|
422
447
|
# @example Add the selection.
|
423
|
-
#
|
448
|
+
# selectable.within_box(location: [[ 1, 10 ], [ 10, 1 ]])
|
424
449
|
#
|
425
450
|
# @example Execute an $within/$box in a where query.
|
426
|
-
#
|
451
|
+
# selectable.where(:field.within_box => [[ 1, 10 ], [ 10, 1 ]])
|
427
452
|
#
|
428
453
|
# @param [ Hash ] criterion The field/box corner criterion.
|
429
454
|
#
|
430
|
-
# @return [ Selectable ] The cloned
|
455
|
+
# @return [ Selectable ] The cloned selectable.
|
431
456
|
#
|
432
457
|
# @since 1.0.0
|
433
458
|
def within_box(criterion = nil)
|
@@ -435,17 +460,17 @@ module Origin
|
|
435
460
|
end
|
436
461
|
key :within_box, :expanded, "$within", "$box"
|
437
462
|
|
438
|
-
# Adds the $within/$center selection to the
|
463
|
+
# Adds the $within/$center selection to the selectable.
|
439
464
|
#
|
440
465
|
# @example Add the selection.
|
441
|
-
#
|
466
|
+
# selectable.within_circle(location: [[ 1, 10 ], 25 ])
|
442
467
|
#
|
443
468
|
# @example Execute an $within/$center in a where query.
|
444
|
-
#
|
469
|
+
# selectable.where(:field.within_circle => [[ 1, 10 ], 25 ])
|
445
470
|
#
|
446
471
|
# @param [ Hash ] criterion The field/radius criterion.
|
447
472
|
#
|
448
|
-
# @return [ Selectable ] The cloned
|
473
|
+
# @return [ Selectable ] The cloned selectable.
|
449
474
|
#
|
450
475
|
# @since 1.0.0
|
451
476
|
def within_circle(criterion = nil)
|
@@ -453,21 +478,21 @@ module Origin
|
|
453
478
|
end
|
454
479
|
key :within_circle, :expanded, "$within", "$center"
|
455
480
|
|
456
|
-
# Adds the $within/$polygon selection to the
|
481
|
+
# Adds the $within/$polygon selection to the selectable.
|
457
482
|
#
|
458
483
|
# @example Add the selection.
|
459
|
-
#
|
484
|
+
# selectable.within_polygon(
|
460
485
|
# location: [[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]
|
461
486
|
# )
|
462
487
|
#
|
463
488
|
# @example Execute an $within/$polygon in a where query.
|
464
|
-
#
|
489
|
+
# selectable.where(
|
465
490
|
# :field.within_polygon => [[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]
|
466
491
|
# )
|
467
492
|
#
|
468
493
|
# @param [ Hash ] criterion The field/polygon points criterion.
|
469
494
|
#
|
470
|
-
# @return [ Selectable ] The cloned
|
495
|
+
# @return [ Selectable ] The cloned selectable.
|
471
496
|
#
|
472
497
|
# @since 1.0.0
|
473
498
|
def within_polygon(criterion = nil)
|
@@ -475,17 +500,17 @@ module Origin
|
|
475
500
|
end
|
476
501
|
key :within_polygon, :expanded, "$within", "$polygon"
|
477
502
|
|
478
|
-
# Adds the $within/$centerSphere selection to the
|
503
|
+
# Adds the $within/$centerSphere selection to the selectable.
|
479
504
|
#
|
480
505
|
# @example Add the selection.
|
481
|
-
#
|
506
|
+
# selectable.within_spherical_circle(location: [[ 1, 10 ], 25 ])
|
482
507
|
#
|
483
508
|
# @example Execute an $within/$centerSphere in a where query.
|
484
|
-
#
|
509
|
+
# selectable.where(:field.within_spherical_circle => [[ 1, 10 ], 25 ])
|
485
510
|
#
|
486
511
|
# @param [ Hash ] criterion The field/distance criterion.
|
487
512
|
#
|
488
|
-
# @return [ Selectable ] The cloned
|
513
|
+
# @return [ Selectable ] The cloned selectable.
|
489
514
|
#
|
490
515
|
# @since 1.0.0
|
491
516
|
def within_spherical_circle(criterion = nil)
|
@@ -500,16 +525,16 @@ module Origin
|
|
500
525
|
# @api private
|
501
526
|
#
|
502
527
|
# @example Create the selection.
|
503
|
-
#
|
528
|
+
# selectable.expr_query(age: 50)
|
504
529
|
#
|
505
530
|
# @param [ Hash ] criterion The field/value pairs.
|
506
531
|
#
|
507
|
-
# @return [ Selectable ] The cloned
|
532
|
+
# @return [ Selectable ] The cloned selectable.
|
508
533
|
#
|
509
534
|
# @since 1.0.0
|
510
535
|
def expr_query(criterion)
|
511
536
|
selection(criterion) do |selector, field, value|
|
512
|
-
selector.merge!(field.specify(value))
|
537
|
+
selector.merge!(field.specify(value, negating?))
|
513
538
|
end
|
514
539
|
end
|
515
540
|
|
@@ -518,7 +543,7 @@ module Origin
|
|
518
543
|
# @api private
|
519
544
|
#
|
520
545
|
# @example Force values to booleans.
|
521
|
-
#
|
546
|
+
# selectable.force_typing(criterion) do |val|
|
522
547
|
# Boolean.evolve(val)
|
523
548
|
# end
|
524
549
|
#
|
@@ -539,11 +564,11 @@ module Origin
|
|
539
564
|
# @api private
|
540
565
|
#
|
541
566
|
# @example Create the javascript selection.
|
542
|
-
#
|
567
|
+
# selectable.js_query("this.age == 50")
|
543
568
|
#
|
544
569
|
# @param [ String ] criterion The javascript as a string.
|
545
570
|
#
|
546
|
-
# @return [ Selectable ] The cloned
|
571
|
+
# @return [ Selectable ] The cloned selectable
|
547
572
|
#
|
548
573
|
# @since 1.0.0
|
549
574
|
def js_query(criterion)
|
@@ -562,7 +587,7 @@ module Origin
|
|
562
587
|
#
|
563
588
|
# @param [ Hash ] criterion The selection to store.
|
564
589
|
#
|
565
|
-
# @return [ Selectable ] The cloned
|
590
|
+
# @return [ Selectable ] The cloned selectable.
|
566
591
|
#
|
567
592
|
# @since 1.0.0
|
568
593
|
def selection(criterion = nil)
|
@@ -572,6 +597,7 @@ module Origin
|
|
572
597
|
yield(query.selector, field.is_a?(Key) ? field : field.to_s, value)
|
573
598
|
end
|
574
599
|
end
|
600
|
+
query.reset_strategies!
|
575
601
|
end
|
576
602
|
end
|
577
603
|
|
@@ -581,7 +607,7 @@ module Origin
|
|
581
607
|
# @api private
|
582
608
|
#
|
583
609
|
# @example Convert all the values to arrays.
|
584
|
-
#
|
610
|
+
# selectable.with_array_values({ key: 1...4 })
|
585
611
|
#
|
586
612
|
# @param [ Hash ] criterion The criterion.
|
587
613
|
#
|
@@ -606,7 +632,8 @@ module Origin
|
|
606
632
|
#
|
607
633
|
# @since 1.0.0
|
608
634
|
def forwardables
|
609
|
-
public_instance_methods(false) -
|
635
|
+
public_instance_methods(false) -
|
636
|
+
[ :negating, :negating=, :negating?, :selector, :selector= ]
|
610
637
|
end
|
611
638
|
end
|
612
639
|
end
|
data/lib/origin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta
|
5
5
|
prerelease: 6
|
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: 2012-04-
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
segments:
|
144
144
|
- 0
|
145
|
-
hash:
|
145
|
+
hash: -293711780185043147
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
none: false
|
148
148
|
requirements:
|