Sha256: c9bdb98c8b5519439e5dcfe8467ad7123bdd1fcfc5da74099b694e0a3c9fd5d5

Contents?: true

Size: 963 Bytes

Versions: 190

Compression:

Stored size: 963 Bytes

Contents

# encoding: utf-8
require "mongoid/matchers/strategies"

module Mongoid #:nodoc:

  # This module contains all the behavior for ruby implementations of MongoDB
  # selectors.
  module Matchers

    # Determines if this document has the attributes to match the supplied
    # MongoDB selector. Used for matching on embedded associations.
    #
    # @example Does the document match?
    #   document.matches?(:title => { "$in" => [ "test" ] })
    #
    # @param [ Hash ] selector The MongoDB selector.
    #
    # @return [ true, false ] True if matches, false if not.
    def matches?(selector)
      selector.each_pair do |key, value|
        if value.is_a?(Hash)
          value.each do |item|
            return false unless Strategies.matcher(self, key, Hash[*item]).matches?(Hash[*item])
          end
        else
          return false unless Strategies.matcher(self, key, value).matches?(value)
        end
      end
      return true
    end
  end
end

Version data entries

190 entries across 98 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
mongoid-2.8.1 lib/mongoid/matchers.rb
mongoid-2.8.0 lib/mongoid/matchers.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/matchers.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/matchers.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/matchers.rb