Sha256: 441f1af2a56d52963f441bb8c2eee4f60b56357b5615324a875a4879d9df2f48

Contents?: true

Size: 745 Bytes

Versions: 3

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Matchable

    # Defines behavior for handling regular expressions in embedded documents.
    class Regexp < Default

      # Does the supplied query match the attribute?
      #
      # @example Does this match?
      #   matcher._matches?(/^Em/)
      #   matcher._matches?(BSON::Regex::Raw.new("^Em"))
      #
      # @param [ BSON::Regexp::Raw, Regexp ] regexp The regular expression object.
      #
      # @return [ true, false ] True if matches, false if not.
      #
      # @since 5.2.1
      def _matches?(regexp)
        if native_regexp = regexp.try(:compile)
          super(native_regexp)
        else
          super
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-7.1.1 lib/mongoid/matchable/regexp.rb
mongoid-7.1.0 lib/mongoid/matchable/regexp.rb
mongoid-7.1.0.rc0 lib/mongoid/matchable/regexp.rb