Class: ActiveRecord::ConnectionAdapters::Redshift::OID::Range

Inherits:
Type::Value
  • Object
show all
Defined in:
lib/active_record/connection_adapters/redshift/oid/range.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subtype, type) ⇒ Range

Returns a new instance of Range.



8
9
10
11
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 8

def initialize(subtype, type)
  @subtype = subtype
  @type = type
end

Instance Attribute Details

#subtypeObject (readonly)

Returns the value of attribute subtype.



6
7
8
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 6

def subtype
  @subtype
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 6

def type
  @type
end

Instance Method Details

#cast_value(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 17

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 \
        "Excluding the beginning of a Range is only partialy supported " \
        "through `#succ`. This is not reliable and will be removed in " \
        "the future."
    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

#type_cast_for_database(value) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 39

def type_cast_for_database(value)
  if value.is_a?(::Range)
    from = type_cast_single_for_database(value.begin)
    to = type_cast_single_for_database(value.end)
    "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}"
  else
    super
  end
end

#type_cast_for_schema(value) ⇒ Object



13
14
15
# File 'lib/active_record/connection_adapters/redshift/oid/range.rb', line 13

def type_cast_for_schema(value)
  value.inspect.gsub('Infinity', '::Float::INFINITY')
end