Class: Mongoid::Matchable::Default
- Inherits:
-
Object
- Object
- Mongoid::Matchable::Default
- Defined in:
- lib/mongoid/matchable/default.rb
Overview
Contains all the default behavior for checking for matching documents given MongoDB expressions.
Instance Attribute Summary collapse
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/matchable/default.rb', line 19 def initialize(attribute, document = nil) @attribute, @document = attribute, document end |
Instance Attribute Details
#attribute ⇒ Object
9 10 11 |
# File 'lib/mongoid/matchable/default.rb', line 9 def attribute @attribute end |
#document ⇒ Object
9 10 11 |
# File 'lib/mongoid/matchable/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/matchable/default.rb', line 34 def matches?(value) attribute.is_a?(Array) && !value.is_a?(Array) ? attribute.any? { |_attribute| value === _attribute } : value === attribute end |