Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Rails51Point

Inherits:
Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ActiveModel::Type::Helpers::Mutable

#changed_in_place?

Instance Method Details

#cast(value) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb', line 14

def cast(value)
  case value
  when ::String
    if value[0] == '(' && value[-1] == ')'
      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


29
30
31
32
33
34
35
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb', line 29

def serialize(value)
  if value.is_a?(ActiveRecord::Point)
    "(#{number_for_point(value.x)},#{number_for_point(value.y)})"
  else
    super
  end
end

#typeObject


10
11
12
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb', line 10

def type
  :point
end