lib/mongoid/criteria/queryable/mergeable.rb in mongoid-7.3.5 vs lib/mongoid/criteria/queryable/mergeable.rb in mongoid-7.4.0

- old
+ new

@@ -1,7 +1,6 @@ # frozen_string_literal: true -# encoding: utf-8 module Mongoid class Criteria module Queryable @@ -15,48 +14,40 @@ # # @example Use intersection on the next call. # mergeable.intersect.in(field: [ 1, 2, 3 ]) # # @return [ Mergeable ] The intersect flagged mergeable. - # - # @since 1.0.0 def intersect use(:__intersect__) end # Instruct the next mergeable call to use override. # # @example Use override on the next call. # mergeable.override.in(field: [ 1, 2, 3 ]) # # @return [ Mergeable ] The override flagged mergeable. - # - # @since 1.0.0 def override use(:__override__) end # Instruct the next mergeable call to use union. # # @example Use union on the next call. # mergeable.union.in(field: [ 1, 2, 3 ]) # # @return [ Mergeable ] The union flagged mergeable. - # - # @since 1.0.0 def union use(:__union__) end # Clear the current strategy and negating flag, used after cloning. # # @example Reset the strategies. # mergeable.reset_strategies! # # @return [ Criteria ] self. - # - # @since 1.0.0 def reset_strategies! self.strategy = nil self.negating = nil self end @@ -72,12 +63,10 @@ # # @param [ Hash ] criterion The criteria. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __add__(criterion, operator) with_strategy(:__add__, criterion, operator) end # Adds the criterion to the existing selection. @@ -90,12 +79,10 @@ # @param [ Hash ] criterion The criteria. # @param [ String ] outer The outer MongoDB operator. # @param [ String ] inner The inner MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __expanded__(criterion, outer, inner) selection(criterion) do |selector, field, value| selector.store(field, { outer => { inner => value }}) end end @@ -109,12 +96,10 @@ # mergeable.__merge__(location: [ 1, 10 ]) # # @param [ Hash ] criterion The criteria. # # @return [ Mergeable ] The cloned object. - # - # @since 2.0.0 def __merge__(criterion) selection(criterion) do |selector, field, value| selector.merge!(field.__expr_part__(value)) end end @@ -128,12 +113,10 @@ # # @param [ Hash ] criterion The criteria. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __intersect__(criterion, operator) with_strategy(:__intersect__, criterion, operator) end # Adds $and/$or/$nor criteria to a copy of this selection. @@ -150,12 +133,10 @@ # @param [ Array<Hash | Criteria> ] criteria Multiple key/value pair # matches or Criteria objects. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __multi__(criteria, operator) clone.tap do |query| sel = query.selector criteria.flatten.each do |expr| next unless expr @@ -169,11 +150,11 @@ end end # Combines criteria into a MongoDB selector. # - # Criteria is an array of criterions which will be flattened. + # Criteria is an array of criterion objects which will be flattened. # # Each criterion can be: # - A hash # - A Criteria instance # - nil, in which case it is ignored @@ -335,12 +316,10 @@ # # @param [ Hash | Criteria ] criterion The criteria. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __override__(criterion, operator) if criterion.is_a?(Selectable) criterion = criterion.selector end selection(criterion) do |selector, field, value| @@ -363,12 +342,10 @@ # # @param [ Hash ] criterion The criteria. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The new mergeable. - # - # @since 1.0.0 def __union__(criterion, operator) with_strategy(:__union__, criterion, operator) end # Use the named strategy for the next operation. @@ -379,12 +356,10 @@ # mergeable.use(:__intersect__) # # @param [ Symbol ] strategy The strategy to use. # # @return [ Mergeable ] The existing mergeable. - # - # @since 1.0.0 def use(strategy) tap do |mergeable| mergeable.strategy = strategy end end @@ -399,12 +374,10 @@ # @param [ Symbol ] strategy The name of the strategy method. # @param [ Object ] criterion The criterion to add. # @param [ String ] operator The MongoDB operator. # # @return [ Mergeable ] The cloned query. - # - # @since 1.0.0 def with_strategy(strategy, criterion, operator) selection(criterion) do |selector, field, value| selector.store( field, selector[field].send(strategy, prepare(field, operator, value)) @@ -421,11 +394,9 @@ # # @param [ String ] field The name of the field. # @param [ Object ] value The value. # # @return [ Object ] The serialized value. - # - # @since 1.0.0 def prepare(field, operator, value) unless operator =~ /exists|type|size/ value = value.__expand_complex__ field = field.to_s name = aliases[field] || field