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

Inherits:
Hash
  • Object
show all
Defined in:
build/mongoid-7.3/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 = {}) {|_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).

Yields:

  • (_self)

Yield Parameters:

Since:

  • 1.0.0



44
45
46
47
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/smash.rb', line 44

def initialize(aliases = {}, serializers = {})
  @aliases, @serializers = aliases, serializers
  yield(self) if block_given?
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



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

def aliases
  @aliases
end

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



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

attr_reader :aliases, :serializers

#serializersObject (readonly)

Returns the value of attribute serializers.



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

def serializers
  @serializers
end

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



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

attr_reader :aliases, :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.

Since:

  • 2.0.0



59
60
61
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/smash.rb', line 59

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.

Since:

  • 1.0.0



23
24
25
26
27
28
29
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/smash.rb', line 23

def __deep_copy__
  self.class.new(aliases, serializers) do |copy|
    each_pair do |key, value|
      copy.store(key, value.__deep_copy__)
    end
  end
end