Class: Mongoid::Matchers::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/matchers/default.rb

Overview

Contains all the default behavior for checking for matching documents given MongoDB expressions.

Direct Known Subclasses

All, And, Exists, Gt, Gte, In, Lt, Lte, Ne, Nin, Or, Size

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, document = nil) ⇒ Default

Creating a new matcher only requires the value.

Examples:

Create a new matcher.

Default.new("attribute")

Parameters:

  • attribute (Object)

    The current attribute to check against.

Since:

  • 1.0.0



19
20
21
# File 'lib/mongoid/matchers/default.rb', line 19

def initialize(attribute, document = nil)
  @attribute, @document = attribute, document
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



9
10
11
# File 'lib/mongoid/matchers/default.rb', line 9

def attribute
  @attribute
end

#documentObject

Returns the value of attribute document.



9
10
11
# File 'lib/mongoid/matchers/default.rb', line 9

def document
  @document
end

Instance Method Details

#matches?(value) ⇒ true, false

Return true if the attribute and value are equal, or if it is an array if the value is included.

Examples:

Does this value match?

default.matches?("value")

Parameters:

  • value (Object)

    The value to check if it matches.

Returns:

  • (true, false)

    True if matches, false if not.

Since:

  • 1.0.0



34
35
36
# File 'lib/mongoid/matchers/default.rb', line 34

def matches?(value)
  attribute.is_a?(Array) && !value.is_a?(Array) ? attribute.include?(value) : value === attribute
end