Class: Origin::Options

Inherits:
Smash
  • Object
show all
Defined in:
lib/origin/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 Origin::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:

  • 2.3.1



97
98
99
100
101
102
103
# File 'lib/origin/options.rb', line 97

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



16
17
18
# File 'lib/origin/options.rb', line 16

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



28
29
30
# File 'lib/origin/options.rb', line 28

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



40
41
42
# File 'lib/origin/options.rb', line 40

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



52
53
54
# File 'lib/origin/options.rb', line 52

def sort
  self[:sort]
end

#store(key, value) ⇒ 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



68
69
70
# File 'lib/origin/options.rb', line 68

def store(key, value)
  super(key, evolve(value))
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



81
82
83
84
85
86
87
# File 'lib/origin/options.rb', line 81

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