activerecord-postgis-adapter 7.0.1 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis/create_connection.rb +4 -0
- data/lib/active_record/connection_adapters/postgis/databases.rake +1 -1
- data/lib/active_record/connection_adapters/postgis/oid/spatial.rb +14 -15
- data/lib/active_record/connection_adapters/postgis/schema_statements.rb +9 -2
- data/lib/active_record/connection_adapters/postgis/spatial_column.rb +1 -1
- data/lib/active_record/connection_adapters/postgis/type.rb +22 -0
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +35 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcaaf2a57395c122e6541b1e40bd416f5f31fd1e512c250e5222ec5bb3feb650
|
4
|
+
data.tar.gz: 2772452b3ea880ecab759cb5add73d2ed22a89a78e12eae087aff60a061a8f20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743b335ad32f5d872eebd7c512d7557102ed137664e4336a8c26154fe5f3b2bc3ded2b8e0ebe73195e05e8bb9affb538f7dde93e2aa095b142078e464c2fed98
|
7
|
+
data.tar.gz: 8cfc035141871044857863337a94f4c854423afc784f305853cd1a838dde14ec729a941c50a14edc5841829e8c21ce8c4f04c1826611ecb853d8239fb95401f4
|
@@ -10,7 +10,11 @@ module ActiveRecord # :nodoc:
|
|
10
10
|
module ConnectionHandling # :nodoc:
|
11
11
|
if RUBY_ENGINE == "jruby"
|
12
12
|
|
13
|
+
# modified from https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/connection_methods.rb#L3
|
13
14
|
def postgis_connection(config)
|
15
|
+
config = config.deep_dup
|
16
|
+
config = symbolize_keys_if_necessary(config)
|
17
|
+
|
14
18
|
config[:adapter_class] = ConnectionAdapters::PostGISAdapter
|
15
19
|
postgresql_connection(config)
|
16
20
|
end
|
@@ -9,7 +9,7 @@ namespace :db do
|
|
9
9
|
environments.each do |environment|
|
10
10
|
ActiveRecord::Base.configurations
|
11
11
|
.configs_for(env_name: environment)
|
12
|
-
.reject { |env| env.configuration_hash[
|
12
|
+
.reject { |env| env.configuration_hash[:database].blank? }
|
13
13
|
.each do |env|
|
14
14
|
ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(env).setup_gis
|
15
15
|
end
|
@@ -4,16 +4,17 @@ module ActiveRecord
|
|
4
4
|
module ConnectionAdapters
|
5
5
|
module PostGIS
|
6
6
|
module OID
|
7
|
+
# OID used to represent geometry/geography database types and attributes.
|
8
|
+
#
|
9
|
+
# Accepts `geo_type`, `srid`, `has_z`, `has_m`, and `geographic` as parameters.
|
10
|
+
# Responsible for parsing sql_types returned from the database and WKT features.
|
7
11
|
class Spatial < Type::Value
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(oid, sql_type)
|
15
|
-
@sql_type = sql_type
|
16
|
-
@geo_type, @srid, @has_z, @has_m = self.class.parse_sql_type(sql_type)
|
12
|
+
def initialize(geo_type: 'geometry', srid: 0, has_z: false, has_m: false, geographic: false)
|
13
|
+
@geo_type = geo_type
|
14
|
+
@srid = srid
|
15
|
+
@has_z = has_z
|
16
|
+
@has_m = has_m
|
17
|
+
@geographic = geographic
|
17
18
|
end
|
18
19
|
|
19
20
|
# sql_type: geometry, geometry(Point), geometry(Point,4326), ...
|
@@ -43,7 +44,9 @@ module ActiveRecord
|
|
43
44
|
# otherType(a,b)
|
44
45
|
geo_type = sql_type
|
45
46
|
end
|
46
|
-
|
47
|
+
geographic = sql_type.match?(/geography/)
|
48
|
+
|
49
|
+
[geo_type, srid, has_z, has_m, geographic]
|
47
50
|
end
|
48
51
|
|
49
52
|
def spatial_factory
|
@@ -53,16 +56,12 @@ module ActiveRecord
|
|
53
56
|
)
|
54
57
|
end
|
55
58
|
|
56
|
-
def geographic?
|
57
|
-
@sql_type =~ /geography/
|
58
|
-
end
|
59
|
-
|
60
59
|
def spatial?
|
61
60
|
true
|
62
61
|
end
|
63
62
|
|
64
63
|
def type
|
65
|
-
geographic
|
64
|
+
@geographic ? :geography : :geometry
|
66
65
|
end
|
67
66
|
|
68
67
|
# support setting an RGeo object or a WKT string
|
@@ -96,8 +96,15 @@ module ActiveRecord
|
|
96
96
|
st_point
|
97
97
|
st_polygon
|
98
98
|
).each do |geo_type|
|
99
|
-
map.register_type(geo_type) do |
|
100
|
-
|
99
|
+
map.register_type(geo_type) do |_, _, sql_type|
|
100
|
+
# sql_type is a string that comes from the database definition
|
101
|
+
# examples:
|
102
|
+
# "geometry(Point,4326)"
|
103
|
+
# "geography(Point,4326)"
|
104
|
+
# "geometry(Polygon,4326) NOT NULL"
|
105
|
+
# "geometry(Geography,4326)"
|
106
|
+
geo_type, srid, has_z, has_m, geographic = OID::Spatial.parse_sql_type(sql_type)
|
107
|
+
OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
|
101
108
|
end
|
102
109
|
end
|
103
110
|
|
@@ -67,7 +67,7 @@ module ActiveRecord # :nodoc:
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def build_from_sql_type(sql_type)
|
70
|
-
geo_type, @srid, @has_z, @has_m = OID::Spatial.parse_sql_type(sql_type)
|
70
|
+
geo_type, @srid, @has_z, @has_m, @geographic = OID::Spatial.parse_sql_type(sql_type)
|
71
71
|
set_geometric_type_from_name(geo_type)
|
72
72
|
end
|
73
73
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module PostGIS
|
6
|
+
module Type
|
7
|
+
# Look for :postgis types first, then check for :postgresql
|
8
|
+
# types to simulate a kind of Type inheritance.
|
9
|
+
def lookup(*args, adapter: current_adapter_name, **kwargs)
|
10
|
+
super(*args, adapter: adapter, **kwargs)
|
11
|
+
rescue ArgumentError => e
|
12
|
+
raise e unless current_adapter_name == :postgis
|
13
|
+
|
14
|
+
super(*args, adapter: :postgresql, **kwargs)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Type uses `class << self` syntax so we have to prepend to the singleton_class
|
21
|
+
Type.singleton_class.prepend(ActiveRecord::ConnectionAdapters::PostGIS::Type)
|
22
|
+
end
|
@@ -18,6 +18,7 @@ require "active_record/connection_adapters/postgis/spatial_column"
|
|
18
18
|
require "active_record/connection_adapters/postgis/arel_tosql"
|
19
19
|
require "active_record/connection_adapters/postgis/setup"
|
20
20
|
require "active_record/connection_adapters/postgis/oid/spatial"
|
21
|
+
require "active_record/connection_adapters/postgis/type" # has to be after oid/*
|
21
22
|
require "active_record/connection_adapters/postgis/create_connection"
|
22
23
|
require "active_record/connection_adapters/postgis/postgis_database_tasks"
|
23
24
|
|
@@ -32,7 +33,7 @@ end
|
|
32
33
|
module ActiveRecord
|
33
34
|
module ConnectionAdapters
|
34
35
|
class PostGISAdapter < PostgreSQLAdapter
|
35
|
-
ADAPTER_NAME = 'PostGIS'
|
36
|
+
ADAPTER_NAME = 'PostGIS'
|
36
37
|
|
37
38
|
SPATIAL_COLUMN_OPTIONS =
|
38
39
|
{
|
@@ -87,6 +88,39 @@ module ActiveRecord
|
|
87
88
|
super
|
88
89
|
end
|
89
90
|
end
|
91
|
+
|
92
|
+
# PostGIS specific types
|
93
|
+
[
|
94
|
+
:geography,
|
95
|
+
:geometry,
|
96
|
+
:geometry_collection,
|
97
|
+
:line_string,
|
98
|
+
:multi_line_string,
|
99
|
+
:multi_point,
|
100
|
+
:multi_polygon,
|
101
|
+
:st_point,
|
102
|
+
:st_polygon,
|
103
|
+
].each do |geo_type|
|
104
|
+
ActiveRecord::Type.register(geo_type, PostGIS::OID::Spatial, adapter: :postgis)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# if using JRUBY, create ArJdbc::PostGIS module
|
111
|
+
# and prepend it to the PostgreSQL adapter since
|
112
|
+
# it is the default adapter_spec.
|
113
|
+
# see: https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/adapter.rb#27
|
114
|
+
if RUBY_ENGINE == "jruby"
|
115
|
+
module ArJdbc
|
116
|
+
module PostGIS
|
117
|
+
ADAPTER_NAME = 'PostGIS'
|
118
|
+
|
119
|
+
def adapter_name
|
120
|
+
ADAPTER_NAME
|
121
|
+
end
|
90
122
|
end
|
91
123
|
end
|
124
|
+
|
125
|
+
ArJdbc::PostgreSQL.prepend(ArJdbc::PostGIS)
|
92
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/active_record/connection_adapters/postgis/spatial_column.rb
|
120
120
|
- lib/active_record/connection_adapters/postgis/spatial_column_info.rb
|
121
121
|
- lib/active_record/connection_adapters/postgis/spatial_table_definition.rb
|
122
|
+
- lib/active_record/connection_adapters/postgis/type.rb
|
122
123
|
- lib/active_record/connection_adapters/postgis/version.rb
|
123
124
|
- lib/active_record/connection_adapters/postgis_adapter.rb
|
124
125
|
- lib/activerecord-postgis-adapter.rb
|