Class: Mongoid::Criteria::Queryable::Options

Inherits:
Smash
  • Object
show all
Defined in:
build/mongoid-master/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.

Instance Attribute Summary

Attributes inherited from Smash

#aliased_associations, #aliased_associations The aliased_associations., #aliases, #aliases The aliases., #associations, #associations The associations., #serializers, #serializers The serializers.

Instance Method Summary collapse

Methods inherited from Smash

#[], #initialize

Constructor Details

This class inherits a constructor from Mongoid::Criteria::Queryable::Smash

Instance Method Details

#__deep_copy__Options

Perform a deep copy of the options.

Examples:

Perform a deep copy.

options.__deep_copy__

Returns:

  • (Options)

    The copied options.



86
87
88
89
90
91
92
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 86

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

#fieldsHash

Convenience method for getting the field options.

Examples:

Get the fields options.

options.fields

Returns:

  • (Hash)

    The fields options.



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

def fields
  self[:fields]
end

#limitInteger

Convenience method for getting the limit option.

Examples:

Get the limit option.

options.limit

Returns:

  • (Integer)

    The limit option.



27
28
29
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 27

def limit
  self[:limit]
end

#skipInteger

Convenience method for getting the skip option.

Examples:

Get the skip option.

options.skip

Returns:

  • (Integer)

    The skip option.



37
38
39
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 37

def skip
  self[:skip]
end

#sortHash

Convenience method for getting the sort options.

Examples:

Get the sort options.

options.sort

Returns:

  • (Hash)

    The sort options.



47
48
49
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 47

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.

Examples:

Store a value in the options.

options.store(:key, "testing")

Parameters:

  • key (String, Symbol)

    The name of the attribute.

  • value (Object)

    The value to add.

Returns:

  • (Object)

    The stored object.



61
62
63
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 61

def store(key, value, localize = true)
  super(key, evolve(value, localize))
end

#to_pipelineArray<Hash>

Convert the options to aggregation pipeline friendly options.

Examples:

Convert the options to a pipeline.

options.to_pipeline

Returns:

  • (Array<Hash>)

    The options in pipeline form.



72
73
74
75
76
77
78
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 72

def to_pipeline
  pipeline = []
  pipeline.push({ "$skip" => skip }) if skip
  pipeline.push({ "$limit" => limit }) if limit
  pipeline.push({ "$sort" => sort }) if sort
  pipeline
end