Class: ActiveRecord::ConnectionAdapters::Mysql2Rgeo::SpatialColumn

Inherits:
ConnectionAdapters::MySQL::Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, spatial: nil) ⇒ SpatialColumn

Returns a new instance of SpatialColumn.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 7

def initialize(name, default,  = nil, null = true, default_function = nil, collation: nil, comment: nil, spatial: nil, **)
  @sql_type_metadata = 
  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
  elsif sql_type =~ /geometry|point|linestring|polygon/i
    build_from_sql_type(.sql_type)
  elsif .sql_type =~ /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
  super(name, default, , null, default_function, collation: collation, comment: comment)
  if spatial?
    if @srid
      @limit = { type: @geometric_type.type_name.underscore, srid: @srid }
    end
  end
end

Instance Attribute Details

#geometric_typeObject (readonly)

Returns the value of attribute geometric_type.



28
29
30
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 28

def geometric_type
  @geometric_type
end

#sridObject (readonly)

Returns the value of attribute srid.



28
29
30
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 28

def srid
  @srid
end

Instance Method Details

#geographicObject Also known as: geographic?



38
39
40
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 38

def geographic
  false
end

#has_mObject Also known as: has_m?



34
35
36
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 34

def has_m
  false
end

#has_zObject Also known as: has_z?



30
31
32
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 30

def has_z
  false
end

#klassObject



54
55
56
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 54

def klass
  type == :spatial ? RGeo::Feature::Geometry : super
end

#limitObject



46
47
48
49
50
51
52
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 46

def limit
  if spatial?
    @limit
  else
    super
  end
end

#multi?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 62

def multi?
  /^(geometrycollection|multi)/i.match?(sql_type)
end

#spatial?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb', line 58

def spatial?
  !@geometric_type.nil?
end