Sha256: 98a1c4e555ec7b52eb99cbe0a3288aa4e4fcaeadbd8320cb8d498514a14fe2a8

Contents?: true

Size: 765 Bytes

Versions: 14

Compression:

Stored size: 765 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Matchable

    class ElemMatch < Default

      # Return true if a given predicate matches a sub document entirely
      #
      # @example Do the values match?
      #   matcher._matches?({"$elemMatch" => {"a" => 1, "b" => 2}})
      #
      # @param [ Hash ] value The values to check.
      #
      # @return [ true, false ] If the values match.
      def _matches?(value)
        if !@attribute.is_a?(Array) || !value.kind_of?(Hash) || !value["$elemMatch"].kind_of?(Hash)
          return false
        end

        return @attribute.any? do |sub_document|
          value["$elemMatch"].all? do |k, v|
            Matchable.matcher(sub_document, k, v)._matches?(v)
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
mongoid-6.4.8 lib/mongoid/matchable/elem_match.rb
mongoid-6.4.7 lib/mongoid/matchable/elem_match.rb
mongoid-6.4.5 lib/mongoid/matchable/elem_match.rb
mongoid-6.4.4 lib/mongoid/matchable/elem_match.rb
mongoid-6.4.2 lib/mongoid/matchable/elem_match.rb
mongoid-6.4.1 lib/mongoid/matchable/elem_match.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/matchable/elem_match.rb
mongoid-6.4.0 lib/mongoid/matchable/elem_match.rb
mongoid-6.3.0 lib/mongoid/matchable/elem_match.rb
mongoid-6.2.1 lib/mongoid/matchable/elem_match.rb
mongoid-7.0.0.beta lib/mongoid/matchable/elem_match.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/lib/mongoid/matchable/elem_match.rb
mongoid-6.2.0 lib/mongoid/matchable/elem_match.rb
mongoid-6.1.1 lib/mongoid/matchable/elem_match.rb