Sha256: 3e272713e208369e3207c4ba10077343f89422142f3cc8308764cf9006591d24

Contents?: true

Size: 954 Bytes

Versions: 32

Compression:

Stored size: 954 Bytes

Contents

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

module Mongoid

  # 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

32 entries across 32 versions & 2 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/matchers.rb
mongoid-3.1.6 lib/mongoid/matchers.rb
mongoid-3.1.5 lib/mongoid/matchers.rb
mongoid-3.1.4 lib/mongoid/matchers.rb
mongoid-3.1.3 lib/mongoid/matchers.rb
mongoid-3.1.2 lib/mongoid/matchers.rb
mongoid-3.0.23 lib/mongoid/matchers.rb
mongoid-3.1.1 lib/mongoid/matchers.rb
mongoid-3.1.0 lib/mongoid/matchers.rb
mongoid-3.0.22 lib/mongoid/matchers.rb
mongoid-3.0.21 lib/mongoid/matchers.rb
mongoid-3.0.20 lib/mongoid/matchers.rb
mongoid-3.0.19 lib/mongoid/matchers.rb
mongoid-3.0.18 lib/mongoid/matchers.rb
mongoid-3.0.17 lib/mongoid/matchers.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/matchers.rb
mongoid-3.0.16 lib/mongoid/matchers.rb
mongoid-3.0.15 lib/mongoid/matchers.rb
mongoid-3.0.14 lib/mongoid/matchers.rb
mongoid-3.0.13 lib/mongoid/matchers.rb