Class: Mongoid::Matchers::In

Inherits:
Default show all
Defined in:
lib/mongoid/matchers/in.rb

Overview

Performs matching for any value in an array.

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::Matchers::Default

Instance Method Details

#matches?(value) ⇒ true, false

Return true if the attribute is in the values.

Examples:

Do the values match?

matcher.matches?({ :key => 10 })

Parameters:

  • value (Hash)

    The values to check.

Returns:

  • (true, false)

    If a value exists.



16
17
18
19
20
21
22
23
24
25
# File 'lib/mongoid/matchers/in.rb', line 16

def matches?(value)
  attribute_array = Array.wrap(@attribute)
  value.values.first.any? do |e|
    if e.is_a?(Regexp)
      attribute_array.any? { |_attribute| _attribute =~ e }
    else
      attribute_array.include?(e)
    end
  end
end