Sha256: c596c09381827a3550b0e1a6027ac31b8b6553285cd9eabe57a37422a109a2a9

Contents?: true

Size: 740 Bytes

Versions: 8

Compression:

Stored size: 740 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Matchers #:nodoc:
    class Default
      # Creating a new matcher only requires the value.
      def initialize(attribute)
        @attribute = attribute
      end
      # Return true if the attribute and value are equal.
      def matches?(value)
        @attribute.is_a?(Array) && value.is_a?(String) ?
          @attribute.include?(value) : value === @attribute
      end

      protected
      # Return the first value in the hash.
      def first(value)
        value.values.first
      end

      # If object exists then compare, else return false
      def determine(value, operator)
        @attribute ? @attribute.send(operator, first(value)) : false
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
stonegao-mongoid-2.0.0.rc.6 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.6 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.5 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.4 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.3 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.2 lib/mongoid/matchers/default.rb
mongoid-2.0.0.rc.1 lib/mongoid/matchers/default.rb
mongoid-2.0.0.beta.20 lib/mongoid/matchers/default.rb