Class: ChewyQuery::Builder::Nodes::Bool

Inherits:
Expr
  • Object
show all
Defined in:
lib/chewy_query/builder/nodes/bool.rb

Constant Summary collapse

METHODS =
%w(must must_not should)

Instance Method Summary collapse

Methods inherited from Expr

#!, #&, #|, #~

Methods inherited from Base

#eql?, #render

Constructor Details

#initialize(options = {}) ⇒ Bool

Returns a new instance of Bool.



7
8
9
10
# File 'lib/chewy_query/builder/nodes/bool.rb', line 7

def initialize(options = {})
  @options = options
  @must, @must_not, @should = [], [], []
end

Instance Method Details

#__render__Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chewy_query/builder/nodes/bool.rb', line 19

def __render__
  bool = METHODS.map do |method|
    value = instance_variable_get("@#{method}")
    [method.to_sym, value.map(&:__render__)] if value.any?
  end.compact

  bool = { bool: Hash[bool] }

  bool[:bool][:_cache] = !!@options[:cache] if @options.key?(:cache)
  bool
end