Module: Origin::Selectable
- Extended by:
- Macroable
- Includes:
- Mergeable
- Included in:
- Queryable
- Defined in:
- lib/origin/selectable.rb
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.
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
Attributes included from Mergeable
#strategy, #strategy The name of the current strategy.
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.
-
#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.
-
#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.
-
#within_box(criterion = nil) ⇒ Selectable
Adds the $within/$box selection to the selectable.
-
#within_circle(criterion = nil) ⇒ Selectable
Adds the $within/$center selection to the selectable.
-
#within_polygon(criterion = nil) ⇒ Selectable
Adds the $within/$polygon selection to the selectable.
-
#within_spherical_circle(criterion = nil) ⇒ Selectable
Adds the $within/$centerSphere selection to the selectable.
Methods included from Macroable
Methods included from Mergeable
#intersect, #override, #reset_strategies!, #union
Instance Attribute Details
#negating ⇒ Object
Returns the value of attribute negating.
13 14 15 |
# File 'lib/origin/selectable.rb', line 13 def negating @negating end |
#negating If the next spression is negated.(Ifthe) ⇒ Object
13 |
# File 'lib/origin/selectable.rb', line 13 attr_accessor :negating, :selector |
#selector ⇒ Object
Returns the value of attribute selector.
13 14 15 |
# File 'lib/origin/selectable.rb', line 13 def selector @selector end |
#selector The query selector.(Thequeryselector.) ⇒ Object
13 |
# File 'lib/origin/selectable.rb', line 13 attr_accessor :negating, :selector |
Class Method Details
.forwardables ⇒ Array<Symbol>
Get the methods on the selectable that can be forwarded to from a model.
643 644 645 646 |
# File 'lib/origin/selectable.rb', line 643 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.
28 29 30 |
# File 'lib/origin/selectable.rb', line 28 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.
45 46 47 |
# File 'lib/origin/selectable.rb', line 45 def and(*criterion) __multi__(criterion, "$and") end |
#between(criterion = nil) ⇒ Selectable
Add the range selection.
63 64 65 66 67 68 69 70 |
# File 'lib/origin/selectable.rb', line 63 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.
91 92 93 |
# File 'lib/origin/selectable.rb', line 91 def elem_match(criterion = nil) __override__(criterion, "$elemMatch") end |
#exists(criterion = nil) ⇒ Selectable
Add the $exists selection.
112 113 114 115 116 |
# File 'lib/origin/selectable.rb', line 112 def exists(criterion = nil) typed_override(criterion, "$exists") do |value| ::Boolean.evolve(value) end end |
#gt(criterion = nil) ⇒ Selectable
Add the $gt criterion to the selector.
134 135 136 |
# File 'lib/origin/selectable.rb', line 134 def gt(criterion = nil) __override__(criterion, "$gt") end |
#gte(criterion = nil) ⇒ Selectable
Add the $gte criterion to the selector.
152 153 154 |
# File 'lib/origin/selectable.rb', line 152 def gte(criterion = nil) __override__(criterion, "$gte") end |
#in(criterion = nil) ⇒ Selectable Also known as: any_in
Adds the $in selection to the selectable.
173 174 175 |
# File 'lib/origin/selectable.rb', line 173 def in(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$in") end |
#lt(criterion = nil) ⇒ Selectable
Add the $lt criterion to the selector.
192 193 194 |
# File 'lib/origin/selectable.rb', line 192 def lt(criterion = nil) __override__(criterion, "$lt") end |
#lte(criterion = nil) ⇒ Selectable
Add the $lte criterion to the selector.
210 211 212 |
# File 'lib/origin/selectable.rb', line 210 def lte(criterion = nil) __override__(criterion, "$lte") end |
#max_distance(criterion = nil) ⇒ Selectable
Add a $maxDistance selection to the selectable.
225 226 227 |
# File 'lib/origin/selectable.rb', line 225 def max_distance(criterion = nil) __add__(criterion, "$maxDistance") end |
#mod(criterion = nil) ⇒ Selectable
Adds $mod selection to the selectable.
242 243 244 |
# File 'lib/origin/selectable.rb', line 242 def mod(criterion = nil) __override__(criterion, "$mod") end |
#ne(criterion = nil) ⇒ Selectable Also known as: excludes
Adds $ne selection to the selectable.
260 261 262 |
# File 'lib/origin/selectable.rb', line 260 def ne(criterion = nil) __override__(criterion, "$ne") end |
#near(criterion = nil) ⇒ Selectable
Adds a $near criterion to a geo selection.
279 280 281 |
# File 'lib/origin/selectable.rb', line 279 def near(criterion = nil) __override__(criterion, "$near") end |
#near_sphere(criterion = nil) ⇒ Selectable
Adds a $nearSphere criterion to a geo selection.
297 298 299 |
# File 'lib/origin/selectable.rb', line 297 def near_sphere(criterion = nil) __override__(criterion, "$nearSphere") end |
#negating? ⇒ true, false
Is the current selectable negating the next selection?
346 347 348 |
# File 'lib/origin/selectable.rb', line 346 def negating? !!negating end |
#nin(criterion = nil) ⇒ Selectable Also known as: not_in
Adds the $nin selection to the selectable.
318 319 320 |
# File 'lib/origin/selectable.rb', line 318 def nin(criterion = nil) send(strategy || :__intersect__, with_array_values(criterion), "$nin") end |
#nor(*criterion) ⇒ Selectable
Adds $nor selection to the selectable.
334 335 336 |
# File 'lib/origin/selectable.rb', line 334 def nor(*criterion) __multi__(criterion, "$nor") end |
#not(*criterion) ⇒ Selectable
Negate the next selection.
366 367 368 |
# File 'lib/origin/selectable.rb', line 366 def not(*criterion) (criterion.size == 0) ? tap { |query| query.negating = true } : __override__(criterion.first, "$not") end |
#or(*criterion) ⇒ Selectable Also known as: any_of
Adds $or selection to the selectable.
381 382 383 |
# File 'lib/origin/selectable.rb', line 381 def or(*criterion) __multi__(criterion, "$or") 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.
450 451 452 |
# File 'lib/origin/selectable.rb', line 450 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.
402 403 404 405 406 |
# File 'lib/origin/selectable.rb', line 402 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.
426 427 428 429 430 |
# File 'lib/origin/selectable.rb', line 426 def with_type(criterion = nil) typed_override(criterion, "$type") do |value| ::Integer.evolve(value) end end |
#within_box(criterion = nil) ⇒ Selectable
Adds the $within/$box selection to the selectable.
467 468 469 |
# File 'lib/origin/selectable.rb', line 467 def within_box(criterion = nil) (criterion, "$within", "$box") end |
#within_circle(criterion = nil) ⇒ Selectable
Adds the $within/$center selection to the selectable.
485 486 487 |
# File 'lib/origin/selectable.rb', line 485 def within_circle(criterion = nil) (criterion, "$within", "$center") end |
#within_polygon(criterion = nil) ⇒ Selectable
Adds the $within/$polygon selection to the selectable.
507 508 509 |
# File 'lib/origin/selectable.rb', line 507 def within_polygon(criterion = nil) (criterion, "$within", "$polygon") end |
#within_spherical_circle(criterion = nil) ⇒ Selectable
Adds the $within/$centerSphere selection to the selectable.
525 526 527 |
# File 'lib/origin/selectable.rb', line 525 def within_spherical_circle(criterion = nil) (criterion, "$within", "$centerSphere") end |