activerecord-postgis-adapter 5.2.1 → 7.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2575c4737840ea81feaba17b0acc313c0e85a75acae5ffba257437057e41e15
4
- data.tar.gz: f77aa6f4a11a01e1be968c156ddb0b743f5bae71a96022c77a36cc7e03599129
3
+ metadata.gz: 0ca517c070d542c846f7bbba2e01c0767d51bc796f63cc97dea7a6c0c93af2de
4
+ data.tar.gz: e1f44ef4078302a420dc27582a1ae5e4ff768591f9879ad9ba91bb288e9016df
5
5
  SHA512:
6
- metadata.gz: 26c3e43c3a9f986811fa9f85272b76bc4fb396b408cffd1e480586bfef4a13401c1e44f6be3ce5162c980b31f95b01d81ed28740de79ff9866db454b863db6a8
7
- data.tar.gz: 2b12969c401226ed98b120e11566439ffbed2c3d4c96b9a0dbe63bd5083313723252588cb27f1a09abda7640f9999b100205b7a9456314947be795ca11ceaa2a
6
+ metadata.gz: 1333881d9758c1b0d1bf4de5ffb24ddd6a3c10d38edab2063ab20ef994ba9f80bd05a5e949ecc254ce210eaef8ff46a5b2ebf310e7282eb88bbe2719867e852e
7
+ data.tar.gz: 35876e4747fc87bf5e27b36c354e3c47c20cf81b4dd51daee3369ed290115a71dc297c1d5a07cc4f83637995a3ae2c1b73feeb86e107b4450997f9ff7215243c
@@ -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
- desc "Setup PostGIS data in the database"
5
+ desc 'Setup PostGIS data in the database'
4
6
  task setup: [:load_config] do
5
7
  environments = [Rails.env]
6
- 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
8
+ environments << 'test' if Rails.env.development?
9
+ environments.each do |environment|
10
+ ActiveRecord::Base.configurations
11
+ .configs_for(env_name: environment)
12
+ .reject { |env| env.configuration_hash['database'].blank? }
13
+ .each do |env|
14
+ ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(env).setup_gis
13
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
@@ -47,11 +49,7 @@ module ActiveRecord
47
49
  def spatial_factory
48
50
  @spatial_factory ||=
49
51
  RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
50
- geo_type: @geo_type,
51
- has_m: @has_m,
52
- has_z: @has_z,
53
- sql_type: @sql_type,
54
- srid: @srid
52
+ factory_attrs
55
53
  )
56
54
  end
57
55
 
@@ -105,6 +103,16 @@ module ActiveRecord
105
103
  RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
106
104
  end
107
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
108
116
  end
109
117
  end
110
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.1"
6
+ VERSION = "7.0.1"
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.1
4
+ version: 7.0.1
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: 2018-03-05 00:00:00.000000000 Z
12
+ date: 2021-01-13 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.6
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.