edge badge
Methods
C
E
I
N
T
Attributes
[R] subtype
[R] type
Class Public methods
new(subtype, type)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 8
def initialize(subtype, type)
  @subtype = subtype
  @type = type
end
Instance Public methods
cast_value(value)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 35
          def cast_value(value)
            return if value == 'empty'
            return value if value.is_a?(::Range)

            extracted = extract_bounds(value)
            from = type_cast_single extracted[:from]
            to = type_cast_single extracted[:to]

            if !infinity?(from) && extracted[:exclude_start]
              if from.respond_to?(:succ)
                from = from.succ
                ActiveSupport::Deprecation.warn <<-MESSAGE
Excluding the beginning of a Range is only partialy supported through `#succ`.
This is not reliable and will be removed in the future.
                MESSAGE
              else
                raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
              end
            end
            ::Range.new(from, to, extracted[:exclude_end])
          end
extract_bounds(value)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 13
def extract_bounds(value)
  from, to = value[1..-2].split(',')
  {
    from:          (value[1] == ',' || from == '-infinity') ? @subtype.infinity(negative: true) : from,
    to:            (value[-2] == ',' || to == 'infinity') ? @subtype.infinity : to,
    exclude_start: (value[0] == '('),
    exclude_end:   (value[-1] == ')')
  }
end
infinity?(value)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 23
def infinity?(value)
  value.respond_to?(:infinite?) && value.infinite?
end
type_cast_for_schema(value)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 27
def type_cast_for_schema(value)
  value.inspect.gsub('Infinity', '::Float::INFINITY')
end
type_cast_single(value)
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb, line 31
def type_cast_single(value)
  infinity?(value) ? value : @subtype.type_cast_from_database(value)
end