Class: ActiveRecord::ConnectionAdapters::CipherStashPG::OID::Point

Inherits:
Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb,
lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/point.rb,
lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/point.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb', line 16

def cast(value)
  case value
  when ::String
    return if value.blank?

    if value.start_with?("(") && value.end_with?(")")
      value = value[1...-1]
    end
    x, y = value.split(",")
    build_point(x, y)
  when ::Array
    build_point(*value)
  else
    value
  end
end

#serialize(value) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb', line 33

def serialize(value)
  if quacks_like_a_point?(value)
    "(#{number_for_point(value.x)},#{number_for_point(value.y)})"
  elsif ::Array == value
    serialize(build_point(*value))
  else
    super
  end
end

#typeObject



12
13
14
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb', line 12

def type
  :point
end

#type_cast_for_schema(value) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb', line 43

def type_cast_for_schema(value)
  if quacks_like_a_point?(value)
    [value.x, value.y]
  else
    super
  end
end