activerecord-postgis-adapter 5.2.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a36aaf405da9a1fd4cc773af8bd16504dfbc482ca2c80f0a5a941fbf1d428b7f
4
- data.tar.gz: 85fde301aa11100d590e24614b9598f5e5376f2e14a9878277c81d68754484b2
3
+ metadata.gz: bb1e1b34ad600caf80e784c5ed95979d2712fe102d7845814d7258cec6605425
4
+ data.tar.gz: 6c9dcf403ec396a9482a9d88a02fd4282d6c9c50fbcc84d2581927f2bbf570d0
5
5
  SHA512:
6
- metadata.gz: a07174891bc9836f90b1118cf21fe5a400c71f05d42ca19e7efd8c707b2f40632cdc83b0150c0823525f98d498849516b532e21c6105445b30b3ea0411bf74d0
7
- data.tar.gz: 4ecaee8b53358240ecb2d07a2b0665179bb6735f19ccb2d532c4ac5d2c4801a6ed946ccde69a0c13dccca5d7ce9900f6ced77a48345f398ca9cbe0c6ec6bb4ed
6
+ metadata.gz: be97e239ddd7b98c4b96616e456250c2ef624bf33517e02623d69ac1a4f94f64f46ecc1e0bf16afd5c036e36e6b3cba68f872ad261ebce44ef07a3b1661b21b5
7
+ data.tar.gz: 48d54259d8027b81ad8419bef0d66b1f73fa5145df8dd001bab340049b28c331bf7474f3614076b9de2f0626fc80a3da19cd1267519e9857b4f19d93008e416d
@@ -1,3 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RGeo
4
+ module ActiveRecord
5
+ ##
6
+ # Extend rgeo-activerecord visitors to use PostGIS specific functionality
7
+ module SpatialToPostGISSql
8
+ def visit_in_spatial_context(node, collector)
9
+ # Use ST_GeomFromEWKT for EWKT geometries
10
+ if node.is_a?(String) && node =~ /SRID=[\d+]{0,};/
11
+ collector << "#{st_func('ST_GeomFromEWKT')}(#{quote(node)})"
12
+ else
13
+ super(node, collector)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ RGeo::ActiveRecord::SpatialToSql.prepend RGeo::ActiveRecord::SpatialToPostGISSql
20
+
1
21
  module Arel # :nodoc:
2
22
  module Visitors # :nodoc:
3
23
  # Different super-class under JRuby JDBC adapter.
@@ -9,22 +29,6 @@ module Arel # :nodoc:
9
29
 
10
30
  class PostGIS < PostGISSuperclass # :nodoc:
11
31
  include RGeo::ActiveRecord::SpatialToSql
12
-
13
- FUNC_MAP = {
14
- "st_wkttosql" => "ST_GeomFromEWKT",
15
- }
16
-
17
- def st_func(standard_name)
18
- FUNC_MAP[standard_name.downcase] || standard_name
19
- end
20
-
21
- def visit_String(node, collector)
22
- collector << "#{st_func('ST_WKTToSQL')}(#{quote(node)})"
23
- end
24
-
25
- def visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector)
26
- aggregate(st_func(node.name), node, collector)
27
- end
28
32
  end
29
33
  end
30
34
  end
@@ -1,46 +1,48 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module PostGIS
4
6
  module ColumnMethods
5
7
  def spatial(name, options = {})
6
8
  raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
7
- column(name, options[:type], options)
9
+ column(name, options[:type], **options)
8
10
  end
9
11
 
10
12
  def geography(name, options = {})
11
- column(name, :geography, options)
13
+ column(name, :geography, **options)
12
14
  end
13
15
 
14
16
  def geometry(name, options = {})
15
- column(name, :geometry, options)
17
+ column(name, :geometry, **options)
16
18
  end
17
19
 
18
20
  def geometry_collection(name, options = {})
19
- column(name, :geometry_collection, options)
21
+ column(name, :geometry_collection, **options)
20
22
  end
21
23
 
22
24
  def line_string(name, options = {})
23
- column(name, :line_string, options)
25
+ column(name, :line_string, **options)
24
26
  end
25
27
 
26
28
  def multi_line_string(name, options = {})
27
- column(name, :multi_line_string, options)
29
+ column(name, :multi_line_string, **options)
28
30
  end
29
31
 
30
32
  def multi_point(name, options = {})
31
- column(name, :multi_point, options)
33
+ column(name, :multi_point, **options)
32
34
  end
33
35
 
34
36
  def multi_polygon(name, options = {})
35
- column(name, :multi_polygon, options)
37
+ column(name, :multi_polygon, **options)
36
38
  end
37
39
 
38
40
  def st_point(name, options = {})
39
- column(name, :st_point, options)
41
+ column(name, :st_point, **options)
40
42
  end
41
43
 
42
44
  def st_polygon(name, options = {})
43
- column(name, :st_polygon, options)
45
+ column(name, :st_polygon, **options)
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if RUBY_ENGINE == "jruby"
2
4
  require "active_record/connection_adapters/jdbcpostgresql_adapter"
3
5
  else
@@ -21,21 +23,22 @@ module ActiveRecord # :nodoc:
21
23
  # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
22
24
  # FULL REPLACEMENT because we need to create a different class.
23
25
  def postgis_connection(config)
24
- conn_params = config.symbolize_keys
25
-
26
- conn_params.delete_if { |_, v| v.nil? }
26
+ conn_params = config.symbolize_keys.compact
27
27
 
28
28
  # Map ActiveRecords param names to PGs.
29
29
  conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
30
30
  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
31
31
 
32
- # Forward only valid config params to PGconn.connect.
32
+ # Forward only valid config params to PG.connect
33
33
  valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
34
34
  conn_params.slice!(*valid_conn_param_keys)
35
35
 
36
- # The postgres drivers don't allow the creation of an unconnected PGconn object,
37
- # so just pass a nil connection object for the time being.
38
- ConnectionAdapters::PostGISAdapter.new(nil, logger, conn_params, config)
36
+ ConnectionAdapters::PostGISAdapter.new(
37
+ ConnectionAdapters::PostGISAdapter.new_client(conn_params),
38
+ logger,
39
+ conn_params,
40
+ config
41
+ )
39
42
  end
40
43
 
41
44
  end
@@ -1,16 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :db do
2
4
  namespace :gis do
3
5
  desc "Setup PostGIS data in the database"
4
6
  task setup: [:load_config] do
5
7
  environments = [Rails.env]
6
8
  environments << "test" if Rails.env.development?
7
- ActiveRecord::Base.configurations
8
- .values_at(*environments)
9
- .compact
10
- .reject { |config| config["database"].blank? }
11
- .each do |config|
12
- ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(config).setup_gis
13
- end
9
+ environments.each do |environment|
10
+ ActiveRecord::Base.configurations
11
+ .configs_for(env_name: environment)
12
+ .reject { |env| env.config["database"].blank? }
13
+ .each do |env|
14
+ ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(env.config).setup_gis
15
+ end
16
+ end
14
17
  end
15
18
  end
16
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module PostGIS
@@ -25,23 +27,20 @@ module ActiveRecord
25
27
  geo_type, srid, has_z, has_m = nil, 0, false, false
26
28
 
27
29
  if sql_type =~ /(geography|geometry)\((.*)\)$/i
30
+ # geometry(Point)
28
31
  # geometry(Point,4326)
29
32
  params = Regexp.last_match(2).split(",")
30
- if params.size > 1
31
- if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
32
- has_z = Regexp.last_match(2).length > 0
33
- has_m = Regexp.last_match(3).length > 0
34
- geo_type = Regexp.last_match(1)
35
- end
36
- if params.last =~ /(\d+)/
37
- srid = Regexp.last_match(1).to_i
38
- end
39
- else
40
- # geometry(Point)
41
- geo_type = params[0]
33
+ if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
34
+ has_z = Regexp.last_match(2).length > 0
35
+ has_m = Regexp.last_match(3).length > 0
36
+ geo_type = Regexp.last_match(1)
37
+ end
38
+ if params.last =~ /(\d+)/
39
+ srid = Regexp.last_match(1).to_i
42
40
  end
43
41
  else
44
42
  # geometry
43
+ # otherType(a,b)
45
44
  geo_type = sql_type
46
45
  end
47
46
  [geo_type, srid, has_z, has_m]
@@ -50,11 +49,7 @@ module ActiveRecord
50
49
  def spatial_factory
51
50
  @spatial_factory ||=
52
51
  RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
53
- geo_type: @geo_type,
54
- has_m: @has_m,
55
- has_z: @has_z,
56
- sql_type: @sql_type,
57
- srid: @srid
52
+ factory_attrs
58
53
  )
59
54
  end
60
55
 
@@ -108,6 +103,16 @@ module ActiveRecord
108
103
  RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
109
104
  end
110
105
  end
106
+
107
+ def factory_attrs
108
+ {
109
+ geo_type: @geo_type.underscore,
110
+ has_m: @has_m,
111
+ has_z: @has_z,
112
+ srid: @srid,
113
+ sql_type: type.to_s
114
+ }
115
+ end
111
116
  end
112
117
  end
113
118
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS # :nodoc:
4
6
  class PostGISDatabaseTasks < ::ActiveRecord::Tasks::PostgreSQLDatabaseTasks # :nodoc:
5
- def initialize(config)
7
+ def initialize(db_config)
6
8
  super
7
9
  ensure_installation_configs
8
10
  end
@@ -12,19 +14,19 @@ module ActiveRecord # :nodoc:
12
14
  if extension_names
13
15
  setup_gis_from_extension
14
16
  end
15
- establish_connection(configuration)
17
+ establish_connection(db_config)
16
18
  end
17
19
 
18
20
  # Override to set the database owner and call setup_gis
19
21
  def create(master_established = false)
20
22
  establish_master_connection unless master_established
21
- extra_configs = { "encoding" => encoding }
22
- extra_configs["owner"] = username if has_su?
23
- connection.create_database(configuration["database"], configuration.merge(extra_configs))
23
+ extra_configs = { encoding: encoding }
24
+ extra_configs[:owner] = username if has_su?
25
+ connection.create_database(db_config.database, configuration_hash.merge(extra_configs))
24
26
  setup_gis
25
27
  rescue ::ActiveRecord::StatementInvalid => error
26
28
  if /database .* already exists/ === error.message
27
- raise ::ActiveRecord::Tasks::DatabaseAlreadyExists
29
+ raise ::ActiveRecord::DatabaseAlreadyExists
28
30
  else
29
31
  raise
30
32
  end
@@ -34,24 +36,24 @@ module ActiveRecord # :nodoc:
34
36
 
35
37
  # Override to use su_username and su_password
36
38
  def establish_master_connection
37
- establish_connection(configuration.merge(
38
- "database" => "postgres",
39
- "password" => su_password,
40
- "schema_search_path" => "public",
41
- "username" => su_username
39
+ establish_connection(configuration_hash.merge(
40
+ database: "postgres",
41
+ password: su_password,
42
+ schema_search_path: "public",
43
+ username: su_username
42
44
  ))
43
45
  end
44
46
 
45
47
  def establish_su_connection
46
- establish_connection(configuration.merge(
47
- "password" => su_password,
48
- "schema_search_path" => "public",
49
- "username" => su_username
48
+ establish_connection(configuration_hash.merge(
49
+ password: su_password,
50
+ schema_search_path: "public",
51
+ username: su_username
50
52
  ))
51
53
  end
52
54
 
53
55
  def username
54
- @username ||= configuration["username"]
56
+ @username ||= configuration_hash[:username]
55
57
  end
56
58
 
57
59
  def quoted_username
@@ -59,29 +61,30 @@ module ActiveRecord # :nodoc:
59
61
  end
60
62
 
61
63
  def password
62
- @password ||= configuration["password"]
64
+ @password ||= configuration_hash[:password]
63
65
  end
64
66
 
65
67
  def su_username
66
- @su_username ||= configuration["su_username"] || username
68
+ @su_username ||= configuration_hash.fetch(:su_username, username)
67
69
  end
68
70
 
69
71
  def su_password
70
- @su_password ||= configuration["su_password"] || password
72
+ @su_password ||= configuration_hash.fetch(:su_password, password)
71
73
  end
72
74
 
73
75
  def has_su?
74
- @has_su = configuration.include?("su_username") unless defined?(@has_su)
75
- @has_su
76
+ return @has_su if defined?(@has_su)
77
+
78
+ @has_su = configuration_hash.include?(:su_username)
76
79
  end
77
80
 
78
81
  def search_path
79
- @search_path ||= configuration["schema_search_path"].to_s.strip.split(",").map(&:strip)
82
+ @search_path ||= configuration_hash[:schema_search_path].to_s.strip.split(",").map(&:strip)
80
83
  end
81
84
 
82
85
  def extension_names
83
86
  @extension_names ||= begin
84
- extensions = configuration["postgis_extension"]
87
+ extensions = configuration_hash[:postgis_extension]
85
88
  case extensions
86
89
  when ::String
87
90
  extensions.split(",")
@@ -94,11 +97,11 @@ module ActiveRecord # :nodoc:
94
97
  end
95
98
 
96
99
  def ensure_installation_configs
97
- if configuration["setup"] == "default" && !configuration["postgis_extension"]
100
+ if configuration_hash[:setup] == "default" && !configuration_hash[:postgis_extension]
98
101
  share_dir = `pg_config --sharedir`.strip rescue "/usr/share"
99
102
  control_file = ::File.expand_path("extension/postgis.control", share_dir)
100
103
  if ::File.readable?(control_file)
101
- configuration["postgis_extension"] = "postgis"
104
+ @configuration_hash = configuration_hash.merge(postgis_extension: "postgis").freeze
102
105
  end
103
106
  end
104
107
  end
@@ -106,10 +109,12 @@ module ActiveRecord # :nodoc:
106
109
  def setup_gis_from_extension
107
110
  extension_names.each do |extname|
108
111
  if extname == "postgis_topology"
109
- raise ::ArgumentError, "'topology' must be in schema_search_path for postgis_topology" unless search_path.include?("topology")
112
+ unless search_path.include?("topology")
113
+ raise ArgumentError, "'topology' must be in schema_search_path for postgis_topology"
114
+ end
110
115
  connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} SCHEMA topology")
111
116
  else
112
- if (postgis_schema = configuration["postgis_schema"])
117
+ if (postgis_schema = configuration_hash[:postgis_schema])
113
118
  schema_clause = "WITH SCHEMA #{postgis_schema}"
114
119
  unless schema_exists?(postgis_schema)
115
120
  connection.execute("CREATE SCHEMA #{postgis_schema}")
@@ -125,7 +130,9 @@ module ActiveRecord # :nodoc:
125
130
  end
126
131
 
127
132
  def schema_exists?(schema_name)
128
- connection.execute("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '#{schema_name}'").any?
133
+ connection.execute(
134
+ "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '#{schema_name}'"
135
+ ).any?
129
136
  end
130
137
  end
131
138
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS # :nodoc:
@@ -1,46 +1,41 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module PostGIS
4
6
  module SchemaStatements
5
7
  # override
6
- # pass table_name to #new_column
7
- def columns(table_name)
8
- # Limit, precision, and scale are all handled by the superclass.
9
- column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod, collation, comment|
10
- oid = oid.to_i
11
- fmod = fmod.to_i
12
- type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
13
- cast_type = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
14
- default_value = extract_value_from_default(default)
15
-
16
- default_function = extract_default_function(default_value, default)
17
- new_column(table_name, column_name, default_value, cast_type, type_metadata, !notnull, default_function, collation, comment)
18
- end
19
- end
8
+ # https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L624
9
+ # Create a SpatialColumn instead of a PostgreSQL::Column
10
+ def new_column_from_field(table_name, field)
11
+ column_name, type, default, notnull, oid, fmod, collation, comment = field
12
+ type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
13
+ default_value = extract_value_from_default(default)
14
+ default_function = extract_default_function(default_value, default)
20
15
 
21
- # override
22
- def new_column(table_name, column_name, default, cast_type, sql_type_metadata = nil, null = true, default_function = nil, collation = nil, comment = nil)
23
- # JDBC gets true/false in Rails 4, where other platforms get 't'/'f' strings.
24
- if null.is_a?(String)
25
- null = (null == "t")
26
- end
16
+ serial =
17
+ if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/))
18
+ sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
19
+ end
27
20
 
28
- column_info = spatial_column_info(table_name).get(column_name, sql_type_metadata.sql_type)
21
+ # {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"}
22
+ spatial = spatial_column_info(table_name).get(column_name, type_metadata.sql_type)
29
23
 
30
- SpatialColumn.new(column_name,
31
- default,
32
- sql_type_metadata,
33
- null,
34
- table_name,
35
- default_function,
36
- collation,
37
- comment,
38
- cast_type,
39
- column_info)
24
+ SpatialColumn.new(
25
+ column_name,
26
+ default_value,
27
+ type_metadata,
28
+ !notnull,
29
+ default_function,
30
+ collation: collation,
31
+ comment: comment.presence,
32
+ serial: serial,
33
+ spatial: spatial
34
+ )
40
35
  end
41
36
 
42
37
  # override
43
- # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L583
38
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L544
44
39
  #
45
40
  # returns Postgresql sql type string
46
41
  # examples:
@@ -50,12 +45,12 @@ module ActiveRecord
50
45
  # note: type alone is not enough to detect the sql type,
51
46
  # so `limit` is used to pass the additional information. :(
52
47
  #
53
- # type_to_sql(:geography, "Point,4326")
48
+ # type_to_sql(:geography, limit: "Point,4326")
54
49
  # => "geography(Point,4326)"
55
- def type_to_sql(type, options = {})
56
- case type
57
- when :geometry, :geography
58
- "#{type}(#{options[:limit]})"
50
+ def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **)
51
+ case type.to_s
52
+ when "geometry", "geography"
53
+ "#{type}(#{limit})"
59
54
  else
60
55
  super
61
56
  end
@@ -79,8 +74,8 @@ module ActiveRecord
79
74
  end
80
75
 
81
76
  # override
82
- def create_table_definition(*args)
83
- PostGIS::TableDefinition.new(*args)
77
+ def create_table_definition(*args, **kwargs)
78
+ PostGIS::TableDefinition.new(self, *args, **kwargs)
84
79
  end
85
80
 
86
81
  # memoize hash of column infos for tables
@@ -90,8 +85,6 @@ module ActiveRecord
90
85
  end
91
86
 
92
87
  def initialize_type_map(map = type_map)
93
- super
94
-
95
88
  %w(
96
89
  geography
97
90
  geometry
@@ -107,6 +100,8 @@ module ActiveRecord
107
100
  OID::Spatial.new(oid, sql_type)
108
101
  end
109
102
  end
103
+
104
+ super
110
105
  end
111
106
  end
112
107
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS # :nodoc:
@@ -5,18 +7,17 @@ module ActiveRecord # :nodoc:
5
7
  # sql_type examples:
6
8
  # "Geometry(Point,4326)"
7
9
  # "Geography(Point,4326)"
8
- # cast_type example classes:
9
- # OID::Spatial
10
- # OID::Integer
11
- def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment = nil, cast_type = nil, opts = nil)
12
- @cast_type = cast_type
10
+ def initialize(name, default, sql_type_metadata = nil, null = true,
11
+ default_function = nil, collation: nil, comment: nil,
12
+ serial: nil, spatial: nil)
13
+ @sql_type_metadata = sql_type_metadata
13
14
  @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
14
- if opts
15
+ if spatial
15
16
  # This case comes from an entry in the geometry_columns table
16
- set_geometric_type_from_name(opts[:type])
17
- @srid = opts[:srid].to_i
18
- @has_z = !!opts[:has_z]
19
- @has_m = !!opts[:has_m]
17
+ set_geometric_type_from_name(spatial[:type])
18
+ @srid = spatial[:srid].to_i
19
+ @has_z = !!spatial[:has_z]
20
+ @has_m = !!spatial[:has_m]
20
21
  elsif @geographic
21
22
  # Geographic type information is embedded in the SQL type
22
23
  @srid = 4326
@@ -29,7 +30,8 @@ module ActiveRecord # :nodoc:
29
30
  # @geometric_type = geo_type_from_sql_type(sql_type)
30
31
  build_from_sql_type(sql_type_metadata.sql_type)
31
32
  end
32
- super(name, default, sql_type_metadata, null, table_name, default_function, collation, comment: comment)
33
+ super(name, default, sql_type_metadata, null, default_function,
34
+ collation: collation, comment: comment, serial: serial)
33
35
  if spatial?
34
36
  if @srid
35
37
  @limit = { srid: @srid, type: to_type_name(geometric_type) }
@@ -51,15 +53,11 @@ module ActiveRecord # :nodoc:
51
53
  alias :has_m? :has_m
52
54
 
53
55
  def limit
54
- if spatial?
55
- @limit
56
- else
57
- super
58
- end
56
+ spatial? ? @limit : super
59
57
  end
60
58
 
61
59
  def spatial?
62
- @cast_type.respond_to?(:spatial?) && @cast_type.spatial?
60
+ %i[geometry geography].include?(@sql_type_metadata.type)
63
61
  end
64
62
 
65
63
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS
@@ -9,7 +11,9 @@ module ActiveRecord # :nodoc:
9
11
  end
10
12
 
11
13
  def all
12
- info = @adapter.query("SELECT f_geometry_column,coord_dimension,srid,type FROM geometry_columns WHERE f_table_name='#{@table_name}'")
14
+ info = @adapter.query(
15
+ "SELECT f_geometry_column,coord_dimension,srid,type FROM geometry_columns WHERE f_table_name='#{@table_name}'"
16
+ )
13
17
  result = {}
14
18
  info.each do |row|
15
19
  name = row[0]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord # :nodoc:
2
4
  module ConnectionAdapters # :nodoc:
3
5
  module PostGIS # :nodoc:
@@ -5,7 +7,7 @@ module ActiveRecord # :nodoc:
5
7
  include ColumnMethods
6
8
 
7
9
  # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
8
- def new_column_definition(name, type, options)
10
+ def new_column_definition(name, type, **options)
9
11
  if (info = PostGISAdapter.spatial_column_options(type.to_sym))
10
12
  if (limit = options.delete(:limit))
11
13
  options.merge!(limit) if limit.is_a?(::Hash)
@@ -16,9 +18,9 @@ module ActiveRecord # :nodoc:
16
18
 
17
19
  options[:limit] = ColumnDefinitionUtils.limit_from_options(geo_type, options)
18
20
  options[:spatial_type] = geo_type
19
- column = super(name, base_type, options)
21
+ column = super(name, base_type, **options)
20
22
  else
21
- column = super(name, type, options)
23
+ column = super(name, type, **options)
22
24
  end
23
25
 
24
26
  column
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module PostGIS
4
- VERSION = "5.2.0"
6
+ VERSION = "7.0.0"
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The activerecord-postgis-adapter gem installs the *postgis*
2
4
  # connection adapter into ActiveRecord.
3
5
 
@@ -5,13 +7,7 @@
5
7
 
6
8
  require "rgeo/active_record"
7
9
 
8
- # autoload AbstractAdapter to avoid circular require and void context warnings
9
- module ActiveRecord
10
- module ConnectionAdapters
11
- AbstractAdapter
12
- end
13
- end
14
-
10
+ require "active_record/connection_adapters"
15
11
  require "active_record/connection_adapters/postgresql_adapter"
16
12
  require "active_record/connection_adapters/postgis/version"
17
13
  require "active_record/connection_adapters/postgis/column_methods"
@@ -36,7 +32,7 @@ end
36
32
  module ActiveRecord
37
33
  module ConnectionAdapters
38
34
  class PostGISAdapter < PostgreSQLAdapter
39
- include PostGIS::SchemaStatements
35
+ ADAPTER_NAME = 'PostGIS'.freeze
40
36
 
41
37
  SPATIAL_COLUMN_OPTIONS =
42
38
  {
@@ -55,22 +51,10 @@ module ActiveRecord
55
51
  # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
56
52
  DEFAULT_SRID = 0
57
53
 
58
- # def initialize(*args)
59
- def initialize(connection, logger, connection_parameters, config)
60
- super
61
-
62
- @visitor = Arel::Visitors::PostGIS.new(self)
63
- # copy from https://github.com/rails/rails/blob/6ece7df8d80c6d93db43878fa4c0278a0204072c/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L199
64
- if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
65
- @prepared_statements = true
66
- @visitor.extend(DetermineIfPreparableVisitor)
67
- else
68
- @prepared_statements = false
69
- end
70
- end
54
+ include PostGIS::SchemaStatements
71
55
 
72
- def adapter_name
73
- "PostGIS".freeze
56
+ def arel_visitor # :nodoc:
57
+ Arel::Visitors::PostGIS.new(self)
74
58
  end
75
59
 
76
60
  def self.spatial_column_options(key)
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/postgis_adapter"
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Azuma, Tee Parham
7
+ - Daniel Azuma
8
+ - Tee Parham
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-12-24 00:00:00.000000000 Z
12
+ date: 2021-01-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activerecord
@@ -16,28 +17,28 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '5.1'
20
+ version: '6.1'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '5.1'
27
+ version: '6.1'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rgeo-activerecord
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '6.0'
34
+ version: 7.0.0
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '6.0'
41
+ version: 7.0.0
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rake
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +98,10 @@ dependencies:
97
98
  description: ActiveRecord connection adapter for PostGIS. It is based on the stock
98
99
  PostgreSQL adapter, and adds built-in support for the spatial extensions provided
99
100
  by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
100
- email: dazuma@gmail.com, parhameter@gmail.com
101
+ email:
102
+ - dazuma@gmail.com
103
+ - parhameter@gmail.com
104
+ - kfdoggett@gmail.com
101
105
  executables: []
102
106
  extensions: []
103
107
  extra_rdoc_files: []
@@ -120,7 +124,7 @@ files:
120
124
  - lib/activerecord-postgis-adapter.rb
121
125
  homepage: http://github.com/rgeo/activerecord-postgis-adapter
122
126
  licenses:
123
- - BSD
127
+ - BSD-3-Clause
124
128
  metadata: {}
125
129
  post_install_message:
126
130
  rdoc_options: []
@@ -130,15 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
134
  requirements:
131
135
  - - ">="
132
136
  - !ruby/object:Gem::Version
133
- version: 2.2.2
137
+ version: 2.5.0
134
138
  required_rubygems_version: !ruby/object:Gem::Requirement
135
139
  requirements:
136
140
  - - ">="
137
141
  - !ruby/object:Gem::Version
138
142
  version: '0'
139
143
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.7.0
144
+ rubygems_version: 3.0.8
142
145
  signing_key:
143
146
  specification_version: 4
144
147
  summary: ActiveRecord adapter for PostGIS, based on RGeo.