123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Criteria::Queryable::Extensions::Array

Relationships & Source Files
Namespace Children
Modules:
Defined in: lib/mongoid/criteria/queryable/extensions/array.rb

Overview

Adds query type-casting behavior to Array class.

Instance Method Summary

Instance Method Details

#__add__(object) ⇒ Object

Combine the two objects using the add strategy.

Examples:

Add the object to the array.

[ 1, 2, 3 ].__add__(4)

Parameters:

  • object (Object)

    The object to add.

Returns:

  • (Object)

    The result of the add.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 20

def __add__(object)
  object.__add_from_array__(self)
end

#__array__Array

Return the object as an array.

Examples:

Get the array.

[ 1, 2 ].__array__

Returns:

  • (Array)

    self

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 30

def __array__; self; end

#__deep_copy__Array

Makes a deep copy of the array, deep copying every element inside the array.

Examples:

Get a deep copy of the array.

[ 1, 2, 3 ].__deep_copy__

Returns:

  • (Array)

    The deep copy of the array.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 39

def __deep_copy__
  map { |value| value.__deep_copy__ }
end

#__evolve_date__Array<Time>

Evolve the array into an array of mongo friendly dates. (Times at midnight).

Examples:

Evolve the array to dates.

[ Date.new(2010, 1, 1) ].__evolve_date__

Returns:

  • (Array<Time>)

    The array as times at midnight UTC.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 50

def __evolve_date__
  map { |value| value.__evolve_date__ }
end

#__evolve_time__Array<Time>

Evolve the array to an array of times.

Examples:

Evolve the array to times.

[ 1231231231 ].__evolve_time__

Returns:

  • (Array<Time>)

    The array as times.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 72

def __evolve_time__
  map { |value| value.__evolve_time__ }
end

#__expand_complex__Array

Get the object as expanded.

Examples:

Get the object expanded.

obj.__expand_complex__

Returns:

  • (Array)

    The expanded array.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 60

def __expand_complex__
  map do |value|
    value.__expand_complex__
  end
end

#__intersect__(object) ⇒ Object

Combine the two objects using an intersection strategy.

Examples:

Intersect with the object.

[ 1, 2 ].__intersect__(3)

Parameters:

  • object (Object)

    The object to intersect with.

Returns:

  • (Object)

    The result of the intersection.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 84

def __intersect__(object)
  object.__intersect_from_array__(self)
end

#__sort_option__Hash

Gets the array as options in the proper format to pass as MongoDB sort criteria.

Examples:

Get the array as sorting options.

[ :field, 1 ].__sort_option__

Returns:

  • (Hash)

    The array as sort criterion.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 95

def __sort_option__
  multi.inject({}) do |options, criteria|
    options.merge!(criteria.__sort_pair__)
    options
  end
end

#__sort_pair__Hash

Get the array as a sort pair.

Examples:

Get the array as field/direction pair.

[ field, 1 ].__sort_pair__

Returns:

  • (Hash)

    The field/direction pair.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 108

def __sort_pair__
  { first => Mongoid::Criteria::Translator.to_direction(last) }
end

#multiArray (private)

This method is for internal use only.

Converts the array to a multi-dimensional array.

Examples:

Convert to multi-dimensional.

[ 1, 2, 3 ].multi

Returns:

  • (Array)

    The multi-dimensional array.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 122

def multi
  first.is_a?(::Symbol) || first.is_a?(::String) ? [ self ] : self
end