Class: Origin::Options
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
#aliases, #aliases The aliases., #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) ⇒ Object
(also: #[]=)
Store the value in the options for the provided key.
-
#to_pipeline ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.
Methods inherited from Smash
Constructor Details
This class inherits a constructor from Origin::Smash
Instance Method Details
#__deep_copy__ ⇒ Options
Perform a deep copy of the options.
97 98 99 100 101 102 103 |
# File 'lib/origin/options.rb', line 97 def __deep_copy__ self.class.new(aliases, serializers) 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.
16 17 18 |
# File 'lib/origin/options.rb', line 16 def fields self[:fields] end |
#limit ⇒ Integer
Convenience method for getting the limit option.
28 29 30 |
# File 'lib/origin/options.rb', line 28 def limit self[:limit] end |
#skip ⇒ Integer
Convenience method for getting the skip option.
40 41 42 |
# File 'lib/origin/options.rb', line 40 def skip self[:skip] end |
#sort ⇒ Hash
Convenience method for getting the sort options.
52 53 54 |
# File 'lib/origin/options.rb', line 52 def sort self[:sort] end |
#store(key, value) ⇒ 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.
68 69 70 |
# File 'lib/origin/options.rb', line 68 def store(key, value) super(key, evolve(value)) end |
#to_pipeline ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.
81 82 83 84 85 86 87 |
# File 'lib/origin/options.rb', line 81 def to_pipeline pipeline = [] pipeline.push({ "$skip" => skip }) if skip pipeline.push({ "$limit" => limit }) if limit pipeline.push({ "$sort" => sort }) if sort pipeline end |