Module: Mongoid::Criteria::Queryable::Mergeable

Included in:
Mongoid::Criteria::Queryable
Defined in:
build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb

Overview

Contains behavior for merging existing selection with new selection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#strategyObject

Returns the value of attribute strategy.



11
12
13
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 11

def strategy
  @strategy
end

#strategy The name of the current strategy.(Thenameofthecurrentstrategy.) ⇒ Object



11
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 11

attr_accessor :strategy

Instance Method Details

#and_with_operator(criterion, operator) ⇒ Criteria

Merge criteria with operators using the and operator.

Parameters:

  • criterion (Hash)

    The criterion to add to the criteria.

  • operator (String)

    The MongoDB operator.

Returns:

  • (Criteria)

    The resulting criteria.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 61

def and_with_operator(criterion, operator)
  crit = self
  if criterion
    criterion.each_pair do |field, value|
      val = prepare(field, operator, value)
      # The prepare method already takes the negation into account. We
      # set negating to false here so that ``and`` doesn't also apply
      # negation and we have a double negative.
      crit.negating = false
      crit = crit.and(field => val)
    end
  end
  crit
end

#intersectMergeable

Instruct the next mergeable call to use intersection.

Examples:

Use intersection on the next call.

mergeable.intersect.in(field: [ 1, 2, 3 ])

Returns:

  • (Mergeable)

    The intersect flagged mergeable.



19
20
21
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 19

def intersect
  use(:__intersect__)
end

#overrideMergeable

Instruct the next mergeable call to use override.

Examples:

Use override on the next call.

mergeable.override.in(field: [ 1, 2, 3 ])

Returns:

  • (Mergeable)

    The override flagged mergeable.



29
30
31
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 29

def override
  use(:__override__)
end

#reset_strategies!Criteria

Clear the current strategy and negating flag, used after cloning.

Examples:

Reset the strategies.

mergeable.reset_strategies!

Returns:



49
50
51
52
53
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 49

def reset_strategies!
  self.strategy = nil
  self.negating = nil
  self
end

#unionMergeable

Instruct the next mergeable call to use union.

Examples:

Use union on the next call.

mergeable.union.in(field: [ 1, 2, 3 ])

Returns:

  • (Mergeable)

    The union flagged mergeable.



39
40
41
# File 'build/mongoid-8.1/lib/mongoid/criteria/queryable/mergeable.rb', line 39

def union
  use(:__union__)
end