Class: ActiveRecord::PredicateBuilder::RangeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/relation/predicate_builder/range_handler.rb

Overview

:nodoc:

Defined Under Namespace

Classes: RangeWithBinds

Instance Method Summary collapse

Constructor Details

#initialize(predicate_builder) ⇒ RangeHandler

Returns a new instance of RangeHandler.



12
13
14
# File 'lib/active_record/relation/predicate_builder/range_handler.rb', line 12

def initialize(predicate_builder)
  @predicate_builder = predicate_builder
end

Instance Method Details

#call(attribute, value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_record/relation/predicate_builder/range_handler.rb', line 16

def call(attribute, value)
  begin_bind = predicate_builder.build_bind_attribute(attribute.name, value.begin)
  end_bind = predicate_builder.build_bind_attribute(attribute.name, value.end)

  if begin_bind.value.infinity?
    if end_bind.value.infinity?
      attribute.not_in([])
    elsif value.exclude_end?
      attribute.lt(end_bind)
    else
      attribute.lteq(end_bind)
    end
  elsif end_bind.value.infinity?
    attribute.gteq(begin_bind)
  elsif value.exclude_end?
    attribute.gteq(begin_bind).and(attribute.lt(end_bind))
  else
    attribute.between(RangeWithBinds.new(begin_bind, end_bind))
  end
end