Class: Chewy::Query::Nodes::And

Inherits:
Expr show all
Defined in:
lib/chewy/query/nodes/and.rb

Instance Method Summary collapse

Methods inherited from Expr

#!, #&, #|, #~

Methods inherited from Base

#eql?, #render

Constructor Details

#initialize(*nodes) ⇒ And

Returns a new instance of And.



5
6
7
8
# File 'lib/chewy/query/nodes/and.rb', line 5

def initialize(*nodes)
  @options = nodes.extract_options!
  @nodes = nodes.flatten.map { |node| node.is_a?(self.class) ? node.__nodes__ : node }.flatten
end

Instance Method Details

#__nodes__Object



10
11
12
# File 'lib/chewy/query/nodes/and.rb', line 10

def __nodes__
  @nodes
end

#__render__Object



14
15
16
17
18
19
20
21
# File 'lib/chewy/query/nodes/and.rb', line 14

def __render__
  nodes = @nodes.map(&:__render__)
  if @options.key?(:cache)
    {and: {filters: nodes, _cache: !!@options[:cache]}}
  else
    {and: nodes}
  end
end