Module: Origin::Queryable

Includes:
Aggregable, Mergeable, Optional, Selectable
Defined in:
lib/origin/queryable.rb

Overview

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

Examples:

Include queryable functionality.

class Criteria
  include Origin::Queryable
end

Constant Summary

Constant Summary

Constants included from Selectable

Selectable::LINE_STRING, Selectable::POINT, Selectable::POLYGON

Instance Attribute Summary collapse

Attributes included from Optional

#options, #options The query options.

Attributes included from Selectable

#negating, #negating If the next spression is negated., #selector, #selector The query selector.

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, #descending, forwardables, #hint, #limit, #max_scan, #no_timeout, #only, #order_by, #reorder, #skip, #slice, #snapshot, #without

Methods included from Macroable

#key

Methods included from Selectable

#all, #and, #between, #elem_match, #exists, forwardables, #geo_spacial, #gt, #gte, #in, #lt, #lte, #max_distance, #mod, #ne, #near, #near_sphere, #negating?, #nin, #nor, #not, #or, #where, #with_size, #with_type

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



32
33
34
# File 'lib/origin/queryable.rb', line 32

def aliases
  @aliases
end

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



32
# File 'lib/origin/queryable.rb', line 32

attr_reader :aliases, :driver, :serializers

#driverObject (readonly)

Returns the value of attribute driver



32
33
34
# File 'lib/origin/queryable.rb', line 32

def driver
  @driver
end

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



32
# File 'lib/origin/queryable.rb', line 32

attr_reader :aliases, :driver, :serializers

#serializersObject (readonly)

Returns the value of attribute serializers



32
33
34
# File 'lib/origin/queryable.rb', line 32

def serializers
  @serializers
end

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



32
# File 'lib/origin/queryable.rb', line 32

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



45
46
47
48
# File 'lib/origin/queryable.rb', line 45

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

#initialize(aliases = {}, serializers = {}, driver = :moped) {|_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.

Origin::Queryable.new

Parameters:

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

    The optional field aliases.

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

    The optional field serializers.

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

    The driver being used.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 1.0.0



61
62
63
64
65
66
67
# File 'lib/origin/queryable.rb', line 61

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



77
78
79
80
81
# File 'lib/origin/queryable.rb', line 77

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