Class: Mongoid::Matchable::Regexp

Inherits:
Default
  • Object
show all
Defined in:
build/mongoid-7.0/lib/mongoid/matchable/regexp.rb

Overview

Defines behavior for handling regular expressions in embedded documents.

Since:

  • 4.0.0

Instance Attribute Summary

Attributes inherited from Default

#attribute, #document

Instance Method Summary collapse

Methods inherited from Default

#initialize

Constructor Details

This class inherits a constructor from Mongoid::Matchable::Default

Instance Method Details

#_matches?(regexp) ⇒ true, false

Does the supplied query match the attribute?

Examples:

Does this match?

matcher._matches?(/\AEm/)
matcher._matches?(BSON::Regex::Raw.new("\\AEm"))

Parameters:

  • regexp (BSON::Regexp::Raw, Regexp)

    The regular expression object.

Returns:

  • (true, false)

    True if matches, false if not.

Since:

  • 5.2.1



18
19
20
21
22
23
24
# File 'build/mongoid-7.0/lib/mongoid/matchable/regexp.rb', line 18

def _matches?(regexp)
  if native_regexp = regexp.try(:compile)
    super(native_regexp)
  else
    super
  end
end