Sha256: 500a2083cc737e26b409dcb70ba0c5455388fab15ae8fdff479cd71259403d5f

Contents?: true

Size: 762 Bytes

Versions: 10

Compression:

Stored size: 762 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

10 entries across 9 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/matchable/elem_match.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/matchable/elem_match.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/matchable/elem_match.rb
mongoid-6.1.0 lib/mongoid/matchable/elem_match.rb
mongoid-6.1.0.rc0 lib/mongoid/matchable/elem_match.rb
mongoid-6.0.3 lib/mongoid/matchable/elem_match.rb
mongoid-6.0.2 lib/mongoid/matchable/elem_match.rb
mongoid-6.0.1 lib/mongoid/matchable/elem_match.rb
mongoid-6.0.0 lib/mongoid/matchable/elem_match.rb
mongoid-6.0.0.rc0 lib/mongoid/matchable/elem_match.rb