Module: Mongoid::Criteria::Queryable

Includes:
Aggregable, Expandable, Mergeable, Optional, Storable, Selectable
Included in:
Mongoid::Criteria
Defined in:
lib/mongoid/criteria/queryable.rb,
lib/mongoid/criteria/queryable/key.rb,
lib/mongoid/criteria/queryable/smash.rb,
lib/mongoid/criteria/queryable/options.rb,
lib/mongoid/criteria/queryable/optional.rb,
lib/mongoid/criteria/queryable/pipeline.rb,
lib/mongoid/criteria/queryable/selector.rb,
lib/mongoid/criteria/queryable/storable.rb,
lib/mongoid/criteria/queryable/macroable.rb,
lib/mongoid/criteria/queryable/mergeable.rb,
lib/mongoid/criteria/queryable/aggregable.rb,
lib/mongoid/criteria/queryable/expandable.rb,
lib/mongoid/criteria/queryable/selectable.rb,
lib/mongoid/criteria/queryable/extensions/set.rb,
lib/mongoid/criteria/queryable/extensions/date.rb,
lib/mongoid/criteria/queryable/extensions/hash.rb,
lib/mongoid/criteria/queryable/extensions/time.rb,
lib/mongoid/criteria/queryable/extensions/array.rb,
lib/mongoid/criteria/queryable/extensions/range.rb,
lib/mongoid/criteria/queryable/extensions/object.rb,
lib/mongoid/criteria/queryable/extensions/regexp.rb,
lib/mongoid/criteria/queryable/extensions/string.rb,
lib/mongoid/criteria/queryable/extensions/symbol.rb,
lib/mongoid/criteria/queryable/extensions/boolean.rb,
lib/mongoid/criteria/queryable/extensions/numeric.rb,
lib/mongoid/criteria/queryable/extensions/date_time.rb,
lib/mongoid/criteria/queryable/extensions/nil_class.rb,
lib/mongoid/criteria/queryable/extensions/big_decimal.rb,
lib/mongoid/criteria/queryable/extensions/time_with_zone.rb

Overview

A queryable is any object that needs queryable’s dsl injected into it to build MongoDB queries. For example, a Mongoid::Criteria is an Queryable.

Examples:

Include queryable functionality.

class Criteria
  include Queryable
end

Defined Under Namespace

Modules: Aggregable, Expandable, Extensions, Macroable, Mergeable, Optional, Selectable, Storable Classes: Key, Options, Pipeline, Selector, Smash

Instance Attribute Summary collapse

Attributes included from Optional

#options, #options The query options.

Attributes included from Aggregable

#aggregating, #aggregating Flag for whether or not we are aggregating., #pipeline, #pipeline The aggregation pipeline.

Attributes included from Mergeable

#strategy, #strategy The name of the current strategy.

Instance Method Summary collapse

Methods included from Optional

#ascending, #batch_size, #collation, #comment, #cursor_type, #descending, forwardables, #hint, #limit, #max_scan, #max_time_ms, #no_timeout, #only, #order_by, #reorder, #skip, #slice, #snapshot, #without

Methods included from Macroable

#key

Methods included from Selectable

#atomic_selector

Methods included from Aggregable

#aggregating?, #group, #project, #unwind

Methods included from Mergeable

#and_with_operator, #intersect, #override, #reset_strategies!, #union

Methods included from Storable

#add_field_expression, #add_logical_operator_expression, #add_one_expression, #add_operator_expression

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



37
38
39
# File 'lib/mongoid/criteria/queryable.rb', line 37

def aliases
  @aliases
end

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



37
# File 'lib/mongoid/criteria/queryable.rb', line 37

attr_reader :aliases

#serializersObject (readonly)

Returns the value of attribute serializers.



40
41
42
# File 'lib/mongoid/criteria/queryable.rb', line 40

def serializers
  @serializers
end

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



40
# File 'lib/mongoid/criteria/queryable.rb', line 40

attr_reader :serializers

Instance Method Details

#==(other) ⇒ true | false

Is this queryable equal to another object? Is true if the selector and options are equal.

Examples:

Are the objects equal?

queryable == criteria

Parameters:

  • other (Object)

    The object to compare against.

Returns:

  • (true | false)

    If the objects are equal.



51
52
53
54
# File 'lib/mongoid/criteria/queryable.rb', line 51

def ==(other)
  return false unless other.is_a?(Queryable)
  selector == other.selector && options == other.options
end

#initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the new queryable. Will yield itself to the block if a block is provided for objects that need additional behavior.

Examples:

Initialize the queryable.

Queryable.new

Parameters:

  • aliases (Hash) (defaults to: {})

    The optional field aliases.

  • serializers (Hash) (defaults to: {})

    The optional field serializers.

  • associations (Hash) (defaults to: {})

    The optional associations.

  • aliased_associations (Hash) (defaults to: {})

    The optional aliased associations.

  • driver (Symbol)

    The driver being used.

Yields:

  • (_self)

Yield Parameters:



69
70
71
72
73
74
75
76
# File 'lib/mongoid/criteria/queryable.rb', line 69

def initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {})
  @aliases, @serializers = aliases, serializers
  @options = Options.new(aliases, serializers, associations, aliased_associations)
  @selector = Selector.new(aliases, serializers, associations, aliased_associations)
  @pipeline = Pipeline.new(aliases)
  @aggregating = nil
  yield(self) if block_given?
end

#initialize_copy(other) ⇒ Object

Handle the creation of a copy via #clone or #dup.

Examples:

Handle copy initialization.

queryable.initialize_copy(criteria)

Parameters:



84
85
86
87
88
# File 'lib/mongoid/criteria/queryable.rb', line 84

def initialize_copy(other)
  @options = other.options.__deep_copy__
  @selector = other.selector.__deep_copy__
  @pipeline = other.pipeline.__deep_copy__
end