Class: Mongoid::Matchable::ElemMatch
- Defined in:
- lib/mongoid/matchable/elem_match.rb
Overview
Instance Attribute Summary
Attributes inherited from Default
Instance Method Summary collapse
-
#matches?(value) ⇒ true, false
Return true if a given predicate matches a sub document entirely.
Methods inherited from Default
Constructor Details
This class inherits a constructor from Mongoid::Matchable::Default
Instance Method Details
#matches?(value) ⇒ true, false
Return true if a given predicate matches a sub document entirely
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mongoid/matchable/elem_match.rb', line 15 def matches?(value) if !@attribute.is_a?(Array) || !value.kind_of?(Hash) || !value["$elemMatch"].kind_of?(Hash) return false end return @attribute.any? do |sub_document| value["$elemMatch"].all? do |k, v| Matchable.matcher(sub_document, k, v).matches?(v) end end end |