Class: ActiveRecord::ConnectionAdapters::PostGIS::Column

Inherits:
PostgreSQL::Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgis/column.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cast_type, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, serial: nil, generated: nil, spatial: nil, identity: nil) ⇒ Column

sql_type examples:

"Geometry(Point,4326)"
"Geography(Point,4326)"


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 10

def initialize(name, cast_type, default,  = nil, null = true,
               default_function = nil, collation: nil, comment: nil,
               serial: nil, generated: nil, spatial: nil, identity: nil)
  super(name, cast_type, default, , null, default_function,
        collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
  @geographic = !!(.sql_type =~ /geography\(/i)
  if spatial
    # This case comes from an entry in the geometry_columns table
    set_geometric_type_from_name(spatial[:type])
    @srid = spatial[:srid].to_i
    @has_z = !!spatial[:has_z]
    @has_m = !!spatial[:has_m]
  elsif @geographic
    # Geographic type information is embedded in the SQL type
    @srid = 4326
    @has_z = @has_m = false
    build_from_sql_type(.sql_type)
  elsif sql_type =~ /geography|geometry|point|linestring|polygon/i
    build_from_sql_type(.sql_type)
  elsif .sql_type =~ /geography|geometry|point|linestring|polygon/i
    # A geometry column with no geometry_columns entry.
    # @geometric_type = geo_type_from_sql_type(sql_type)
    build_from_sql_type(.sql_type)
  end
  if spatial? && @srid
    @limit = { srid: @srid, type: to_type_name(geometric_type) }
    @limit[:has_z] = true if @has_z
    @limit[:has_m] = true if @has_m
    @limit[:geographic] = true if @geographic
  end
end

Instance Attribute Details

#geographicObject (readonly) Also known as: geographic?

Returns the value of attribute geographic.



42
43
44
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 42

def geographic
  @geographic
end

#geometric_typeObject (readonly)

Returns the value of attribute geometric_type.



42
43
44
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 42

def geometric_type
  @geometric_type
end

#has_mObject (readonly) Also known as: has_m?

Returns the value of attribute has_m.



42
43
44
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 42

def has_m
  @has_m
end

#has_zObject (readonly) Also known as: has_z?

Returns the value of attribute has_z.



42
43
44
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 42

def has_z
  @has_z
end

#sridObject (readonly)

Returns the value of attribute srid.



42
43
44
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 42

def srid
  @srid
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



80
81
82
83
84
85
86
87
88
89
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 80

def ==(other)
  other.is_a?(Column) &&
    super &&
    other.geographic == geographic &&
    other.geometric_type == geometric_type &&
    other.has_m == has_m &&
    other.has_z == has_z &&
    other.srid == srid &&
    other.limit == limit
end

#encode_with(coder) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 70

def encode_with(coder)
  coder["geographic"] = @geographic
  coder["geometric_type"] = @geometric_type
  coder["has_m"] = @has_m
  coder["has_z"] = @has_z
  coder["srid"] = @srid
  coder["limit"] = @limit
  super
end

#hashObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 92

def hash
  Column.hash ^
    super.hash ^
    geographic.hash ^
    geometric_type.hash ^
    has_m.hash ^
    has_z.hash ^
    srid.hash ^
    limit.hash
end

#init_with(coder) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 60

def init_with(coder)
  @geographic = coder["geographic"]
  @geometric_type = coder["geometric_type"]
  @has_m = coder["has_m"]
  @has_z = coder["has_z"]
  @srid = coder["srid"]
  @limit = coder["limit"]
  super
end

#limitObject



52
53
54
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 52

def limit
  spatial? ? @limit : super
end

#spatial?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/active_record/connection_adapters/postgis/column.rb', line 56

def spatial?
  %i[geometry geography].include?(@sql_type_metadata.type)
end