Sha256: 4a80a19e746d3c1908fb851f7193b0899aa49cda4a98ab1701fa4219e922b0db

Contents?: true

Size: 1.05 KB

Versions: 31

Compression:

Stored size: 1.05 KB

Contents

# encoding: utf-8
require "mongoid/matchers/default"
require "mongoid/matchers/all"
require "mongoid/matchers/exists"
require "mongoid/matchers/gt"
require "mongoid/matchers/gte"
require "mongoid/matchers/in"
require "mongoid/matchers/lt"
require "mongoid/matchers/lte"
require "mongoid/matchers/ne"
require "mongoid/matchers/nin"
require "mongoid/matchers/size"

module Mongoid #:nodoc:
  module Matchers
    # Determines if this document has the attributes to match the supplied
    # MongoDB selector. Used for matching on embedded associations.
    def matches?(selector)
      selector.each_pair do |key, value|
        return false unless matcher(key, value).matches?(value)
      end
      true
    end

    protected
    # Get the matcher for the supplied key and value. Will determine the class
    # name from the key.
    def matcher(key, value)
      if value.is_a?(Hash)
        name = "Mongoid::Matchers::#{value.keys.first.gsub("$", "").camelize}"
        return name.constantize.new(attributes[key])
      end
      Default.new(attributes[key])
    end
  end
end

Version data entries

31 entries across 31 versions & 5 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/matchers.rb
mongoid-with-auth-1.9.4 lib/mongoid/matchers.rb
mongoid-rails2-1.9.4 lib/mongoid/matchers.rb
mongoid-rails2-1.9.3 lib/mongoid/matchers.rb
mongoid-1.9.2 lib/mongoid/matchers.rb
sskirby-mongoid-1.9.1 lib/mongoid/matchers.rb
mongoid-1.9.1 lib/mongoid/matchers.rb
mongoid-1.9.0 lib/mongoid/matchers.rb
mongoid-pre-2.0.0.beta1 lib/mongoid/matchers.rb
mongoid-2.0.0.alpha lib/mongoid/matchers.rb
mongoid-1.2.14 lib/mongoid/matchers.rb
mongoid-1.2.13 lib/mongoid/matchers.rb
mongoid-1.2.12 lib/mongoid/matchers.rb
mongoid-1.2.11 lib/mongoid/matchers.rb
mongoid-1.2.10 lib/mongoid/matchers.rb
mongoid-1.2.9 lib/mongoid/matchers.rb
mongoid-1.2.8 lib/mongoid/matchers.rb
mongoid-1.2.7 lib/mongoid/matchers.rb
mongoid-pre-2.0.0.pre lib/mongoid/matchers.rb
mongoid-1.2.6 lib/mongoid/matchers.rb