Sha256: 553653093880c395977808eb098d2ad095ae41554ac84ec84c820dfb8ad05e51

Contents?: true

Size: 1.11 KB

Versions: 30

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  class PredicateBuilder
    class RangeHandler # :nodoc:
      class RangeWithBinds < Struct.new(:begin, :end)
        def exclude_end?
          false
        end
      end

      def initialize(predicate_builder)
        @predicate_builder = predicate_builder
      end

      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

      protected

        attr_reader :predicate_builder
    end
  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
activerecord-5.2.8.1 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.8 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.7.1 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.7 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.6.3 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.6.2 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.6.1 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.6 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.6 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.5 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.5 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.4 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.3 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.2 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.1 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4 lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.4.rc1 lib/active_record/relation/predicate_builder/range_handler.rb
spiral_form-0.1.1 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/relation/predicate_builder/range_handler.rb
spiral_form-0.1.0 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/relation/predicate_builder/range_handler.rb
activerecord-5.2.3 lib/active_record/relation/predicate_builder/range_handler.rb