Class: Mongoid::Matchers::Default
- Defined in:
- lib/mongoid/matchers/default.rb
Overview
Contains all the default behavior for checking for matching documents given MongoDB expressions.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
-
#initialize(attribute, document = nil) ⇒ Default
constructor
Creating a new matcher only requires the value.
-
#matches?(value) ⇒ true, false
Return true if the attribute and value are equal, or if it is an array if the value is included.
Constructor Details
#initialize(attribute, document = nil) ⇒ Default
Creating a new matcher only requires the value.
19 20 21 |
# File 'lib/mongoid/matchers/default.rb', line 19 def initialize(attribute, document = nil) @attribute, @document = attribute, document end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
9 10 11 |
# File 'lib/mongoid/matchers/default.rb', line 9 def attribute @attribute end |
#document ⇒ Object
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.
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 |