Class: Mongoid::Tags::Query

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/mongoid/tags.rb

Instance Method Summary collapse

Instance Method Details

#to_criteria(tags = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/mongoid/tags.rb', line 32

def to_criteria(tags = nil)
  {}.tap do |criteria|
    (tags.presence || elements).each do |tag|
      (criteria[tag.operator.selector] ||= []) << tag.to_criteria if tag.is_a? Tag

      criteria.merge!(to_criteria(tag.elements)) { |key, first, second| first + second } if tag.elements.present?
    end
  end
end