activerecord-mysql2rgeo-adapter 8.0.4 → 8.0.5

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: b8e687a3f8a5ccfc68ed65b3a4580741bc2b68aa33f18b11a0db6aa3eb5de58d
4
- data.tar.gz: f86a9aa0893e135f478701e58bbfd23d99ddf3e5e2ae078dcbb4b5870baa69de
3
+ metadata.gz: c7c7868e390a06f088a15fbc05edcf4191cd4234da8d0d3a2946f92870a4ce3e
4
+ data.tar.gz: e6ccf5ee308dfbefd8b0997b67c17b895e7346d14be5ca36a86782b73e80d73f
5
5
  SHA512:
6
- metadata.gz: 6fc4adc88222d567042ff0017179e86cab2a637ceb601b0406a1835aa7b850d0b7c13861f93d45bc5e83954ec4e956d731cb3d47a586c73048f177dd1b487bb2
7
- data.tar.gz: b853618805dc918bb1c10ac1f5cf57ba582deabda7f5ae0dcca4cf8d4657d4c35bf41c22e1e89e3667feceae043d0f7f06ffe3df56781825a6dd723a51a9807d
6
+ metadata.gz: e0109fb5a4f7a6afcaa3b8bb3a698239de3c2e211be0d776e5135b0c45cf36cc66ed0ecd9208c41477784391664f10c7e5596e3d1abe3fe498c76da26332a0be
7
+ data.tar.gz: 3974d1716e3446e6addf1edcdc7ed8ce31c7367f1b9a12eaa45944f0e57aaceb57526b3ed79e63e4365b7f87ab5e12b6a66a465a7fd41db197ce4316ab486e02
@@ -9,12 +9,10 @@ module Arel # :nodoc:
9
9
  MySQL
10
10
  end
11
11
 
12
- class Mysql2Rgeo < MySQLSuperclass # :nodoc:
12
+ class Mysql2Rgeo < MySQLSuperclass # :nodoc:
13
13
  include RGeo::ActiveRecord::SpatialToSql
14
14
 
15
- if ::Arel::Visitors.const_defined?(:BindVisitor)
16
- include ::Arel::Visitors::BindVisitor
17
- end
15
+ include ::Arel::Visitors::BindVisitor if ::Arel::Visitors.const_defined?(:BindVisitor)
18
16
 
19
17
  FUNC_MAP = {
20
18
  "st_wkttosql" => "ST_GeomFromText",
@@ -52,18 +50,19 @@ module Arel # :nodoc:
52
50
  end
53
51
 
54
52
  def self.parse_node(node)
55
- if RGeo::Feature::Instance === node
53
+ if node.is_a?(RGeo::Feature::Instance)
56
54
  wkt = RGeo::WKRep::WKTGenerator.new(tag_format: :wkt11, emit_ewkt_srid: false).generate(node)
57
55
  return [wkt, node.srid]
58
56
  end
59
57
 
60
- if RGeo::Cartesian::BoundingBox === node
58
+ if node.is_a?(RGeo::Cartesian::BoundingBox)
61
59
  geometry = node.to_geometry
62
60
  wkt = RGeo::WKRep::WKTGenerator.new(tag_format: :wkt11, emit_ewkt_srid: false).generate(geometry)
63
61
  return [wkt, geometry.srid]
64
62
  end
65
63
 
66
- value, srid = nil, 0
64
+ value = nil
65
+ srid = 0
67
66
  if node =~ /.*;.*$/i
68
67
  params = Regexp.last_match(0).split(";")
69
68
  if params.first =~ /(srid|SRID)=\d*/
@@ -5,34 +5,33 @@ module ActiveRecord
5
5
  module Mysql2Rgeo
6
6
  class SchemaCreation < MySQL::SchemaCreation # :nodoc:
7
7
  private
8
- def visit_IndexDefinition(o, create = false)
9
- if o.using&.to_sym == :gist
10
- sql = create ? ["CREATE SPATIAL INDEX"] : ["SPATIAL INDEX"]
11
- sql << quote_column_name(o.name)
12
- sql << "ON #{quote_table_name(o.table)}" if create
13
- sql << "(#{quoted_columns(o)})"
14
- return sql.join(" ")
15
- end
16
8
 
17
- super
9
+ def visit_IndexDefinition(o, create = false)
10
+ if o.using&.to_sym == :gist
11
+ sql = create ? ["CREATE SPATIAL INDEX"] : ["SPATIAL INDEX"]
12
+ sql << quote_column_name(o.name)
13
+ sql << "ON #{quote_table_name(o.table)}" if create
14
+ sql << "(#{quoted_columns(o)})"
15
+ return sql.join(" ")
18
16
  end
19
17
 
20
- def add_column_options!(sql, options)
21
- if options[:srid]
22
- sql << " /*!80003 SRID #{options[:srid]} */"
23
- options = options.except(:srid)
24
- end
18
+ super
19
+ end
25
20
 
26
- if options_include_default?(options) && spatial_column_definition?(options[:column])
27
- options = options.except(:default)
28
- end
29
-
30
- super
21
+ def add_column_options!(sql, options)
22
+ if options[:srid]
23
+ sql << " /*!80003 SRID #{options[:srid]} */"
24
+ options = options.except(:srid)
31
25
  end
32
26
 
33
- def spatial_column_definition?(column)
34
- column.respond_to?(:type) && column.type && @conn.class.spatial_column_options(column.type.to_sym)
35
- end
27
+ options = options.except(:default) if options_include_default?(options) && spatial_column_definition?(options[:column])
28
+
29
+ super
30
+ end
31
+
32
+ def spatial_column_definition?(column)
33
+ column.respond_to?(:type) && column.type && @conn.class.spatial_column_options(column.type.to_sym)
34
+ end
36
35
  end
37
36
  end
38
37
  end
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
  # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb
8
8
 
9
9
  # override
10
- def indexes(table_name) #:nodoc:
10
+ def indexes(table_name) # :nodoc:
11
11
  indexes = super
12
12
  # HACK(aleks, 06/15/18): MySQL 5 does not support prefix lengths for spatial indexes
13
13
  # https://dev.mysql.com/doc/refman/5.6/en/create-index.html
@@ -33,7 +33,7 @@ module ActiveRecord
33
33
 
34
34
  column_options = column.limit.is_a?(Hash) ? column.limit.symbolize_keys.except(:type) : {}
35
35
  column_options[:comment] = column.comment if column.comment.present?
36
- change_column(table_name, name, column.limit[:type].to_sym, **column_options.merge(null: false))
36
+ change_column(table_name, name, column.limit[:type].to_sym, **column_options, null: false)
37
37
  end
38
38
  end
39
39
 
@@ -42,11 +42,9 @@ module ActiveRecord
42
42
 
43
43
  # override
44
44
  def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
45
- if type.to_sym == :geometry && limit.is_a?(String)
46
- return "geometry(#{limit})"
47
- end
45
+ return "geometry(#{limit})" if type.to_sym == :geometry && limit.is_a?(String)
48
46
 
49
- if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
47
+ if RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_"))
50
48
  type = limit[:type] || type if limit.is_a?(::Hash)
51
49
  type = type.to_s.delete("_").upcase
52
50
  end
@@ -72,13 +70,15 @@ module ActiveRecord
72
70
  # override
73
71
  def new_column_from_field(table_name, field, _definitions)
74
72
  type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
75
- default, default_function = field[:Default], nil
73
+ default = field[:Default]
74
+ default_function = nil
76
75
  metadata = Mysql2Rgeo::ColumnDefinitionUtils.extract_metadata(field[:Comment])
77
76
  comment = Mysql2Rgeo::ColumnDefinitionUtils.strip_metadata_comment(field[:Comment])
78
77
  default = metadata[:default_hex] if default.nil? && metadata[:default_hex].present?
79
78
 
80
79
  if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
81
- default, default_function = nil, default
80
+ default_function = default
81
+ default = nil
82
82
  elsif type_metadata.extra == "DEFAULT_GENERATED"
83
83
  if default == "NULL" && metadata[:default_hex].present?
84
84
  default = metadata[:default_hex]
@@ -87,8 +87,9 @@ module ActiveRecord
87
87
  end
88
88
 
89
89
  if default&.match?(/\Ast_geomfromtext\(/i)
90
- default = +"(#{default})" unless default.start_with?("(")
91
- default, default_function = nil, default
90
+ default = "(#{default})" unless default.start_with?("(")
91
+ default_function = default
92
+ default = nil
92
93
  end
93
94
  end
94
95
 
@@ -116,9 +117,9 @@ module ActiveRecord
116
117
  type: :geometry,
117
118
  limit: nil,
118
119
  precision: type_metadata.precision,
119
- scale: type_metadata.scale,
120
+ scale: type_metadata.scale
120
121
  ),
121
- extra: type_metadata.extra,
122
+ extra: type_metadata.extra
122
123
  )
123
124
 
124
125
  if default_function&.match?(/\A\(?st_geomfromtext\(/i)
@@ -159,10 +160,11 @@ module ActiveRecord
159
160
  srid: srid,
160
161
  geographic: spatial[:geographic],
161
162
  has_z: spatial[:has_z],
162
- has_m: spatial[:has_m],
163
+ has_m: spatial[:has_m]
163
164
  )
164
165
  geometry = type.serialize(wkt)
165
166
  return unless geometry
167
+
166
168
  geometry = RGeo::Feature.cast(geometry, factory: type.send(:spatial_factory), project: true) if spatial[:geographic]
167
169
 
168
170
  wkb = RGeo::WKRep::WKBGenerator.new(
@@ -190,7 +192,7 @@ module ActiveRecord
190
192
  AND table_name = #{quote(table_name)}
191
193
  AND column_name = #{quote(column_name)}
192
194
  SQL
193
- &.gsub(/st_buffer\(([^,]+),\s*(\d+)\)/i, 'st_buffer(\1, (\2)::double precision)')
195
+ &.gsub(/st_buffer\(([^,]+),\s*(\d+)\)/i, 'st_buffer(\1, (\2)::double precision)')
194
196
  end
195
197
 
196
198
  def generated_default_for(table_name, column_name)
@@ -4,7 +4,8 @@ module ActiveRecord # :nodoc:
4
4
  module ConnectionAdapters # :nodoc:
5
5
  module Mysql2Rgeo # :nodoc:
6
6
  class SpatialColumn < ConnectionAdapters::MySQL::Column # :nodoc:
7
- def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, spatial: nil, array: false, **)
7
+ def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil,
8
+ spatial: nil, array: false, **)
8
9
  @sql_type_metadata = sql_type_metadata
9
10
  @array = array
10
11
  @geographic = !!(sql_type_metadata&.sql_type =~ /geography\(/i)
@@ -27,14 +28,13 @@ module ActiveRecord # :nodoc:
27
28
  build_from_sql_type(sql_type_metadata.sql_type)
28
29
  end
29
30
  super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
30
- if spatial?
31
- if @srid
32
- @limit = { type: limit_type_name, srid: @srid }
33
- @limit[:geographic] = true if geographic?
34
- @limit[:has_z] = true if has_z?
35
- @limit[:has_m] = true if has_m?
36
- end
37
- end
31
+ return unless spatial?
32
+ return unless @srid
33
+
34
+ @limit = { type: limit_type_name, srid: @srid }
35
+ @limit[:geographic] = true if geographic?
36
+ @limit[:has_z] = true if has_z?
37
+ @limit[:has_m] = true if has_m?
38
38
  end
39
39
 
40
40
  attr_reader :geometric_type, :srid
@@ -29,11 +29,11 @@ module ActiveRecord # :nodoc:
29
29
  has_z = type.sub!(/z$/i, "").present?
30
30
  has_m = type.sub!(/m$/i, "").present?
31
31
  result[name] = {
32
- name: name,
33
- srid: row[1].to_i,
34
- type: type,
35
- has_z: has_z,
36
- has_m: has_m,
32
+ name: name,
33
+ srid: row[1].to_i,
34
+ type: type,
35
+ has_z: has_z,
36
+ has_m: has_m,
37
37
  geographic: column_comment.include?("mysql2rgeo:geographic"),
38
38
  }
39
39
  end
@@ -5,6 +5,7 @@ module ActiveRecord # :nodoc:
5
5
  module Mysql2Rgeo # :nodoc:
6
6
  class TableDefinition < MySQL::TableDefinition # :nodoc:
7
7
  include ColumnMethods
8
+
8
9
  # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
9
10
  def new_column_definition(name, type, **options)
10
11
  spatial_type = type.to_sym == :virtual ? options[:type]&.to_sym : type.to_sym
@@ -20,7 +21,9 @@ module ActiveRecord # :nodoc:
20
21
  ColumnDefinitionUtils.geo_type(options[:type] || spatial_type || info[:type])
21
22
  end
22
23
 
23
- unless type.to_sym == :virtual
24
+ if type.to_sym == :virtual
25
+ options.delete(:srid)
26
+ else
24
27
  options[:srid] ||= ColumnDefinitionUtils.default_srid(options)
25
28
  options[:comment] = ColumnDefinitionUtils.add_metadata_comment(
26
29
  options[:comment],
@@ -32,19 +35,20 @@ module ActiveRecord # :nodoc:
32
35
  srid: options[:srid],
33
36
  geo_type: geo_type
34
37
  )
35
- else
36
- options.delete(:srid)
37
38
  end
38
39
 
39
40
  options[:spatial_type] = geo_type
40
- if type.to_sym == :virtual
41
- column = super(name, type, **options.merge(type: geo_type.downcase.to_sym))
42
- else
43
- column = super(name, geo_type.downcase.to_sym, **options)
44
- end
41
+ column = if type.to_sym == :virtual
42
+ super(name, type, **options.merge(type: geo_type.downcase.to_sym))
43
+ else
44
+ super(name, geo_type.downcase.to_sym, **options)
45
+ end
45
46
  else
46
- options[:comment] = ColumnDefinitionUtils.add_metadata_comment(options[:comment], array: options[:array]) if options[:array]
47
- column = super(name, type, **options)
47
+ if options[:array]
48
+ options[:comment] =
49
+ ColumnDefinitionUtils.add_metadata_comment(options[:comment], array: options[:array])
50
+ end
51
+ column = super
48
52
  end
49
53
 
50
54
  column
@@ -77,14 +81,16 @@ module ActiveRecord # :nodoc:
77
81
  options[:geographic] ? 4326 : Mysql2RgeoAdapter::DEFAULT_SRID
78
82
  end
79
83
 
80
- def add_metadata_comment(comment, geographic: false, has_m: false, has_z: false, array: false, default: nil, srid: nil, geo_type: nil)
84
+ def add_metadata_comment(comment, geographic: false, has_m: false, has_z: false, array: false, default: nil, srid: nil,
85
+ geo_type: nil)
81
86
  values = [comment]
82
87
  values << METADATA_TOKENS[:geographic] if geographic
83
88
  values << METADATA_TOKENS[:has_m] if has_m
84
89
  values << METADATA_TOKENS[:has_z] if has_z
85
90
  values << METADATA_TOKENS[:array] if array
86
91
  if default
87
- values << "#{METADATA_TOKENS[:default_prefix]}#{encode_default(default, geographic: geographic, srid: srid, geo_type: geo_type, has_m: has_m, has_z: has_z)}"
92
+ values << "#{METADATA_TOKENS[:default_prefix]}#{encode_default(default, geographic: geographic, srid: srid,
93
+ geo_type: geo_type, has_m: has_m, has_z: has_z)}"
88
94
  end
89
95
  values.compact_blank.join(" ")
90
96
  end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module Mysql2Rgeo
6
- VERSION = "8.0.4"
6
+ VERSION = "8.0.5"
7
7
  end
8
8
  end
9
9
  end
@@ -35,7 +35,7 @@ module ActiveRecord
35
35
  config = config.symbolize_keys
36
36
  config[:flags] ||= 0
37
37
 
38
- if config[:flags].kind_of? Array
38
+ if config[:flags].is_a? Array
39
39
  config[:flags].push "FOUND_ROWS"
40
40
  else
41
41
  config[:flags] |= Mysql2::Client::FOUND_ROWS
@@ -45,7 +45,7 @@ module ActiveRecord
45
45
  ConnectionAdapters::Mysql2RgeoAdapter.new_client(config),
46
46
  logger,
47
47
  nil,
48
- config,
48
+ config
49
49
  )
50
50
  end
51
51
  end
@@ -58,23 +58,23 @@ module ActiveRecord
58
58
 
59
59
  SPATIAL_COLUMN_OPTIONS =
60
60
  {
61
- geography: { type: "geometry", geographic: true },
62
- geometry: {},
63
- geometrycollection: {},
61
+ geography: { type: "geometry", geographic: true },
62
+ geometry: {},
63
+ geometrycollection: {},
64
64
  geometry_collection: { type: "geometrycollection" },
65
- linestring: {},
66
- line_string: { type: "linestring" },
67
- multilinestring: {},
68
- multi_line_string: { type: "multilinestring" },
69
- multipoint: {},
70
- multi_point: { type: "multipoint" },
71
- multipolygon: {},
72
- multi_polygon: { type: "multipolygon" },
73
- spatial: { type: "geometry" },
74
- point: {},
75
- polygon: {},
76
- st_point: { type: "point" },
77
- st_polygon: { type: "polygon" }
65
+ linestring: {},
66
+ line_string: { type: "linestring" },
67
+ multilinestring: {},
68
+ multi_line_string: { type: "multilinestring" },
69
+ multipoint: {},
70
+ multi_point: { type: "multipoint" },
71
+ multipolygon: {},
72
+ multi_polygon: { type: "multipolygon" },
73
+ spatial: { type: "geometry" },
74
+ point: {},
75
+ polygon: {},
76
+ st_point: { type: "point" },
77
+ st_polygon: { type: "polygon" }
78
78
  }.freeze
79
79
 
80
80
  DEFAULT_SRID = 0
@@ -97,78 +97,77 @@ module ActiveRecord
97
97
  # Add spatial types
98
98
  # Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
99
99
  super.merge(
100
- geometry: { name: "geometry" },
101
- geometrycollection: { name: "geometrycollection" },
102
- line_string: { name: "linestring" },
103
- linestring: { name: "linestring" },
104
- st_point: { name: "point" },
105
- st_polygon: { name: "polygon" },
106
- multi_line_string: { name: "multilinestring" },
107
- multi_point: { name: "multipoint" },
108
- multi_polygon: { name: "multipolygon" },
109
- spatial: { name: "geometry" },
110
- point: { name: "point" },
111
- polygon: { name: "polygon" }
100
+ geometry: { name: "geometry" },
101
+ geometrycollection: { name: "geometrycollection" },
102
+ line_string: { name: "linestring" },
103
+ linestring: { name: "linestring" },
104
+ st_point: { name: "point" },
105
+ st_polygon: { name: "polygon" },
106
+ multi_line_string: { name: "multilinestring" },
107
+ multi_point: { name: "multipoint" },
108
+ multi_polygon: { name: "multipolygon" },
109
+ spatial: { name: "geometry" },
110
+ point: { name: "point" },
111
+ polygon: { name: "polygon" }
112
112
  )
113
113
  end
114
114
 
115
115
  class << self
116
-
117
116
  private
118
- def initialize_type_map(m)
119
- super
120
-
121
- {
122
- "geography" => "geometry",
123
- "geometry" => "geometry",
124
- "geometry_collection" => "geometrycollection",
125
- "line_string" => "linestring",
126
- "multi_line_string" => "multilinestring",
127
- "multi_point" => "multipoint",
128
- "multi_polygon" => "multipolygon",
129
- "st_point" => "point",
130
- "st_polygon" => "polygon",
131
- }.each do |registered_type, geo_type|
132
- m.register_type(registered_type) do |sql_type|
133
- Type::Spatial.new(sql_type.to_s, geo_type: geo_type)
134
- end
135
- end
136
117
 
137
- [
138
- /\Ageometry(?:\(.*\))?\z/i,
139
- /\Ageography(?:\(.*\))?\z/i,
140
- /\Apoint(?:\s.*)?\z/i,
141
- /\Alinestring(?:\s.*)?\z/i,
142
- /\Apolygon(?:\s.*)?\z/i,
143
- /\Amultipoint(?:\s.*)?\z/i,
144
- /\Amultilinestring(?:\s.*)?\z/i,
145
- /\Amultipolygon(?:\s.*)?\z/i,
146
- /\Ageometrycollection(?:\s.*)?\z/i,
147
- ].each do |pattern|
148
- m.register_type(pattern) do |sql_type|
149
- Type::Spatial.new(sql_type.to_s)
150
- end
118
+ def initialize_type_map(m)
119
+ super
120
+
121
+ {
122
+ "geography" => "geometry",
123
+ "geometry" => "geometry",
124
+ "geometry_collection" => "geometrycollection",
125
+ "line_string" => "linestring",
126
+ "multi_line_string" => "multilinestring",
127
+ "multi_point" => "multipoint",
128
+ "multi_polygon" => "multipolygon",
129
+ "st_point" => "point",
130
+ "st_polygon" => "polygon",
131
+ }.each do |registered_type, geo_type|
132
+ m.register_type(registered_type) do |sql_type|
133
+ Type::Spatial.new(sql_type.to_s, geo_type: geo_type)
151
134
  end
135
+ end
152
136
 
153
- {
154
- st_point: "point",
155
- st_polygon: "polygon",
156
- line_string: "linestring",
157
- multi_line_string: "multilinestring",
158
- multi_point: "multipoint",
159
- multi_polygon: "multipolygon",
160
- }.each do |alias_type, geo_type|
161
- ActiveRecord::Type.register(alias_type) do |_, **kwargs|
162
- Type::Spatial.new(geo_type, geo_type: geo_type, **kwargs)
163
- end
137
+ [
138
+ /\Ageometry(?:\(.*\))?\z/i,
139
+ /\Ageography(?:\(.*\))?\z/i,
140
+ /\Apoint(?:\s.*)?\z/i,
141
+ /\Alinestring(?:\s.*)?\z/i,
142
+ /\Apolygon(?:\s.*)?\z/i,
143
+ /\Amultipoint(?:\s.*)?\z/i,
144
+ /\Amultilinestring(?:\s.*)?\z/i,
145
+ /\Amultipolygon(?:\s.*)?\z/i,
146
+ /\Ageometrycollection(?:\s.*)?\z/i,
147
+ ].each do |pattern|
148
+ m.register_type(pattern) do |sql_type|
149
+ Type::Spatial.new(sql_type.to_s)
164
150
  end
151
+ end
165
152
 
153
+ {
154
+ st_point: "point",
155
+ st_polygon: "polygon",
156
+ line_string: "linestring",
157
+ multi_line_string: "multilinestring",
158
+ multi_point: "multipoint",
159
+ multi_polygon: "multipolygon",
160
+ }.each do |alias_type, geo_type|
161
+ ActiveRecord::Type.register(alias_type) do |_, **kwargs|
162
+ Type::Spatial.new(geo_type, geo_type: geo_type, **kwargs)
163
+ end
166
164
  end
165
+ end
167
166
  end
168
167
 
169
168
  TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }
170
169
  TYPE_MAP_WITH_BOOLEAN = Type::TypeMap.new(TYPE_MAP).tap do |m|
171
- m.register_type %r(^tinyint\(1\))i, Type::Boolean.new
170
+ m.register_type(/^tinyint\(1\)/i, Type::Boolean.new)
172
171
  end
173
172
 
174
173
  def supports_spatial?
@@ -211,9 +210,10 @@ module ActiveRecord
211
210
  end
212
211
 
213
212
  private
214
- def type_map
215
- emulate_booleans ? TYPE_MAP_WITH_BOOLEAN : TYPE_MAP
216
- end
213
+
214
+ def type_map
215
+ emulate_booleans ? TYPE_MAP_WITH_BOOLEAN : TYPE_MAP
216
+ end
217
217
  end
218
218
  end
219
219
  end
@@ -41,9 +41,7 @@ module ActiveRecord
41
41
  has_z = Regexp.last_match(2).casecmp("z").zero?
42
42
  has_m = Regexp.last_match(3).casecmp("m").zero?
43
43
  end
44
- if params.last =~ /(\d+)/
45
- srid = Regexp.last_match(1).to_i
46
- end
44
+ srid = Regexp.last_match(1).to_i if params.last =~ /(\d+)/
47
45
  elsif sql_type =~ /\A(geography|geometry)\z/i
48
46
  geographic = Regexp.last_match(1).casecmp("geography").zero?
49
47
  geo_type = Regexp.last_match(1)
@@ -82,7 +80,7 @@ module ActiveRecord
82
80
  has_z: @has_z,
83
81
  sql_type: @geographic ? "geography" : "geometry",
84
82
  srid: @srid
85
- )
83
+ )
86
84
  end
87
85
 
88
86
  def klass
@@ -118,7 +116,7 @@ module ActiveRecord
118
116
  def cast_value(value)
119
117
  return if value.nil?
120
118
 
121
- ::String === value ? parse_wkt(value) : value
119
+ value.is_a?(::String) ? parse_wkt(value) : value
122
120
  end
123
121
 
124
122
  # convert WKT string into RGeo object
@@ -126,7 +124,7 @@ module ActiveRecord
126
124
  marker = string[4, 1]
127
125
  if ["\x00", "\x01"].include?(marker)
128
126
  @srid = string[0, 4].unpack1(marker == "\x01" ? "V" : "N")
129
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(string[4..-1])
127
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(string[4..])
130
128
  elsif string.match?(/\A[0-9a-fA-F]+\z/)
131
129
  original_srid = @srid
132
130
  parser = RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid)
@@ -139,9 +137,9 @@ module ActiveRecord
139
137
 
140
138
  if string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
141
139
  @srid = string[0, 8].to_i(16)
142
- @srid = [@srid].pack("V").unpack("N").first if string[9, 1] == "1"
140
+ @srid = [@srid].pack("V").unpack1("N") if string[9, 1] == "1"
143
141
  parser = RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid)
144
- return parser.parse([string[8..-1]].pack("H*"))
142
+ return parser.parse([string[8..]].pack("H*"))
145
143
  end
146
144
 
147
145
  parser.parse([string].pack("H*"))
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-mysql2rgeo-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.4
4
+ version: 8.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yongdae Hwang
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-03-31 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 7.2.0
18
+ version: '7.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 7.2.0
25
+ version: '7.2'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rgeo-activerecord
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +79,6 @@ dependencies:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
81
  version: '2.0'
83
- - !ruby/object:Gem::Dependency
84
- name: mocha
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.1'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.1'
97
82
  - !ruby/object:Gem::Dependency
98
83
  name: benchmark-ips
99
84
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +137,6 @@ metadata:
152
137
  source_code_uri: https://github.com/stadia/activerecord-mysql2rgeo-adapter
153
138
  documentation_uri: https://github.com/stadia/activerecord-mysql2rgeo-adapter/blob/main/README.md
154
139
  rubygems_mfa_required: 'true'
155
- post_install_message:
156
140
  rdoc_options: []
157
141
  require_paths:
158
142
  - lib
@@ -167,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
151
  - !ruby/object:Gem::Version
168
152
  version: '0'
169
153
  requirements: []
170
- rubygems_version: 3.3.27
171
- signing_key:
154
+ rubygems_version: 4.0.20
172
155
  specification_version: 4
173
156
  summary: ActiveRecord adapter for MySQL, based on RGeo.
174
157
  test_files: []