activerecord-postgis-adapter 10.0.1 → 11.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c89079951de976b3c0909194bfc5c19e7788f6002ac72851c4ad42606ffea8fd
4
- data.tar.gz: ab2b792b1bb948cd59cf7fcfccb447ac833c5cbae9d12b7a8822295b94c4cf65
3
+ metadata.gz: d477a971bc892e6bafc575dc82dd5af7b007b0f8755b2b27a7d4adabfea7261f
4
+ data.tar.gz: 61f5cb02bde912292f92f8c416ae64e22442f35ba466074ffc3466625501d638
5
5
  SHA512:
6
- metadata.gz: b8399daa6d86e1871e1de81442f9fa059ed8667bf809429f3fd43b58fe7957c87d882322346ca808f7062acd1cebf63fbd2fe5507316de0fc1cefaec2b039523
7
- data.tar.gz: 9939e9d954d8d9c0aeb10c13641507819028c8f9b5d57e2db66fd50dff058773eda3c13f40c4ee28e75cd26e0c9fb6f4e39982f0dcadfe12d82ad88a9b9f34a0
6
+ metadata.gz: 4864a98aa11734fffa2c7f0cd81049c81004a0bc19c6912c6c05c73457a4f0ab4dfd18de3960a3108dd31c0a2b0acbee36cdc5e0280b1551f632a60b0596c5da
7
+ data.tar.gz: 9fea7a830019c327036b974e4fd4c1cdede785834f3dc791cbc323bb05320f5273365de176b778b19d7c421b23ed1c3aec928fbd6e42f5779f3f01e4ca055380
@@ -3,14 +3,15 @@
3
3
  module ActiveRecord # :nodoc:
4
4
  module ConnectionAdapters # :nodoc:
5
5
  module PostGIS # :nodoc:
6
- class SpatialColumn < ConnectionAdapters::PostgreSQLColumn # :nodoc:
6
+ class Column < PostgreSQL::Column # :nodoc:
7
7
  # sql_type examples:
8
8
  # "Geometry(Point,4326)"
9
9
  # "Geography(Point,4326)"
10
- def initialize(name, default, sql_type_metadata = nil, null = true,
10
+ def initialize(name, cast_type, default, sql_type_metadata = nil, null = true,
11
11
  default_function = nil, collation: nil, comment: nil,
12
12
  serial: nil, generated: nil, spatial: nil, identity: nil)
13
- @sql_type_metadata = sql_type_metadata
13
+ super(name, cast_type, default, sql_type_metadata, null, default_function,
14
+ collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
14
15
  @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
15
16
  if spatial
16
17
  # This case comes from an entry in the geometry_columns table
@@ -30,8 +31,6 @@ module ActiveRecord # :nodoc:
30
31
  # @geometric_type = geo_type_from_sql_type(sql_type)
31
32
  build_from_sql_type(sql_type_metadata.sql_type)
32
33
  end
33
- super(name, default, sql_type_metadata, null, default_function,
34
- collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
35
34
  if spatial? && @srid
36
35
  @limit = { srid: @srid, type: to_type_name(geometric_type) }
37
36
  @limit[:has_z] = true if @has_z
@@ -58,6 +57,49 @@ module ActiveRecord # :nodoc:
58
57
  %i[geometry geography].include?(@sql_type_metadata.type)
59
58
  end
60
59
 
60
+ def init_with(coder)
61
+ @geographic = coder["geographic"]
62
+ @geometric_type = coder["geometric_type"]
63
+ @has_m = coder["has_m"]
64
+ @has_z = coder["has_z"]
65
+ @srid = coder["srid"]
66
+ @limit = coder["limit"]
67
+ super
68
+ end
69
+
70
+ def encode_with(coder)
71
+ coder["geographic"] = @geographic
72
+ coder["geometric_type"] = @geometric_type
73
+ coder["has_m"] = @has_m
74
+ coder["has_z"] = @has_z
75
+ coder["srid"] = @srid
76
+ coder["limit"] = @limit
77
+ super
78
+ end
79
+
80
+ def ==(other)
81
+ other.is_a?(Column) &&
82
+ super &&
83
+ other.geographic == geographic &&
84
+ other.geometric_type == geometric_type &&
85
+ other.has_m == has_m &&
86
+ other.has_z == has_z &&
87
+ other.srid == srid &&
88
+ other.limit == limit
89
+ end
90
+ alias :eql? :==
91
+
92
+ def hash
93
+ Column.hash ^
94
+ super.hash ^
95
+ geographic.hash ^
96
+ geometric_type.hash ^
97
+ has_m.hash ^
98
+ has_z.hash ^
99
+ srid.hash ^
100
+ limit.hash
101
+ end
102
+
61
103
  private
62
104
 
63
105
  def set_geometric_type_from_name(name)
@@ -10,12 +10,17 @@ module ActiveRecord
10
10
  # Responsible for parsing sql_types returned from the database and WKT features.
11
11
  class Spatial < Type::Value
12
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
13
+ super()
14
+ @geographic = geographic.freeze
15
+ @factory_attrs = {
16
+ geo_type: geo_type.underscore.freeze,
17
+ has_m: has_m.freeze,
18
+ has_z: has_z.freeze,
19
+ srid: srid.freeze,
20
+ sql_type: type.to_s.freeze
21
+ }.freeze
18
22
  end
23
+ protected attr_reader :geographic, :factory_attrs
19
24
 
20
25
  # sql_type: geometry, geometry(Point), geometry(Point,4326), ...
21
26
  #
@@ -53,10 +58,9 @@ module ActiveRecord
53
58
  end
54
59
 
55
60
  def spatial_factory
56
- @spatial_factory ||=
57
- RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
58
- factory_attrs
59
- )
61
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
62
+ factory_attrs
63
+ )
60
64
  end
61
65
 
62
66
  def spatial?
@@ -80,6 +84,17 @@ module ActiveRecord
80
84
  .generate(geo_value)
81
85
  end
82
86
 
87
+ def ==(other)
88
+ super &&
89
+ @geographic == other.geographic &&
90
+ @factory_attrs == other.factory_attrs
91
+ end
92
+ alias eql? ==
93
+
94
+ def hash
95
+ super ^ [@geographic, @factory_attrs].hash
96
+ end
97
+
83
98
  private
84
99
 
85
100
  def cast_value(value)
@@ -105,16 +120,6 @@ module ActiveRecord
105
120
  RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
106
121
  end
107
122
  end
108
-
109
- def factory_attrs
110
- {
111
- geo_type: @geo_type.underscore,
112
- has_m: @has_m,
113
- has_z: @has_z,
114
- srid: @srid,
115
- sql_type: type.to_s
116
- }
117
- end
118
123
  end
119
124
  end
120
125
  end
@@ -12,6 +12,21 @@ module ActiveRecord
12
12
  super
13
13
  end
14
14
  end
15
+
16
+ # NOTE: This method should be private in future rails versions.
17
+ # Hence we should also make it private then.
18
+ #
19
+ # See https://github.com/rails/rails/blob/v8.1.1/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb#L190
20
+ def lookup_cast_type(sql_type)
21
+ type_map.lookup(
22
+ # oid
23
+ query_value("SELECT #{quote(sql_type)}::regtype::oid", "SCHEMA").to_i,
24
+ # fmod, not needed.
25
+ nil,
26
+ # details needed for `..::PostGIS::OID::Spatial` (e.g. `geometry(point,3857)`)
27
+ sql_type
28
+ )
29
+ end
15
30
  end
16
31
  end
17
32
  end
@@ -12,11 +12,11 @@ module ActiveRecord
12
12
  type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
13
13
  default_value = extract_value_from_default(default)
14
14
 
15
- if attgenerated.present?
16
- default_function = default
17
- else
18
- default_function = extract_default_function(default_value, default)
19
- end
15
+ default_function = if attgenerated.present?
16
+ default
17
+ else
18
+ extract_default_function(default_value, default)
19
+ end
20
20
 
21
21
  if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/))
22
22
  serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
@@ -25,8 +25,9 @@ module ActiveRecord
25
25
  # {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"}
26
26
  spatial = spatial_column_info(table_name).get(column_name, type_metadata.sql_type)
27
27
 
28
- SpatialColumn.new(
28
+ Column.new(
29
29
  column_name,
30
+ get_oid_type(oid.to_i, fmod.to_i, column_name, type),
30
31
  default_value,
31
32
  type_metadata,
32
33
  !notnull,
@@ -50,6 +51,11 @@ module ActiveRecord
50
51
  @spatial_column_info ||= {}
51
52
  @spatial_column_info[table_name.to_sym] ||= SpatialColumnInfo.new(self, table_name.to_s)
52
53
  end
54
+
55
+ # Returns an array of view names defined in the database.
56
+ def views
57
+ super - %w[geography_columns geometry_columns]
58
+ end
53
59
  end
54
60
  end
55
61
  end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module PostGIS
6
- VERSION = "10.0.1"
6
+ VERSION = "11.1.0"
7
7
  end
8
8
  end
9
9
  end
@@ -12,7 +12,7 @@ require_relative "postgis/schema_statements"
12
12
  require_relative "postgis/database_statements"
13
13
  require_relative "postgis/spatial_column_info"
14
14
  require_relative "postgis/spatial_table_definition"
15
- require_relative "postgis/spatial_column"
15
+ require_relative "postgis/column"
16
16
  require_relative "postgis/arel_tosql"
17
17
  require_relative "postgis/oid/spatial"
18
18
  require_relative "postgis/oid/date_time"
@@ -84,7 +84,7 @@ module ActiveRecord
84
84
  # "geometry(Polygon,4326) NOT NULL"
85
85
  # "geometry(Geography,4326)"
86
86
  geo_type, srid, has_z, has_m, geographic = PostGIS::OID::Spatial.parse_sql_type(sql_type)
87
- PostGIS::OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
87
+ PostGIS::OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic).freeze
88
88
  end
89
89
  end
90
90
 
@@ -92,9 +92,7 @@ module ActiveRecord
92
92
  end
93
93
 
94
94
  def native_database_types
95
- @native_database_types ||= begin
96
- default_types = PostgreSQLAdapter.native_database_types
97
- default_types.merge({
95
+ @native_database_types ||= super.merge({
98
96
  geography: { name: "geography" },
99
97
  geometry: { name: "geometry" },
100
98
  geometry_collection: { name: "geometry_collection" },
@@ -106,7 +104,6 @@ module ActiveRecord
106
104
  st_point: { name: "st_point" },
107
105
  st_polygon: { name: "st_polygon" }
108
106
  })
109
- end
110
107
  end
111
108
  end
112
109
 
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ class Relation
5
+ module QueryMethodsExt
6
+ def st_contains!(column, inner_geom)
7
+ where!(self.arel_table[:column].st_contains(inner_geom))
8
+ end
9
+
10
+ def st_contains(...)
11
+ spawn.st_contains!(...)
12
+ end
13
+
14
+ RGeo::ActiveRecord::SpatialExpressions.instance_methods.each do |method_name|
15
+ next if method_name == :st_function
16
+ met = RGeo::ActiveRecord::SpatialExpressions.instance_method(method_name)
17
+ class_eval(<<-CODE, __FILE__, __LINE__ + 1)
18
+ def #{method_name}(...); #{method_name}!(...); end
19
+ def #{method_name}!(column, *args)
20
+ rel = self.arel_table[column]
21
+ where!(rel.#{method_name}(*args))
22
+ end
23
+ CODE
24
+ end
25
+ end
26
+
27
+ QueryMethods.prepend(QueryMethodsExt)
28
+ end
29
+ # `ActiveRecord::Base` ancestors do not include `QueryMethods`.
30
+ # But the `#all` method returns a relation, which has `QueryMethods`
31
+ # as ancestor. That is how active_record is doing is as well.
32
+ #
33
+ # @see https://github.com/rails/rails/blob/914130a9f/activerecord/lib/active_record/querying.rb#L23
34
+ Querying.delegate(:st_contains, to: :all)
35
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.1
4
+ version: 11.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  - Tee Parham
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-11-15 00:00:00.000000000 Z
11
+ date: 2025-11-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
@@ -17,28 +16,28 @@ dependencies:
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: 7.2.0
19
+ version: 8.1.0
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: 7.2.0
26
+ version: 8.1.0
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: rgeo-activerecord
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
- version: 8.0.0
33
+ version: 8.1.0
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
- version: 8.0.0
40
+ version: 8.1.0
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: rake
44
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,18 +121,19 @@ extra_rdoc_files: []
122
121
  files:
123
122
  - LICENSE.txt
124
123
  - lib/active_record/connection_adapters/postgis/arel_tosql.rb
124
+ - lib/active_record/connection_adapters/postgis/column.rb
125
125
  - lib/active_record/connection_adapters/postgis/column_methods.rb
126
126
  - lib/active_record/connection_adapters/postgis/database_statements.rb
127
127
  - lib/active_record/connection_adapters/postgis/oid/date_time.rb
128
128
  - lib/active_record/connection_adapters/postgis/oid/spatial.rb
129
129
  - lib/active_record/connection_adapters/postgis/quoting.rb
130
130
  - lib/active_record/connection_adapters/postgis/schema_statements.rb
131
- - lib/active_record/connection_adapters/postgis/spatial_column.rb
132
131
  - lib/active_record/connection_adapters/postgis/spatial_column_info.rb
133
132
  - lib/active_record/connection_adapters/postgis/spatial_table_definition.rb
134
133
  - lib/active_record/connection_adapters/postgis/type.rb
135
134
  - lib/active_record/connection_adapters/postgis/version.rb
136
135
  - lib/active_record/connection_adapters/postgis_adapter.rb
136
+ - lib/active_record/relation/query_methods_ext.rb
137
137
  - lib/activerecord-postgis-adapter.rb
138
138
  homepage: http://github.com/rgeo/activerecord-postgis-adapter
139
139
  licenses:
@@ -141,7 +141,6 @@ licenses:
141
141
  metadata:
142
142
  funding_uri: https://opencollective.com/rgeo
143
143
  rubygems_mfa_required: 'true'
144
- post_install_message:
145
144
  rdoc_options: []
146
145
  require_paths:
147
146
  - lib
@@ -149,15 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
148
  requirements:
150
149
  - - ">="
151
150
  - !ruby/object:Gem::Version
152
- version: 3.1.0
151
+ version: 3.2.0
153
152
  required_rubygems_version: !ruby/object:Gem::Requirement
154
153
  requirements:
155
154
  - - ">="
156
155
  - !ruby/object:Gem::Version
157
156
  version: '0'
158
157
  requirements: []
159
- rubygems_version: 3.3.26
160
- signing_key:
158
+ rubygems_version: 3.6.4
161
159
  specification_version: 4
162
160
  summary: ActiveRecord adapter for PostGIS, based on RGeo.
163
161
  test_files: []