Class: Mongoid::Criteria::Queryable::Options
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Mongoid::Criteria::Queryable::Smash
|
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.
Class Attribute Summary
::Mongoid::Extensions::Hash::ClassMethods
- Extended
resizable? | Can the size of this object change? |
Class Method Summary
Smash
- Inherited
.new | Initialize the new selector. |
::Mongoid::Extensions::Hash::ClassMethods
- Extended
mongoize | Turn the object from the ruby type we deal with to a Mongo friendly type. |
Instance Attribute Summary
Smash
- Inherited
#aliased_associations, #aliased_associations The aliased_associations., #aliases, #aliases The aliases., #associations, #associations The associations., #serializers, #serializers The serializers. |
::Mongoid::Extensions::Hash
- Included
#resizable? | Can the size of this object change? |
Instance Method Summary
-
#[]=(key, value, localize = true)
Alias for #store.
-
#__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.
-
#evolve(value, localize = true) ⇒ Object
private
Internal use only
Internal use only
Evolve a single key selection with various types of values.
-
#evolve_hash(value, localize = true) ⇒ Object
private
Internal use only
Internal use only
Evolve a single key selection with hash values.
Smash
- Inherited
#[] | Get an item from the smart hash by the provided key. |
#__deep_copy__ | Perform a deep copy of the smash. |
#get_serializer | Retrieves the serializer for the given name. |
#localized_key | Get the localized value for the key if needed. |
#storage_pair | Get the pair of objects needed to store the value in a hash by the provided key. |
::Mongoid::Extensions::Hash
- Included
#__consolidate__ | Consolidate the key/values in the hash under an atomic $set. |
#__evolve_object_id__ | Evolves each value in the hash to an object id if it is convertable. |
#__mongoize_object_id__ | Mongoizes each value in the hash to an object id if it is convertable. |
#delete_id | Deletes an id value from the hash. |
#extract_id | Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol. |
#mongoize | Turn the object from the ruby type we deal with to a Mongo friendly type. |
#to_criteria | Convert this hash to a criteria. |
Constructor Details
This class inherits a constructor from Mongoid::Criteria::Queryable::Smash
Instance Method Details
#[]=(key, value, localize = true)
Alias for #store.
# File 'lib/mongoid/criteria/queryable/options.rb', line 65
alias :[]= :store
#__deep_copy__ ⇒ Options
Perform a deep copy of the options.
# File 'lib/mongoid/criteria/queryable/options.rb', line 87
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
#evolve(value, localize = true) ⇒ Object
(private)
Evolve a single key selection with various types of values.
# File 'lib/mongoid/criteria/queryable/options.rb', line 107
def evolve(value, localize = true) case value when Hash evolve_hash(value, localize) else value end end
#evolve_hash(value, localize = true) ⇒ Object
(private)
Evolve a single key selection with hash values.
# File 'lib/mongoid/criteria/queryable/options.rb', line 126
def evolve_hash(value, localize = true) value.inject({}) do |hash, (field, _value)| name, serializer = storage_pair(field) name = localized_key(name, serializer) if localize hash[name] = _value hash end end
#fields ⇒ Hash
Convenience method for getting the field options.
# File 'lib/mongoid/criteria/queryable/options.rb', line 18
def fields self[:fields] end
#limit ⇒ Integer
Convenience method for getting the limit option.
# File 'lib/mongoid/criteria/queryable/options.rb', line 28
def limit self[:limit] end
#skip ⇒ Integer
Convenience method for getting the skip option.
# File 'lib/mongoid/criteria/queryable/options.rb', line 38
def skip self[:skip] end
#sort ⇒ Hash
Convenience method for getting the sort options.
# File 'lib/mongoid/criteria/queryable/options.rb', line 48
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.
# File 'lib/mongoid/criteria/queryable/options.rb', line 62
def store(key, value, localize = true) super(key, evolve(value, localize)) end
#to_pipeline ⇒ Array<Hash>
Convert the options to aggregation pipeline friendly options.