activerecord-trilogis-adapter 7.0.2 → 8.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.
@@ -2,102 +2,256 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module Type
5
- class Spatial < Binary # :nodoc:
6
- # sql_type is a string that comes from the database definition
7
- # examples:
8
- # "geometry"
9
- # "geometry NOT NULL"
10
- # "geometry"
5
+ class Spatial < Binary
6
+ attr_reader :geo_type, :srid
7
+
11
8
  def initialize(sql_type = "geometry")
12
9
  @sql_type = sql_type
13
10
  @geo_type, @srid = self.class.parse_sql_type(sql_type)
14
11
  end
15
12
 
16
- # sql_type: geometry, geometry(Point), geometry(Point,4326), ...
17
- #
18
- # returns [geo_type, srid]
19
- # geo_type: geometry, point, line_string, polygon, ...
20
- # srid: 1234
13
+ def type
14
+ :geometry
15
+ end
16
+
17
+ # Class method for parsing SQL type
21
18
  def self.parse_sql_type(sql_type)
22
- geo_type, srid = nil, 0
23
- if sql_type =~ /(geometry)\((.*)\)$/i
24
- # geometry(Point)
25
- # geometry(Point,4326)
26
- params = Regexp.last_match(2).split(",")
27
- if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
28
- geo_type = Regexp.last_match(1)
29
- end
30
- if params.last =~ /(\d+)/
31
- srid = Regexp.last_match(1).to_i
32
- end
19
+ sql_type = sql_type.to_s.downcase
20
+
21
+ # Extract geometry type and SRID from SQL type
22
+ # Examples: "geometry", "point", "linestring", "geometry(Point,4326)"
23
+ if sql_type =~ /(\w+)(?:\((\w+)(?:,(\d+))?\))?/
24
+ geo_type = Regexp.last_match(1)
25
+ sub_type = Regexp.last_match(2)
26
+ srid = Regexp.last_match(3).to_i
27
+
28
+ geo_type = sub_type.downcase if sub_type
29
+ [geo_type, srid]
33
30
  else
34
- # geometry
35
- # otherType(a,b)
36
- geo_type = sql_type
31
+ [sql_type, 0]
37
32
  end
38
- [geo_type, srid]
39
33
  end
40
34
 
41
- def spatial_factory
42
- @spatial_factories ||= {}
35
+ def serialize(value)
36
+ return nil if value.nil?
43
37
 
44
- @spatial_factories[@srid] ||= RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
45
- geo_type: @geo_type,
46
- sql_type: @sql_type,
47
- srid: @srid
48
- )
38
+ # Return the RGeo geometry object as-is
39
+ # The adapter's quote method will handle conversion to SQL
40
+ cast(value)
49
41
  end
50
42
 
51
- def klass
52
- type == :geometry ? RGeo::Feature::Geometry : super
43
+ def deserialize(value)
44
+ return nil if value.nil?
45
+
46
+ # Handle RGeo objects directly
47
+ return value if value.is_a?(RGeo::Feature::Instance)
48
+
49
+ # Convert to string if needed and check for empty
50
+ value = value.to_s if value.respond_to?(:to_s)
51
+ return nil if value.empty?
52
+
53
+ # MySQL returns binary WKB with SRID prefix
54
+ # Try to parse as binary WKB first
55
+ if [Encoding::ASCII_8BIT, Encoding::BINARY].include?(value.encoding)
56
+ result = parse_wkb_binary(value)
57
+ return result if result
58
+ end
59
+
60
+ # Try hex WKB
61
+ return parse_wkb_hex(value) if value.match?(/\A[0-9a-fA-F]+\z/)
62
+
63
+ # Try WKT
64
+ parse_wkt(value)
53
65
  end
54
66
 
55
- def spatial?
56
- true
67
+ def cast(value)
68
+ return nil if value.nil?
69
+
70
+ # Check by class name instead of is_a? due to ActiveRecord wrapping values
71
+ if value.is_a?(RGeo::Feature::Instance)
72
+ value
73
+ elsif value.instance_of?(::String) || value.respond_to?(:to_str)
74
+ parse_string(value.to_s)
75
+ elsif value.is_a?(Hash)
76
+ cast_hash(value)
77
+ end
57
78
  end
58
79
 
59
- def type
60
- :geometry
80
+ def changed?(old_value, new_value, _new_value_before_type_cast)
81
+ old_value != new_value
61
82
  end
62
83
 
63
- # support setting an RGeo object or a WKT string
64
- def serialize(value)
65
- return if value.nil?
84
+ def changed_in_place?(raw_old_value, new_value)
85
+ deserialize(raw_old_value) != new_value
86
+ end
87
+
88
+ private
66
89
 
67
- geo_value = cast_value(value)
90
+ def parse_sql_type(sql_type)
91
+ original_sql_type = sql_type.to_s
92
+ sql_type = sql_type.to_s.downcase
68
93
 
69
- # TODO: - only valid types should be allowed
70
- # e.g. linestring is not valid for point column
71
- raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
94
+ # Only parse known spatial types
95
+ # For non-spatial types, return them unchanged
96
+ spatial_types = %w[geometry point linestring polygon multipoint multilinestring multipolygon geometrycollection]
72
97
 
73
- geo_value
98
+ # Check if it's a spatial type
99
+ base_type = sql_type.split("(").first
100
+ return [original_sql_type, 0] unless spatial_types.include?(base_type)
101
+
102
+ # Extract geometry type and SRID from SQL type
103
+ # Examples: "geometry", "point", "linestring", "geometry(Point,4326)"
104
+ if sql_type =~ /(\w+)(?:\((\w+)(?:,(\d+))?\))?/
105
+ geo_type = Regexp.last_match(1)
106
+ sub_type = Regexp.last_match(2)
107
+ srid = Regexp.last_match(3).to_i
108
+
109
+ geo_type = sub_type.downcase if sub_type
110
+ [geo_type, srid]
111
+ else
112
+ [sql_type, 0]
113
+ end
74
114
  end
75
115
 
76
- private
116
+ def parse_string(string)
117
+ return nil if string.blank?
77
118
 
78
- def cast_value(value)
79
- return if value.nil?
119
+ # Handle EWKT format: SRID=xxxx;GEOMETRY(...)
120
+ if string =~ /SRID=(\d+);(.+)/i
121
+ srid = Regexp.last_match(1).to_i
122
+ wkt = Regexp.last_match(2)
80
123
 
81
- ::String === value ? parse_wkt(value) : value
124
+ # Use SpatialFactoryStore to get the appropriate factory
125
+ geo_factory = RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
126
+ geo_type: @geo_type,
127
+ sql_type: @sql_type,
128
+ srid: srid
129
+ )
130
+ begin
131
+ return RGeo::WKRep::WKTParser.new(geo_factory, support_ewkt: true, default_srid: srid).parse(wkt)
132
+ rescue RGeo::Error::ParseError
133
+ return nil
134
+ end
135
+ end
136
+
137
+ # Try to parse as WKT
138
+ if string.match?(/^[A-Z]/i)
139
+ parse_wkt(string)
140
+ # Try to parse as WKB hex
141
+ elsif string.match?(/^[0-9a-fA-F]+$/)
142
+ parse_wkb_hex(string)
143
+ end
82
144
  end
83
145
 
84
- # convert WKT string into RGeo object
85
146
  def parse_wkt(string)
86
- marker = string[4, 1]
87
- if ["\x00", "\x01"].include?(marker)
88
- @srid = string[0, 4].unpack1(marker == "\x01" ? "V" : "N")
89
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(string[4..-1])
90
- elsif string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
91
- @srid = string[0, 8].to_i(16)
92
- @srid = [@srid].pack("V").unpack("N").first if string[9, 1] == "1"
93
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(string[8..-1])
147
+ # Support EWKT (Extended Well-Known Text) format with SRID
148
+ RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
149
+ rescue RGeo::Error::ParseError
150
+ # WKT parsing failed, return nil
151
+ nil
152
+ end
153
+
154
+ def parse_wkb_hex(hex_string)
155
+ return nil if hex_string.nil? || hex_string.empty?
156
+
157
+ binary = convert_hex_to_binary(hex_string)
158
+ parse_binary_with_srid(binary)
159
+ rescue RGeo::Error::ParseError, ArgumentError
160
+ nil
161
+ end
162
+
163
+ def convert_hex_to_binary(hex_string)
164
+ # MySQL returns WKB as hex string
165
+ [hex_string].pack("H*")
166
+ end
167
+
168
+ def parse_binary_with_srid(binary)
169
+ # MySQL internal format: first 4 bytes are SRID (little-endian), then WKB
170
+ if binary.length >= 5
171
+ srid = extract_srid(binary)
172
+ wkb_data = binary[4..]
173
+ parse_wkb_with_factory(wkb_data, srid)
94
174
  else
95
- string, @srid = Arel::Visitors::Trilogis.parse_node(string)
96
- RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
175
+ parse_standard_wkb(binary)
97
176
  end
98
- rescue RGeo::Error::ParseError, RGeo::Error::InvalidGeometry
177
+ end
178
+
179
+ def extract_srid(binary)
180
+ # V = unsigned 32-bit little-endian
181
+ binary[0..3].unpack1("V")
182
+ end
183
+
184
+ def parse_wkb_with_factory(wkb_data, srid)
185
+ geo_factory = create_factory_for_srid(srid)
186
+ RGeo::WKRep::WKBParser.new(geo_factory, support_ewkb: true, default_srid: srid).parse(wkb_data)
187
+ end
188
+
189
+ def create_factory_for_srid(srid)
190
+ # Geographic SRIDs (4326, 4269, 4267, 4258, 4019) need spherical factory
191
+ if geographic_srid?(srid)
192
+ RGeo::Geographic.spherical_factory(srid: srid)
193
+ else
194
+ RGeo::Cartesian.preferred_factory(srid: srid)
195
+ end
196
+ end
197
+
198
+ def parse_standard_wkb(binary)
199
+ # Fall back to standard WKB parsing with EWKB support
200
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(binary)
201
+ end
202
+
203
+ # Check if SRID represents a geographic coordinate system
204
+ def geographic_srid?(srid)
205
+ # Common geographic SRIDs that use latitude-longitude
206
+ [4326, 4269, 4267, 4258, 4019].include?(srid)
207
+ end
208
+
209
+ def parse_wkb_binary(binary_string)
210
+ return nil if binary_string.nil? || binary_string.empty?
211
+
212
+ # MySQL internal format: first 4 bytes are SRID (little-endian), then WKB
213
+ if binary_string.length >= 5
214
+ srid = binary_string[0..3].unpack1("V") # V = unsigned 32-bit little-endian
215
+ wkb_data = binary_string[4..]
216
+
217
+ # Create appropriate factory based on SRID
218
+ # Geographic SRIDs (4326, 4269, 4267, 4258, 4019) need spherical factory
219
+ geo_factory = if geographic_srid?(srid)
220
+ RGeo::Geographic.spherical_factory(srid: srid)
221
+ else
222
+ RGeo::Cartesian.preferred_factory(srid: srid)
223
+ end
224
+
225
+ # Support EWKB format
226
+ RGeo::WKRep::WKBParser.new(geo_factory, support_ewkb: true, default_srid: srid).parse(wkb_data)
227
+ else
228
+ # Fall back to standard WKB parsing with EWKB support
229
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(binary_string)
230
+ end
231
+ rescue RGeo::Error::ParseError, ArgumentError
232
+ # Failed to parse, return nil
99
233
  nil
100
234
  end
235
+
236
+ def cast_hash(hash)
237
+ return nil unless hash.is_a?(Hash)
238
+
239
+ # Support GeoJSON-like hashes (allow symbol or string keys)
240
+ normalized_hash = hash.transform_keys(&:to_s)
241
+ return unless normalized_hash["type"] && normalized_hash["coordinates"]
242
+
243
+ RGeo::GeoJSON.decode(normalized_hash.to_json, geo_factory: spatial_factory)
244
+ end
245
+
246
+ def spatial_factory
247
+ @spatial_factories ||= {}
248
+
249
+ @spatial_factories[@srid] ||= RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
250
+ geo_type: @geo_type,
251
+ sql_type: @sql_type,
252
+ srid: @srid
253
+ )
254
+ end
101
255
  end
102
256
  end
103
257
  end
@@ -1,4 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_record/connection_adapters/trilogis_adapter"
4
- require "active_record/connection_adapters/trilogis/railtie"
3
+ require "active_record"
4
+
5
+ # Load ActiveRecord dependencies explicitly to ensure correct loading order
6
+ # This approach works across all Ruby versions and avoids autoload issues
7
+ require_relative "active_record/dependency_loader"
8
+
9
+ require "active_record/connection_adapters/trilogy_adapter"
10
+ require "rgeo"
11
+ require "rgeo/active_record"
12
+
13
+ # Load the adapter
14
+ require_relative "active_record/connection_adapters/trilogis_adapter"
15
+
16
+ # Load railtie if Rails is defined
17
+ require_relative "active_record/connection_adapters/trilogis/railtie" if defined?(Rails)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-trilogis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.2
4
+ version: 8.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ether Moon
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-04-18 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,111 +15,178 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 7.0.0
18
+ version: '8.0'
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.0.0
25
+ version: '8.0'
27
26
  - !ruby/object:Gem::Dependency
28
- name: rgeo-activerecord
27
+ name: rgeo
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: 7.0.0
32
+ version: '3.0'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: 7.0.0
39
+ version: '3.0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: activerecord-trilogy-adapter
41
+ name: rgeo-activerecord
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: 3.1.0
46
+ version: '8.0'
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: 3.1.0
53
+ version: '8.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: minitest
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.4'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.4'
68
+ - !ruby/object:Gem::Dependency
69
+ name: mocha
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: ostruct
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
55
96
  - !ruby/object:Gem::Dependency
56
97
  name: rake
57
98
  requirement: !ruby/object:Gem::Requirement
58
99
  requirements:
59
100
  - - "~>"
60
101
  - !ruby/object:Gem::Version
61
- version: '12.0'
102
+ version: '13.0'
62
103
  type: :development
63
104
  prerelease: false
64
105
  version_requirements: !ruby/object:Gem::Requirement
65
106
  requirements:
66
107
  - - "~>"
67
108
  - !ruby/object:Gem::Version
68
- version: '12.0'
109
+ version: '13.0'
69
110
  - !ruby/object:Gem::Dependency
70
- name: minitest
111
+ name: rubocop
71
112
  requirement: !ruby/object:Gem::Requirement
72
113
  requirements:
73
114
  - - "~>"
74
115
  - !ruby/object:Gem::Version
75
- version: '5.4'
116
+ version: '1.81'
76
117
  type: :development
77
118
  prerelease: false
78
119
  version_requirements: !ruby/object:Gem::Requirement
79
120
  requirements:
80
121
  - - "~>"
81
122
  - !ruby/object:Gem::Version
82
- version: '5.4'
123
+ version: '1.81'
83
124
  - !ruby/object:Gem::Dependency
84
- name: mocha
125
+ name: rubocop-minitest
85
126
  requirement: !ruby/object:Gem::Requirement
86
127
  requirements:
87
128
  - - "~>"
88
129
  - !ruby/object:Gem::Version
89
- version: '2.0'
130
+ version: '0.38'
90
131
  type: :development
91
132
  prerelease: false
92
133
  version_requirements: !ruby/object:Gem::Requirement
93
134
  requirements:
94
135
  - - "~>"
95
136
  - !ruby/object:Gem::Version
96
- version: '2.0'
137
+ version: '0.38'
97
138
  - !ruby/object:Gem::Dependency
98
- name: appraisal
139
+ name: rubocop-performance
99
140
  requirement: !ruby/object:Gem::Requirement
100
141
  requirements:
101
142
  - - "~>"
102
143
  - !ruby/object:Gem::Version
103
- version: '2.0'
144
+ version: '1.24'
104
145
  type: :development
105
146
  prerelease: false
106
147
  version_requirements: !ruby/object:Gem::Requirement
107
148
  requirements:
108
149
  - - "~>"
109
150
  - !ruby/object:Gem::Version
110
- version: '2.0'
111
- description: ActiveRecord connection adapter for MySQL. It is based on the stock MySQL
112
- adapter, and adds built-in support for the spatial extensions provided by MySQL.
113
- It uses the RGeo library to represent spatial data in Ruby.
151
+ version: '1.24'
152
+ - !ruby/object:Gem::Dependency
153
+ name: rubocop-rake
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '0.6'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '0.6'
166
+ - !ruby/object:Gem::Dependency
167
+ name: trilogy
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '2.9'
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '2.9'
180
+ description: ActiveRecord connection adapter for MySQL. It extends the Rails built-in
181
+ Trilogy adapter and adds spatial extensions support via RGeo. Compatible with Rails
182
+ 8.0+ native Trilogy adapter. Requires Ruby 3.2+ and Rails 8.0+.
114
183
  email: chipseru@gmail.com
115
184
  executables: []
116
185
  extensions: []
117
186
  extra_rdoc_files: []
118
187
  files:
119
- - LICENSE.txt
188
+ - LICENSE
120
189
  - lib/active_record/connection_adapters/trilogis/arel_tosql.rb
121
- - lib/active_record/connection_adapters/trilogis/column_methods.rb
122
- - lib/active_record/connection_adapters/trilogis/connection.rb
123
- - lib/active_record/connection_adapters/trilogis/rails/dbconsole.rb
124
190
  - lib/active_record/connection_adapters/trilogis/railtie.rb
125
191
  - lib/active_record/connection_adapters/trilogis/schema_creation.rb
126
192
  - lib/active_record/connection_adapters/trilogis/schema_statements.rb
@@ -130,14 +196,15 @@ files:
130
196
  - lib/active_record/connection_adapters/trilogis/spatial_table_definition.rb
131
197
  - lib/active_record/connection_adapters/trilogis/version.rb
132
198
  - lib/active_record/connection_adapters/trilogis_adapter.rb
199
+ - lib/active_record/dependency_loader.rb
133
200
  - lib/active_record/tasks/trilogis_database_tasks.rb
134
201
  - lib/active_record/type/spatial.rb
135
202
  - lib/activerecord-trilogis-adapter.rb
136
203
  homepage: http://github.com/ether-moon/activerecord-trilogis-adapter
137
204
  licenses:
138
- - BSD-3-Clause
139
- metadata: {}
140
- post_install_message:
205
+ - MIT
206
+ metadata:
207
+ rubygems_mfa_required: 'true'
141
208
  rdoc_options: []
142
209
  require_paths:
143
210
  - lib
@@ -146,14 +213,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
213
  - - ">="
147
214
  - !ruby/object:Gem::Version
148
215
  version: 3.2.0
216
+ - - "<"
217
+ - !ruby/object:Gem::Version
218
+ version: '3.5'
149
219
  required_rubygems_version: !ruby/object:Gem::Requirement
150
220
  requirements:
151
221
  - - ">="
152
222
  - !ruby/object:Gem::Version
153
223
  version: '0'
154
224
  requirements: []
155
- rubygems_version: 3.5.6
156
- signing_key:
225
+ rubygems_version: 3.6.9
157
226
  specification_version: 4
158
- summary: ActiveRecord adapter for MySQL, based on RGeo.
227
+ summary: ActiveRecord adapter for MySQL with spatial extensions, built on Trilogy.
159
228
  test_files: []
data/LICENSE.txt DELETED
@@ -1,29 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- # Copyright 2012 Daniel Azuma
3
- #
4
- # All rights reserved.
5
- #
6
- # Redistribution and use in source and binary forms, with or without
7
- # modification, are permitted provided that the following conditions are met:
8
- #
9
- # * Redistributions of source code must retain the above copyright notice,
10
- # this list of conditions and the following disclaimer.
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- # * Neither the name of the copyright holder, nor the names of any other
15
- # contributors to this software, may be used to endorse or promote products
16
- # derived from this software without specific prior written permission.
17
- #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
- # POSSIBILITY OF SUCH DAMAGE.
29
- # -----------------------------------------------------------------------------
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module Trilogis
6
- module ColumnMethods
7
- def spatial(name, options = {})
8
- raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
9
-
10
- column(name, options[:type], **options)
11
- end
12
-
13
- def geometry(name, options = {})
14
- column(name, :geometry, **options)
15
- end
16
-
17
- def geometry_collection(name, options = {})
18
- column(name, :geometrycollection, **options)
19
- end
20
- alias geometrycollection geometry_collection
21
-
22
- def line_string(name, options = {})
23
- column(name, :linestring, **options)
24
- end
25
- alias linestring line_string
26
-
27
- def multi_line_string(name, options = {})
28
- column(name, :multilinestring, **options)
29
- end
30
- alias multilinestring multi_line_string
31
-
32
- def multi_point(name, options = {})
33
- column(name, :multipoint, **options)
34
- end
35
- alias multipoint multi_point
36
-
37
- def multi_polygon(name, options = {})
38
- column(name, :multipolygon, **options)
39
- end
40
- alias multipolygon multi_polygon
41
-
42
- def point(name, options = {})
43
- column(name, :point, **options)
44
- end
45
-
46
- def polygon(name, options = {})
47
- column(name, :polygon, **options)
48
- end
49
- end
50
- end
51
-
52
- MySQL::Table.include Trilogis::ColumnMethods
53
- end
54
- end