Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subtype, type = :range) ⇒ Range

Returns a new instance of Range.



11
12
13
14
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 11

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

Instance Attribute Details

#subtypeObject (readonly)

Returns the value of attribute subtype



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

def subtype
  @subtype
end

#typeObject (readonly)

Returns the value of attribute type



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

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 44

def ==(other)
  other.is_a?(Range) &&
    other.subtype == subtype &&
    other.type == type
end

#cast_value(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 20

def cast_value(value)
  return if value == "empty"
  return value unless value.is_a?(::String)

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

  if !infinity?(from) && extracted[:exclude_start]
    raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
  end
  ::Range.new(*sanitize_bounds(from, to), extracted[:exclude_end])
end

#force_equality?(value) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 56

def force_equality?(value)
  value.is_a?(::Range)
end

#map(value) ⇒ Object

:nodoc:



50
51
52
53
54
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 50

def map(value) # :nodoc:
  new_begin = yield(value.begin)
  new_end = yield(value.end)
  ::Range.new(new_begin, new_end, value.exclude_end?)
end

#serialize(value) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 34

def serialize(value)
  if value.is_a?(::Range)
    from = type_cast_single_for_database(value.begin)
    to = type_cast_single_for_database(value.end)
    ::Range.new(from, to, value.exclude_end?)
  else
    super
  end
end

#type_cast_for_schema(value) ⇒ Object



16
17
18
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 16

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