activerecord-postgis-adapter 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb +7 -1
- data/lib/active_record/connection_adapters/postgis_adapter/create_connection.rb +27 -16
- data/lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb +7 -1
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +1 -1
- data/test/ddl_test.rb +46 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfce80e5cc8bb5ad34d51937326e5f9a2037e207
|
4
|
+
data.tar.gz: d3ce8ba42c544093651afcd799d717aa10f76625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b79c9d7807b857a6f408495a34714106e3bcbd0b9d4578655abd51abbb53463af920971a7e4f712632df82521708467d8e5b28023e3cd4a8e90ac3fb0caf18a
|
7
|
+
data.tar.gz: 3c5f7672e35341ac23bf39c57fa031e9d0f335b93bb954fe593d5595bff3cd19971811d562ae6ff3b2534823da026b2a55b1fd7cfef95413671ea70ce4b20a95
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Arel # :nodoc:
|
2
2
|
module Visitors # :nodoc:
|
3
|
+
# Different super-class under JRuby JDBC adapter.
|
4
|
+
PostGISSuperclass = if defined?(::ArJdbc::PostgreSQL::BindSubstitution)
|
5
|
+
::ArJdbc::PostgreSQL::BindSubstitution
|
6
|
+
else
|
7
|
+
::Arel::Visitors::PostgreSQL
|
8
|
+
end
|
3
9
|
|
4
|
-
class PostGIS <
|
10
|
+
class PostGIS < PostGISSuperclass # :nodoc:
|
5
11
|
|
6
12
|
FUNC_MAP = {
|
7
13
|
'st_wkttosql' => 'ST_GeomFromEWKT',
|
@@ -1,26 +1,37 @@
|
|
1
|
-
|
1
|
+
if(defined?(::RUBY_ENGINE) && ::RUBY_ENGINE == 'jruby')
|
2
|
+
require 'active_record/connection_adapters/jdbcpostgresql_adapter'
|
3
|
+
else
|
4
|
+
require 'pg'
|
5
|
+
end
|
2
6
|
|
3
7
|
module ActiveRecord # :nodoc:
|
4
8
|
module ConnectionHandling # :nodoc:
|
9
|
+
if(defined?(::RUBY_ENGINE) && ::RUBY_ENGINE == 'jruby')
|
10
|
+
def postgis_connection(config)
|
11
|
+
config[:adapter_class] = ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter
|
12
|
+
postgresql_connection(config)
|
13
|
+
end
|
14
|
+
alias_method :jdbcpostgis_connection, :postgis_connection
|
15
|
+
else
|
16
|
+
# Based on the default <tt>postgresql_connection</tt> definition from ActiveRecord.
|
17
|
+
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
|
18
|
+
def postgis_connection(config)
|
19
|
+
# FULL REPLACEMENT because we need to create a different class.
|
20
|
+
conn_params = config.symbolize_keys
|
5
21
|
|
6
|
-
|
7
|
-
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
|
8
|
-
def postgis_connection(config)
|
9
|
-
# FULL REPLACEMENT because we need to create a different class.
|
10
|
-
conn_params = config.symbolize_keys
|
11
|
-
|
12
|
-
conn_params.delete_if { |_, v| v.nil? }
|
22
|
+
conn_params.delete_if { |_, v| v.nil? }
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
# Map ActiveRecords param names to PGs.
|
25
|
+
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
26
|
+
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
17
27
|
|
18
|
-
|
19
|
-
|
28
|
+
# Forward only valid config params to PGconn.connect.
|
29
|
+
conn_params.keep_if { |k, _| VALID_CONN_PARAMS.include?(k) }
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
# The postgres drivers don't allow the creation of an unconnected PGconn object,
|
32
|
+
# so just pass a nil connection object for the time being.
|
33
|
+
::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, conn_params, config)
|
34
|
+
end
|
24
35
|
end
|
25
36
|
|
26
37
|
end
|
@@ -34,6 +34,12 @@ module ActiveRecord # :nodoc:
|
|
34
34
|
column_info = SpatialColumnInfo.new(self, quote_string(table_name.to_s))
|
35
35
|
# Limit, precision, and scale are all handled by the superclass.
|
36
36
|
column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod|
|
37
|
+
# JDBC gets true/false in Rails 4, where other platforms get
|
38
|
+
# 't'/'f' strings.
|
39
|
+
if(notnull.is_a?(String))
|
40
|
+
notnull = (notnull == 't')
|
41
|
+
end
|
42
|
+
|
37
43
|
oid = column_type_map.fetch(oid.to_i, fmod.to_i) { OID::Identity.new }
|
38
44
|
SpatialColumn.new(@rgeo_factory_settings,
|
39
45
|
table_name,
|
@@ -41,7 +47,7 @@ module ActiveRecord # :nodoc:
|
|
41
47
|
default,
|
42
48
|
oid,
|
43
49
|
type,
|
44
|
-
notnull
|
50
|
+
!notnull,
|
45
51
|
column_info.get(column_name, type))
|
46
52
|
end
|
47
53
|
end
|
data/test/ddl_test.rb
CHANGED
@@ -247,6 +247,52 @@ class DDLTest < ActiveSupport::TestCase # :nodoc:
|
|
247
247
|
assert_nil klass.columns[1].has_z
|
248
248
|
end
|
249
249
|
|
250
|
+
# Ensure that null contraints info is getting captured like the
|
251
|
+
# normal adapter.
|
252
|
+
def test_null_constraints
|
253
|
+
klass_ = create_ar_class
|
254
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
255
|
+
t_.column 'nulls_allowed', :string, :null => true
|
256
|
+
t_.column 'nulls_disallowed', :string, :null => false
|
257
|
+
end
|
258
|
+
assert_equal(true, klass_.columns[-2].null)
|
259
|
+
assert_equal(false, klass_.columns[-1].null)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Ensure that default value info is getting captured like the
|
263
|
+
# normal adapter.
|
264
|
+
def test_column_defaults
|
265
|
+
klass_ = create_ar_class
|
266
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
267
|
+
t_.column 'sample_integer_neg_default', :integer, :default => -1
|
268
|
+
end
|
269
|
+
assert_equal(-1, klass_.columns.last.default)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Ensure that column type info is getting captured like the
|
273
|
+
# normal adapter.
|
274
|
+
def test_column_types
|
275
|
+
klass_ = create_ar_class
|
276
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
277
|
+
t_.column 'sample_integer', :integer
|
278
|
+
t_.column 'sample_string', :string
|
279
|
+
t_.column 'latlon', :point
|
280
|
+
end
|
281
|
+
assert_equal(:integer, klass_.columns[-3].type)
|
282
|
+
assert_equal(:string, klass_.columns[-2].type)
|
283
|
+
assert_equal(:spatial, klass_.columns[-1].type)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_array_columns
|
287
|
+
klass_ = create_ar_class
|
288
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
289
|
+
t_.column 'sample_array', :string, :array => true
|
290
|
+
t_.column 'sample_non_array', :string
|
291
|
+
end
|
292
|
+
assert_equal(true, klass_.columns[-2].array)
|
293
|
+
assert_equal(false, klass_.columns[-1].array)
|
294
|
+
end
|
295
|
+
|
250
296
|
private
|
251
297
|
|
252
298
|
def geometry_column_count_query
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
69
83
|
description: ActiveRecord connection adapter for PostGIS. It is based on the stock
|
70
84
|
PostgreSQL adapter, but provides built-in support for the spatial extensions provided
|
71
85
|
by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
|
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
132
|
version: '0'
|
119
133
|
requirements: []
|
120
134
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.4.1
|
122
136
|
signing_key:
|
123
137
|
specification_version: 4
|
124
138
|
summary: ActiveRecord adapter for PostGIS, based on RGeo.
|