Class: Mongoid::Criteria::Queryable::Smash

Inherits:
Hash
  • Object
show all
Defined in:
build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb

Overview

This is a smart hash for use with options and selectors.

Direct Known Subclasses

Options, Selector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... } ⇒ Smash

Initialize the new selector.

Examples:

Initialize the new selector.

Queryable::Smash.new(aliases, serializers)

Parameters:

  • aliases (Hash) (defaults to: {})

    A hash of mappings from aliases to the actual field names in the database.

  • serializers (Hash) (defaults to: {})

    An optional hash of objects that are responsible for serializing values. The keys of the hash must be strings that match the field name, and the values must respond to #localized? and #evolve(object).

  • associations (Hash) (defaults to: {})

    An optional hash of names to association objects.

  • aliased_associations (Hash) (defaults to: {})

    An optional hash of mappings from aliases for associations to their actual field names in the database.

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
55
56
57
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 51

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_associationsObject (readonly)

Returns the value of attribute aliased_associations.



20
21
22
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 20

def aliased_associations
  @aliased_associations
end

#aliased_associations The aliased_associations.(Thealiased_associations.) ⇒ Object (readonly)



20
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 20

attr_reader :aliased_associations

#aliasesObject (readonly)

Returns the value of attribute aliases.



11
12
13
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 11

def aliases
  @aliases
end

#aliases The aliases.(Thealiases.) ⇒ Object (readonly)



11
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 11

attr_reader :aliases

#associationsObject (readonly)

Returns the value of attribute associations.



17
18
19
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 17

def associations
  @associations
end

#associations The associations.(Theassociations.) ⇒ Object (readonly)



17
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 17

attr_reader :associations

#serializersObject (readonly)

Returns the value of attribute serializers.



14
15
16
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 14

def serializers
  @serializers
end

#serializers The serializers.(Theserializers.) ⇒ Object (readonly)



14
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 14

attr_reader :serializers

Instance Method Details

#[](key) ⇒ Object

Get an item from the smart hash by the provided key.

Examples:

Get an item by the key.

smash["test"]

Parameters:

  • key (String)

    The key.

Returns:

  • (Object)

    The found object.



67
68
69
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 67

def [](key)
  fetch(aliases[key]) { super }
end

#__deep_copy__Smash

Perform a deep copy of the smash.

Examples:

Perform a deep copy.

smash.__deep_copy__

Returns:

  • (Smash)

    The copied hash.



28
29
30
31
32
33
34
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/smash.rb', line 28

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