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

#aliases, #aliases The aliases., #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.

Since:

  • 6.1.1



101
102
103
104
105
106
107
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 101

def __deep_copy__
  self.class.new(aliases, serializers) 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.

Since:

  • 1.0.0



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

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.

Since:

  • 1.0.0



32
33
34
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 32

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.

Since:

  • 1.0.0



44
45
46
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 44

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.

Since:

  • 1.0.0



56
57
58
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/options.rb', line 56

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.

Since:

  • 1.0.0



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

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.

Since:

  • 2.0.0



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

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