Sha256: b1fe483aae8f3319997e0e438ee0aa33e1c82a141d054523e2f99985f1270bb0

Contents?: true

Size: 1.2 KB

Versions: 75

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "active_model/attribute"

module ActiveRecord
  class Relation
    class QueryAttribute < ActiveModel::Attribute # :nodoc:
      def type_cast(value)
        value
      end

      def value_for_database
        @value_for_database ||= super
      end

      def with_cast_value(value)
        QueryAttribute.new(name, value, type)
      end

      def nil?
        unless value_before_type_cast.is_a?(StatementCache::Substitute)
          value_before_type_cast.nil? ||
            type.respond_to?(:subtype, true) && value_for_database.nil?
        end
      rescue ::RangeError
      end

      def infinite?
        infinity?(value_before_type_cast) || infinity?(value_for_database)
      rescue ::RangeError
      end

      def unboundable?
        if defined?(@_unboundable)
          @_unboundable
        else
          value_for_database unless value_before_type_cast.is_a?(StatementCache::Substitute)
          @_unboundable = nil
        end
      rescue ::RangeError
        @_unboundable = type.cast(value_before_type_cast) <=> 0
      end

      private
        def infinity?(value)
          value.respond_to?(:infinite?) && value.infinite?
        end
    end
  end
end

Version data entries

75 entries across 75 versions & 7 rubygems

Version Path
activerecord-6.1.7.10 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.9 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.8 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.7 lib/active_record/relation/query_attribute.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.6 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.5 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.4 lib/active_record/relation/query_attribute.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.3 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.2 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7.1 lib/active_record/relation/query_attribute.rb
activerecord-6.0.6.1 lib/active_record/relation/query_attribute.rb
activerecord-6.1.7 lib/active_record/relation/query_attribute.rb
activerecord-6.0.6 lib/active_record/relation/query_attribute.rb
activerecord-6.1.6.1 lib/active_record/relation/query_attribute.rb
activerecord-6.0.5.1 lib/active_record/relation/query_attribute.rb
activerecord-6.0.5 lib/active_record/relation/query_attribute.rb
activerecord-6.1.6 lib/active_record/relation/query_attribute.rb
activerecord-6.1.5.1 lib/active_record/relation/query_attribute.rb