Module: Mongoid::Criteria::Queryable::Selectable
- Extended by:
- Macroable
- Defined in:
- lib/mongoid/criteria/queryable/selectable.rb
Overview
An queryable 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 expression 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.
29 30 31 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 29 def negating @negating end |
#negating If the next expression is negated.(Ifthe) ⇒ Object
29 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 29 attr_accessor :negating, :selector |
#selector ⇒ Object
Returns the value of attribute selector.
29 30 31 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 29 def selector @selector end |
#selector The query selector.(Thequeryselector.) ⇒ Object
29 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 29 attr_accessor :negating, :selector |
Class Method Details
.forwardables ⇒ Array<Symbol>
Get the methods on the selectable that can be forwarded to from a model.
654 655 656 657 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 654 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.
44 45 46 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 44 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.
61 62 63 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 61 def and(*criterion) __multi__(criterion, "$and") end |
#between(criterion = nil) ⇒ Selectable
Add the range selection.
79 80 81 82 83 84 85 86 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 79 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.
107 108 109 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 107 def elem_match(criterion = nil) __override__(criterion, "$elemMatch") end |
#exists(criterion = nil) ⇒ Selectable
Add the $exists selection.
128 129 130 131 132 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 128 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.
162 163 164 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 162 def geo_spacial(criterion = nil) __merge__(criterion) end |
#gt(criterion = nil) ⇒ Selectable
Add the $gt criterion to the selector.
191 192 193 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 191 def gt(criterion = nil) __override__(criterion, "$gt") end |
#gte(criterion = nil) ⇒ Selectable
Add the $gte criterion to the selector.
209 210 211 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 209 def gte(criterion = nil) __override__(criterion, "$gte") end |
#in(criterion = nil) ⇒ Selectable Also known as: any_in
Adds the $in selection to the selectable.
230 231 232 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 230 def in(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$in") end |
#lt(criterion = nil) ⇒ Selectable
Add the $lt criterion to the selector.
249 250 251 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 249 def lt(criterion = nil) __override__(criterion, "$lt") end |
#lte(criterion = nil) ⇒ Selectable
Add the $lte criterion to the selector.
267 268 269 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 267 def lte(criterion = nil) __override__(criterion, "$lte") end |
#max_distance(criterion = nil) ⇒ Selectable
Add a $maxDistance selection to the selectable.
282 283 284 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 282 def max_distance(criterion = nil) __add__(criterion, "$maxDistance") end |
#mod(criterion = nil) ⇒ Selectable
Adds $mod selection to the selectable.
299 300 301 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 299 def mod(criterion = nil) __override__(criterion, "$mod") end |
#ne(criterion = nil) ⇒ Selectable Also known as: excludes
Adds $ne selection to the selectable.
317 318 319 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 317 def ne(criterion = nil) __override__(criterion, "$ne") end |
#near(criterion = nil) ⇒ Selectable
Adds a $near criterion to a geo selection.
336 337 338 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 336 def near(criterion = nil) __override__(criterion, "$near") end |
#near_sphere(criterion = nil) ⇒ Selectable
Adds a $nearSphere criterion to a geo selection.
354 355 356 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 354 def near_sphere(criterion = nil) __override__(criterion, "$nearSphere") end |
#negating? ⇒ true, false
Is the current selectable negating the next selection?
403 404 405 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 403 def negating? !!negating end |
#nin(criterion = nil) ⇒ Selectable Also known as: not_in
Adds the $nin selection to the selectable.
375 376 377 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 375 def nin(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$nin") end |
#nor(*criterion) ⇒ Selectable
Adds $nor selection to the selectable.
391 392 393 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 391 def nor(*criterion) __multi__(criterion, "$nor") end |
#not(*criterion) ⇒ Selectable
Negate the next selection.
423 424 425 426 427 428 429 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 423 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.
442 443 444 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 442 def or(*criterion) __multi__(criterion, "$or") end |
#text_search(terms, opts = nil) ⇒ Selectable
Construct a text search selector.
512 513 514 515 516 517 518 519 520 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 512 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.
537 538 539 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 537 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.
463 464 465 466 467 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 463 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.
487 488 489 490 491 |
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 487 def with_type(criterion = nil) typed_override(criterion, "$type") do |value| ::Integer.evolve(value) end end |