Class: Mongoid::Criteria::Queryable::Options
- Defined in:
- lib/mongoid/criteria/queryable/options.rb
Overview
The options is a hash representation of options passed to MongoDB queries, such as skip, limit, and sorting criteria.
Instance Attribute Summary
Attributes inherited from Smash
#aliased_associations, #aliased_associations The aliased_associations., #aliases, #aliases The aliases., #associations, #associations The associations., #serializers, #serializers The serializers.
Instance Method Summary collapse
-
#__deep_copy__ ⇒ Options
Perform a deep copy of the options.
-
#fields ⇒ Hash
Convenience method for getting the field options.
-
#limit ⇒ Integer
Convenience method for getting the limit option.
-
#skip ⇒ Integer
Convenience method for getting the skip option.
-
#sort ⇒ Hash
Convenience method for getting the sort options.
-
#store(key, value, localize = true) ⇒ Object
(also: #[]=)
Store the value in the options for the provided key.
-
#to_pipeline ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.
-
#to_pipeline_for_lookup ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.
Methods inherited from Smash
Constructor Details
This class inherits a constructor from Mongoid::Criteria::Queryable::Smash
Instance Method Details
#__deep_copy__ ⇒ Options
Perform a deep copy of the options.
99 100 101 102 103 104 105 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 99 def __deep_copy__ self.class.new(aliases, serializers, associations, aliased_associations) do |copy| each_pair do |key, value| copy.merge!(key => value.__deep_copy__) end end end |
#fields ⇒ Hash
Convenience method for getting the field options.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 15 def fields self[:fields] end |
#limit ⇒ Integer
Convenience method for getting the limit option.
25 26 27 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 25 def limit self[:limit] end |
#skip ⇒ Integer
Convenience method for getting the skip option.
35 36 37 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 35 def skip self[:skip] end |
#sort ⇒ Hash
Convenience method for getting the sort options.
45 46 47 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 45 def sort self[:sort] end |
#store(key, value, localize = true) ⇒ Object Also known as: []=
Store the value in the options for the provided key. The options will handle all necessary serialization and localization in this step.
59 60 61 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 59 def store(key, value, localize = true) super(key, evolve(value, localize)) end |
#to_pipeline ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.
70 71 72 73 74 75 76 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 70 def to_pipeline pipeline = [] pipeline.push({ '$skip' => skip }) if skip pipeline.push({ '$limit' => limit }) if limit pipeline.push({ '$sort' => sort }) if sort pipeline end |
#to_pipeline_for_lookup ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options. This version places sort last to comply with $lookup requirements.
85 86 87 88 89 90 91 |
# File 'lib/mongoid/criteria/queryable/options.rb', line 85 def to_pipeline_for_lookup pipeline = [] pipeline.push({ '$sort' => sort }) if sort pipeline.push({ '$skip' => skip }) if skip pipeline.push({ '$limit' => limit }) if limit pipeline end |