class ChewyQuery::Builder::Nodes::Range

Constants

EXECUTION

Public Class Methods

new(name, *args) click to toggle source
# File lib/chewy_query/builder/nodes/range.rb, line 12
def initialize(name, *args)
  @name = name.to_s
  @options = args.extract_options!
  @range = @options.reject{|k, v| ![:gt, :lt].include?(k) }
  @bounds = @options.reject{|k, v| ![:left_closed, :right_closed].include?(k) }
  execution = EXECUTION[args.first.to_sym] if args.first
  @options[:execution] = execution if execution
end

Public Instance Methods

&(other) click to toggle source
Calls superclass method ChewyQuery::Builder::Nodes::Expr#&
# File lib/chewy_query/builder/nodes/range.rb, line 21
def &(other)
  if other.is_a?(self.class) && other.__name__ == @name
    state = __state__.merge(other.__state__)

    cache = other.__options__[:cache] || @options[:cache]
    state[:cache] = cache unless cache.nil?

    execution = other.__options__[:execution] || @options[:execution]
    state[:execution] = execution unless execution.nil?

    self.class.new(@name, state)
  else
    super
  end
end
__name__() click to toggle source
# File lib/chewy_query/builder/nodes/range.rb, line 37
def __name__
  @name
end
__options__() click to toggle source
# File lib/chewy_query/builder/nodes/range.rb, line 45
def __options__
  @options
end
__render__() click to toggle source
# File lib/chewy_query/builder/nodes/range.rb, line 49
def __render__
  body = {}
  body[@bounds[:left_closed] ? :gte : :gt] = @range[:gt] if @range.key?(:gt)
  body[@bounds[:right_closed] ? :lte : :lt] = @range[:lt] if @range.key?(:lt)

  filter = { @name => body }
  filter[:_cache] = !!@options[:cache] if @options.key?(:cache)
  filter.merge!(@options.slice(:execution))

  { range: filter }
end
__state__() click to toggle source
# File lib/chewy_query/builder/nodes/range.rb, line 41
def __state__
  @range.merge(@bounds)
end