Module: Mongoid::Criteria::Queryable

Includes:
Aggregable, Mergeable, Optional, 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/macroable.rb,
lib/mongoid/criteria/queryable/mergeable.rb,
lib/mongoid/criteria/queryable/aggregable.rb,
lib/mongoid/criteria/queryable/selectable.rb,
lib/mongoid/criteria/queryable/forwardable.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, Extensions, Forwardable, Macroable, Mergeable, Optional, Selectable 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

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

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases



34
35
36
# File 'lib/mongoid/criteria/queryable.rb', line 34

def aliases
  @aliases
end

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



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

attr_reader :aliases, :driver, :serializers

#driverObject (readonly)

Returns the value of attribute driver



34
35
36
# File 'lib/mongoid/criteria/queryable.rb', line 34

def driver
  @driver
end

#driver The Mongo driver being used.(TheMongodriverbeingused.) ⇒ Object (readonly)



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

attr_reader :aliases, :driver, :serializers

#serializersObject (readonly)

Returns the value of attribute serializers



34
35
36
# File 'lib/mongoid/criteria/queryable.rb', line 34

def serializers
  @serializers
end

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



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

attr_reader :aliases, :driver, :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.

Since:

  • 1.0.0



47
48
49
50
# File 'lib/mongoid/criteria/queryable.rb', line 47

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

#initialize(aliases = {}, serializers = {}, driver = :mongo) {|_self| ... } ⇒ Object

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

Examples:

Initialize the queryable.

Queryable.new

Parameters:

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

    The optional field aliases.

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

    The optional field serializers.

  • driver (Symbol) (defaults to: :mongo)

    The driver being used.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 1.0.0



63
64
65
66
67
68
69
70
# File 'lib/mongoid/criteria/queryable.rb', line 63

def initialize(aliases = {}, serializers = {}, driver = :mongo)
  @aliases, @driver, @serializers = aliases, driver.to_sym, serializers
  @options = Options.new(aliases, serializers)
  @selector = Selector.new(aliases, serializers)
  @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:

Since:

  • 1.0.0



80
81
82
83
84
# File 'lib/mongoid/criteria/queryable.rb', line 80

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