activerecord-postgis 0.6.0 → 0.6.2

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: 86b0a720bdf3520ba032d20033a4259e1875bd37ec97e9e517b0b1b1ac647e40
4
- data.tar.gz: 4c2ff56e23a305ad149fb61b9f84d8742675e62358f80c4cd8708a488c7b3f67
3
+ metadata.gz: c4caab5fe6b63c11ebb789f2e77cb8997ac1c495333cc08e2cba397e043916fa
4
+ data.tar.gz: a8688b2c439daf278f07fe7c9ff00fd791ef82f964a74f0032ec088e5a495144
5
5
  SHA512:
6
- metadata.gz: 1a3849e3b5f56491964affeaac36f53317bc6fe1d77557067171b00197b0af5675b5aa090250efe9d083f51bf94e531b2965ed97802e704f4969e3e840cf4485
7
- data.tar.gz: a4d2916514e25e89fd722567cddd90fe96bbda946c3de5c110018f6d20ad2b3e395049a5c4960bec1d565d03824340b22ed7c8f1bce92f3bbad4f5e6c1fabbba
6
+ metadata.gz: 55b212ec58aff548cd55062d88728b75383859b246a66cd49cda54e1f86d2acde0ad3b6a3df8d921e4e7678efe99c9898f78efa4557e978b9361e520996bd823
7
+ data.tar.gz: 5c33782d1350c14a8f8bf1edbe3ae8495bd40527293241f80e5d6b140f964c70b953d2f3fc8b513a1c5df8fb218c896540d6fcc80645ef4573c7e7460abc11e0
@@ -25,9 +25,9 @@ module ActiveRecord
25
25
  has_z = geo_part.end_with?("Z") || geo_part.end_with?("ZM")
26
26
  has_m = geo_part.end_with?("M") || geo_part.end_with?("ZM")
27
27
  end
28
- elsif o.limit.is_a?(String) && o.limit.include?(",")
28
+ elsif o.options[:limit].is_a?(String) && o.options[:limit].include?(",")
29
29
  # Fallback to parsing limit string (for schema loading)
30
- geo_part, srid_part = o.limit.split(",", 2)
30
+ geo_part, srid_part = o.options[:limit].split(",", 2)
31
31
  srid = srid_part.to_i if srid_part && !srid_part.empty?
32
32
  if geo_part
33
33
  has_z = geo_part.end_with?("Z") || geo_part.end_with?("ZM")
@@ -42,9 +42,9 @@ module ActiveRecord
42
42
  end
43
43
 
44
44
  sql_type = type_to_sql(o.type.to_sym,
45
- limit: o.options[:spatial_sql] || o.limit,
46
- precision: o.precision,
47
- scale: o.scale,
45
+ limit: o.options[:spatial_sql] || o.options[:limit],
46
+ precision: o.options[:precision],
47
+ scale: o.options[:scale],
48
48
  srid: srid,
49
49
  geographic: geographic,
50
50
  has_z: has_z,
@@ -22,8 +22,9 @@ module ActiveRecord
22
22
  end
23
23
 
24
24
  if spatial_column_type?(col_type)
25
- if (limit = options.delete(:limit)) && limit.is_a?(::Hash)
26
- options.merge!(limit)
25
+ case (limit = options.delete(:limit))
26
+ when ::Hash then options.merge!(limit)
27
+ when ::String then options.reverse_merge!(ColumnDefinitionUtils.options_from_limit(limit))
27
28
  end
28
29
 
29
30
  # Set geographic option for geography types
@@ -125,6 +126,17 @@ module ActiveRecord
125
126
  end
126
127
  end
127
128
 
129
+ # Inverse of limit_from_options: "POINTZ,4326" => { srid: 4326, has_z: true }
130
+ def options_from_limit(limit)
131
+ geo_part, srid_part = limit.split(",", 2)
132
+ dimensions = geo_part.to_s.upcase[/(ZM|Z|M)\z/].to_s
133
+ options = {}
134
+ options[:srid] = Integer(srid_part) if srid_part.present?
135
+ options[:has_z] = true if dimensions.include?("Z")
136
+ options[:has_m] = true if dimensions.include?("M")
137
+ options
138
+ end
139
+
128
140
  def limit_from_options(type, options = {})
129
141
  has_z = options[:has_z] ? "Z" : ""
130
142
  has_m = options[:has_m] ? "M" : ""
@@ -15,13 +15,6 @@ module ActiveRecord
15
15
  @has_z = has_z
16
16
  @has_m = has_m
17
17
  @geographic = geographic
18
- @factory = RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
19
- geo_type: @geo_type.underscore,
20
- srid: srid,
21
- has_z: has_z,
22
- has_m: has_m,
23
- sql_type: (@geographic ? "geography" : "geometry")
24
- )
25
18
  end
26
19
 
27
20
  def type
@@ -40,6 +33,18 @@ module ActiveRecord
40
33
 
41
34
  private
42
35
 
36
+ # Not memoized: types are frozen for Ractor sharing, and factories
37
+ # hold mutexes/procs. SpatialFactoryStore already caches them.
38
+ def factory
39
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
40
+ geo_type: @geo_type.underscore,
41
+ srid: @srid,
42
+ has_z: @has_z,
43
+ has_m: @has_m,
44
+ sql_type: (@geographic ? "geography" : "geometry")
45
+ )
46
+ end
47
+
43
48
  def cast_value(value)
44
49
  case value
45
50
  when ::RGeo::Feature::Instance
@@ -56,11 +61,11 @@ module ActiveRecord
56
61
  def parse_wkt(string)
57
62
  if binary_string?(string)
58
63
  # Parse WKB (Well-Known Binary) format
59
- wkb_parser = RGeo::WKRep::WKBParser.new(@factory, support_ewkb: true, default_srid: @srid)
64
+ wkb_parser = RGeo::WKRep::WKBParser.new(factory, support_ewkb: true, default_srid: @srid)
60
65
  wkb_parser.parse(string)
61
66
  else
62
67
  # Parse WKT (Well-Known Text) format
63
- wkt_parser = RGeo::WKRep::WKTParser.new(@factory, support_ewkt: true, default_srid: @srid)
68
+ wkt_parser = RGeo::WKRep::WKTParser.new(factory, support_ewkt: true, default_srid: @srid)
64
69
  wkt_parser.parse(string)
65
70
  end
66
71
  rescue RGeo::Error::ParseError
@@ -74,7 +79,7 @@ module ActiveRecord
74
79
  def parse_hash(hash)
75
80
  # Support GeoJSON-style hash
76
81
  if hash["type"] && hash["coordinates"]
77
- RGeo::GeoJSON.decode(hash.to_json, geo_factory: @factory)
82
+ RGeo::GeoJSON.decode(hash.to_json, geo_factory: factory)
78
83
  else
79
84
  nil
80
85
  end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module PostGIS
6
- VERSION = "0.6.0"
6
+ VERSION = "0.6.2"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 4.0.10
139
+ rubygems_version: 4.0.20
140
140
  specification_version: 4
141
141
  summary: PostGIS Type support for ActiveRecord
142
142
  test_files: []