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 26 27 28 29 30 31 |
# File 'lib/mongoid/matchable/elem_match.rb', line 15 def _matches?(value) elem_match = value["$elemMatch"] || value[:$elemMatch] if !@attribute.is_a?(Array) || !value.kind_of?(Hash) || !elem_match.kind_of?(Hash) return false end return @attribute.any? do |sub_document| elem_match.all? do |k, v| if v.try(:first).try(:[],0) == "$not".freeze || v.try(:first).try(:[],0) == :$not !Matchable.matcher(sub_document, k, v.first[1])._matches?(v.first[1]) else Matchable.matcher(sub_document, k, v)._matches?(v) end end end end |