Module: Origin::Selectable
Overview
An origin selectable is selectable, in that it has the ability to select document from the database. The selectable module brings all functionality to the selectable that has to do with building MongoDB selectors.
Constant Summary collapse
- LINE_STRING =
Constant for a LineString $geometry.
"LineString"
- POINT =
Constant for a Point $geometry.
"Point"
- POLYGON =
Constant for a Polygon $geometry.
"Polygon"
Instance Attribute Summary collapse
-
#negating ⇒ Object
Returns the value of attribute negating.
- #negating If the next spression is negated.(Ifthe) ⇒ Object
-
#selector ⇒ Object
Returns the value of attribute selector.
- #selector The query selector.(Thequeryselector.) ⇒ Object
Class Method Summary collapse
-
.forwardables ⇒ Array<Symbol>
Get the methods on the selectable that can be forwarded to from a model.
Instance Method Summary collapse
-
#all(criterion = nil) ⇒ Selectable
(also: #all_in)
Add the $all criterion.
-
#and(*criterion) ⇒ Selectable
(also: #all_of)
Add the $and criterion.
-
#between(criterion = nil) ⇒ Selectable
Add the range selection.
-
#elem_match(criterion = nil) ⇒ Selectable
Select with an $elemMatch.
-
#exists(criterion = nil) ⇒ Selectable
Add the $exists selection.
-
#geo_spacial(criterion = nil) ⇒ Selectable
Add a $geoIntersects or $geoWithin selection.
-
#gt(criterion = nil) ⇒ Selectable
Add the $gt criterion to the selector.
-
#gte(criterion = nil) ⇒ Selectable
Add the $gte criterion to the selector.
-
#in(criterion = nil) ⇒ Selectable
(also: #any_in)
Adds the $in selection to the selectable.
-
#lt(criterion = nil) ⇒ Selectable
Add the $lt criterion to the selector.
-
#lte(criterion = nil) ⇒ Selectable
Add the $lte criterion to the selector.
-
#max_distance(criterion = nil) ⇒ Selectable
Add a $maxDistance selection to the selectable.
-
#mod(criterion = nil) ⇒ Selectable
Adds $mod selection to the selectable.
-
#ne(criterion = nil) ⇒ Selectable
(also: #excludes)
Adds $ne selection to the selectable.
-
#near(criterion = nil) ⇒ Selectable
Adds a $near criterion to a geo selection.
-
#near_sphere(criterion = nil) ⇒ Selectable
Adds a $nearSphere criterion to a geo selection.
-
#negating? ⇒ true, false
Is the current selectable negating the next selection?.
-
#nin(criterion = nil) ⇒ Selectable
(also: #not_in)
Adds the $nin selection to the selectable.
-
#nor(*criterion) ⇒ Selectable
Adds $nor selection to the selectable.
-
#not(*criterion) ⇒ Selectable
Negate the next selection.
-
#or(*criterion) ⇒ Selectable
(also: #any_of)
Adds $or selection to the selectable.
-
#text_search(terms, opts = nil) ⇒ Selectable
Construct a text search selector.
-
#where(criterion = nil) ⇒ Selectable
This is the general entry point for most MongoDB queries.
-
#with_size(criterion = nil) ⇒ Selectable
Add a $size selection for array fields.
-
#with_type(criterion = nil) ⇒ Selectable
Adds a $type selection to the selectable.
Methods included from Macroable
Instance Attribute Details
#negating ⇒ Object
Returns the value of attribute negating.
27 28 29 |
# File 'lib/origin/selectable.rb', line 27 def negating @negating end |
#negating If the next spression is negated.(Ifthe) ⇒ Object
27 |
# File 'lib/origin/selectable.rb', line 27 attr_accessor :negating, :selector |
#selector ⇒ Object
Returns the value of attribute selector.
27 28 29 |
# File 'lib/origin/selectable.rb', line 27 def selector @selector end |
#selector The query selector.(Thequeryselector.) ⇒ Object
27 |
# File 'lib/origin/selectable.rb', line 27 attr_accessor :negating, :selector |
Class Method Details
.forwardables ⇒ Array<Symbol>
Get the methods on the selectable that can be forwarded to from a model.
652 653 654 655 |
# File 'lib/origin/selectable.rb', line 652 def forwardables public_instance_methods(false) - [ :negating, :negating=, :negating?, :selector, :selector= ] end |
Instance Method Details
#all(criterion = nil) ⇒ Selectable Also known as: all_in
Add the $all criterion.
42 43 44 |
# File 'lib/origin/selectable.rb', line 42 def all(criterion = nil) send(strategy || :__union__, with_array_values(criterion), "$all") end |
#and(*criterion) ⇒ Selectable Also known as: all_of
Add the $and criterion.
59 60 61 |
# File 'lib/origin/selectable.rb', line 59 def and(*criterion) __multi__(criterion, "$and") end |
#between(criterion = nil) ⇒ Selectable
Add the range selection.
77 78 79 80 81 82 83 84 |
# File 'lib/origin/selectable.rb', line 77 def between(criterion = nil) selection(criterion) do |selector, field, value| selector.store( field, { "$gte" => value.min, "$lte" => value.max } ) end end |
#elem_match(criterion = nil) ⇒ Selectable
Select with an $elemMatch.
105 106 107 |
# File 'lib/origin/selectable.rb', line 105 def elem_match(criterion = nil) __override__(criterion, "$elemMatch") end |
#exists(criterion = nil) ⇒ Selectable
Add the $exists selection.
126 127 128 129 130 |
# File 'lib/origin/selectable.rb', line 126 def exists(criterion = nil) typed_override(criterion, "$exists") do |value| ::Boolean.evolve(value) end end |
#geo_spacial(criterion = nil) ⇒ Selectable
The only valid geometry shapes for a $geoIntersects are: :intersects_line, :intersects_point, and :intersects_polygon.
The only valid geometry shape for a $geoWithin is :within_polygon
Add a $geoIntersects or $geoWithin selection. Symbol operators must be used as shown in the examples to expand the criteria.
160 161 162 |
# File 'lib/origin/selectable.rb', line 160 def geo_spacial(criterion = nil) __merge__(criterion) end |
#gt(criterion = nil) ⇒ Selectable
Add the $gt criterion to the selector.
189 190 191 |
# File 'lib/origin/selectable.rb', line 189 def gt(criterion = nil) __override__(criterion, "$gt") end |
#gte(criterion = nil) ⇒ Selectable
Add the $gte criterion to the selector.
207 208 209 |
# File 'lib/origin/selectable.rb', line 207 def gte(criterion = nil) __override__(criterion, "$gte") end |
#in(criterion = nil) ⇒ Selectable Also known as: any_in
Adds the $in selection to the selectable.
228 229 230 |
# File 'lib/origin/selectable.rb', line 228 def in(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$in") end |
#lt(criterion = nil) ⇒ Selectable
Add the $lt criterion to the selector.
247 248 249 |
# File 'lib/origin/selectable.rb', line 247 def lt(criterion = nil) __override__(criterion, "$lt") end |
#lte(criterion = nil) ⇒ Selectable
Add the $lte criterion to the selector.
265 266 267 |
# File 'lib/origin/selectable.rb', line 265 def lte(criterion = nil) __override__(criterion, "$lte") end |
#max_distance(criterion = nil) ⇒ Selectable
Add a $maxDistance selection to the selectable.
280 281 282 |
# File 'lib/origin/selectable.rb', line 280 def max_distance(criterion = nil) __add__(criterion, "$maxDistance") end |
#mod(criterion = nil) ⇒ Selectable
Adds $mod selection to the selectable.
297 298 299 |
# File 'lib/origin/selectable.rb', line 297 def mod(criterion = nil) __override__(criterion, "$mod") end |
#ne(criterion = nil) ⇒ Selectable Also known as: excludes
Adds $ne selection to the selectable.
315 316 317 |
# File 'lib/origin/selectable.rb', line 315 def ne(criterion = nil) __override__(criterion, "$ne") end |
#near(criterion = nil) ⇒ Selectable
Adds a $near criterion to a geo selection.
334 335 336 |
# File 'lib/origin/selectable.rb', line 334 def near(criterion = nil) __override__(criterion, "$near") end |
#near_sphere(criterion = nil) ⇒ Selectable
Adds a $nearSphere criterion to a geo selection.
352 353 354 |
# File 'lib/origin/selectable.rb', line 352 def near_sphere(criterion = nil) __override__(criterion, "$nearSphere") end |
#negating? ⇒ true, false
Is the current selectable negating the next selection?
401 402 403 |
# File 'lib/origin/selectable.rb', line 401 def negating? !!negating end |
#nin(criterion = nil) ⇒ Selectable Also known as: not_in
Adds the $nin selection to the selectable.
373 374 375 |
# File 'lib/origin/selectable.rb', line 373 def nin(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$nin") end |
#nor(*criterion) ⇒ Selectable
Adds $nor selection to the selectable.
389 390 391 |
# File 'lib/origin/selectable.rb', line 389 def nor(*criterion) __multi__(criterion, "$nor") end |
#not(*criterion) ⇒ Selectable
Negate the next selection.
421 422 423 424 425 426 427 |
# File 'lib/origin/selectable.rb', line 421 def not(*criterion) if criterion.empty? tap { |query| query.negating = true } else __override__(criterion.first, "$not") end end |
#or(*criterion) ⇒ Selectable Also known as: any_of
Adds $or selection to the selectable.
440 441 442 |
# File 'lib/origin/selectable.rb', line 440 def or(*criterion) __multi__(criterion, "$or") end |
#text_search(terms, opts = nil) ⇒ Selectable
Construct a text search selector.
510 511 512 513 514 515 516 517 518 |
# File 'lib/origin/selectable.rb', line 510 def text_search(terms, opts = nil) clone.tap do |query| if terms criterion = { :$text => { :$search => terms } } criterion[:$text].merge!(opts) if opts query.selector = criterion end end end |
#where(criterion = nil) ⇒ Selectable
This is the general entry point for most MongoDB queries. This either creates a standard field: value selection, and expanded selection with the use of hash methods, or a $where selection if a string is provided.
535 536 537 |
# File 'lib/origin/selectable.rb', line 535 def where(criterion = nil) criterion.is_a?(String) ? js_query(criterion) : expr_query(criterion) end |
#with_size(criterion = nil) ⇒ Selectable
This method is named #with_size not to conflict with any existing #size method on enumerables or symbols.
Add a $size selection for array fields.
461 462 463 464 465 |
# File 'lib/origin/selectable.rb', line 461 def with_size(criterion = nil) typed_override(criterion, "$size") do |value| ::Integer.evolve(value) end end |
#with_type(criterion = nil) ⇒ Selectable
vurl.me/PGOU contains a list of all types.
Adds a $type selection to the selectable.
485 486 487 488 489 |
# File 'lib/origin/selectable.rb', line 485 def with_type(criterion = nil) typed_override(criterion, "$type") do |value| ::Integer.evolve(value) end end |