Class: ActiveRecord::PredicateBuilder::RangeHandler

Inherits:
Object
  • Object
show all
Defined in:
activerecord/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.


6
7
8
# File 'activerecord/lib/active_record/relation/predicate_builder/range_handler.rb', line 6

def initialize(predicate_builder)
  @predicate_builder = predicate_builder
end

Instance Method Details

#call(attribute, value) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'activerecord/lib/active_record/relation/predicate_builder/range_handler.rb', line 10

def call(attribute, value)
  if value.begin.respond_to?(:infinite?) && value.begin.infinite?
    if value.end.respond_to?(:infinite?) && value.end.infinite?
      attribute.not_in([])
    elsif value.exclude_end?
      attribute.lt(value.end)
    else
      attribute.lteq(value.end)
    end
  elsif value.end.respond_to?(:infinite?) && value.end.infinite?
    attribute.gteq(value.begin)
  elsif value.exclude_end?
    attribute.gteq(value.begin).and(attribute.lt(value.end))
  else
    attribute.between(value)
  end
end