Class: Mongoid::Criteria::Queryable::Smash
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Hash
|
Defined in: | lib/mongoid/criteria/queryable/smash.rb |
Overview
This is a smart hash for use with options and selectors.
Class Attribute Summary
::Mongoid::Extensions::Hash::ClassMethods
- Extended
resizable? | Can the size of this object change? |
Class Method Summary
-
.new(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... } ⇒ Smash
constructor
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
- #aliased_associations readonly
- #aliased_associations The aliased_associations.(The aliased_associations.) readonly
- #aliases readonly
- #aliases The aliases.(The aliases.) readonly
- #associations readonly
- #associations The associations.(The associations.) readonly
- #serializers readonly
- #serializers The serializers.(The serializers.) readonly
::Mongoid::Extensions::Hash
- Included
#resizable? | Can the size of this object change? |
Instance Method Summary
-
#[](key) ⇒ Object
Get an item from the smart hash by the provided key.
-
#__deep_copy__ ⇒ Smash
Perform a deep copy of the smash.
-
#get_serializer(name) ⇒ Object
private
Retrieves the serializer for the given name.
-
#localized_key(name, serializer) ⇒ String
private
Internal use only
Internal use only
Get the localized value for the key if needed.
-
#storage_pair(key) ⇒ Array<String, Object>
private
Internal use only
Internal use only
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
.new(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... } ⇒ Smash
Initialize the new selector.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 52
def initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) @aliases = aliases @serializers = serializers @associations = associations @aliased_associations = aliased_associations yield(self) if block_given? end
Instance Attribute Details
#aliased_associations (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 21
attr_reader :aliased_associations
#aliased_associations The aliased_associations.(The aliased_associations.) (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 21
attr_reader :aliased_associations
#aliases (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 12
attr_reader :aliases
#aliases The aliases.(The aliases.) (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 12
attr_reader :aliases
#associations (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 18
attr_reader :associations
#associations The associations.(The associations.) (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 18
attr_reader :associations
#serializers (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 15
attr_reader :serializers
#serializers The serializers.(The serializers.) (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/smash.rb', line 15
attr_reader :serializers
Instance Method Details
#[](key) ⇒ Object
Get an item from the smart hash by the provided key.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 68
def [](key) fetch(aliases[key]) { super } end
#__deep_copy__ ⇒ Smash
Perform a deep copy of the smash.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 29
def __deep_copy__ self.class.new(aliases, serializers, associations, aliased_associations) do |copy| each_pair do |key, value| copy.store(key, value.__deep_copy__) end end end
#get_serializer(name) ⇒ Object
(private)
Retrieves the serializer for the given name. If the name exists in the serializers hash then return that immediately, otherwise recursively look through the associations and find the appropriate field.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 119
def get_serializer(name) if s = serializers[name] s else Fields.traverse_association_tree(name, serializers, associations, aliased_associations) end end
#localized_key(name, serializer) ⇒ String (private)
Get the localized value for the key if needed. If the field uses localization the current locale will be appended to the key in MongoDB dot notation.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 87
def localized_key(name, serializer) serializer && serializer.localized? ? "#{name}.#{::I18n.locale}" : name end
#storage_pair(key) ⇒ Array<String, Object
> (private)
Get the pair of objects needed to store the value in a hash by the provided key. This is the database field name and the serializer.
# File 'lib/mongoid/criteria/queryable/smash.rb', line 103
def storage_pair(key) field = key.to_s name = Fields.database_field_name(field, associations, aliases, aliased_associations) [ name, get_serializer(name) ] end