armg 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/armg.rb +1 -1
- data/lib/armg/armg.rb +22 -0
- data/lib/armg/mysql_geometry.rb +17 -5
- data/lib/armg/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e6b3ee252fb5c11271a5ef0ae7ab318d4a509d
|
4
|
+
data.tar.gz: 2c2be3dad6a3db05718938e80b238debc0c13168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9aa995ba5b6b5a228ab6f6eac7c2640a2e9db5a37de2e71e759c3b6104026277d18e688fbf451853a9258257be461470719e4be8049b5fcda7e3ee978d2b6c
|
7
|
+
data.tar.gz: 1f609a7196e10b8c29e71399988f45389443df8960084347cce53e3992b2920ced2b8051b034776c5391907091006272aade83b9f88efb5f966ed393172c66e2
|
data/lib/armg.rb
CHANGED
@@ -7,6 +7,7 @@ ActiveSupport.on_load(:active_record) do
|
|
7
7
|
require 'armg/abstract_mysql_adapter_ext'
|
8
8
|
require 'armg/mysql_geometry'
|
9
9
|
require 'armg/table_definition_ext'
|
10
|
+
require 'armg/armg'
|
10
11
|
|
11
12
|
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES[:geometry] = { name: "geometry" }
|
12
13
|
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(Armg::AbstractMysqlAdapterExt)
|
@@ -14,4 +15,3 @@ ActiveSupport.on_load(:active_record) do
|
|
14
15
|
ActiveRecord::ConnectionAdapters::MySQL::TableDefinition.prepend(Armg::TableDefinitionExt)
|
15
16
|
ActiveRecord::ConnectionAdapters::MySQL::Table.prepend(Armg::TableDefinitionExt)
|
16
17
|
end
|
17
|
-
|
data/lib/armg/armg.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Armg
|
2
|
+
@wkb_parser_factory = Armg::MysqlGeometry::DEFAULT_WKB_PARSER_FACTORY
|
3
|
+
@wkb_generator_factory = Armg::MysqlGeometry::DEFAULT_WKB_GENERATOR_FACTORY
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def wkb_parser_factory
|
7
|
+
@wkb_parser_factory
|
8
|
+
end
|
9
|
+
|
10
|
+
def wkb_parser_factory=(factory)
|
11
|
+
@wkb_parser_factory = factory
|
12
|
+
end
|
13
|
+
|
14
|
+
def wkb_generator_factory
|
15
|
+
@wkb_generator_factory
|
16
|
+
end
|
17
|
+
|
18
|
+
def wkb_generator_factory=(factory)
|
19
|
+
@wkb_generator_factory = factory
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/armg/mysql_geometry.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
class Armg::MysqlGeometry < ActiveModel::Type::Value
|
2
2
|
include ActiveModel::Type::Helpers::Mutable
|
3
3
|
|
4
|
+
DEFAULT_WKB_PARSER_FACTORY = proc do |wkb|
|
5
|
+
srid = wkb[0..3].unpack('L<').first
|
6
|
+
[ RGeo::WKRep::WKBParser.new(nil, support_ewkb: true, default_srid: srid),
|
7
|
+
wkb[4..-1],
|
8
|
+
]
|
9
|
+
end
|
10
|
+
|
11
|
+
DEFAULT_WKB_GENERATOR_FACTORY = proc do |value|
|
12
|
+
[ RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true),
|
13
|
+
[value.srid].pack('L<'),
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
4
17
|
def type
|
5
18
|
:geometry
|
6
19
|
end
|
7
20
|
|
8
21
|
def deserialize(value)
|
9
22
|
if value.is_a?(::String)
|
10
|
-
|
11
|
-
wkb_parser
|
12
|
-
wkb_parser.parse(value[4..-1])
|
23
|
+
wkb_parser, value = Armg.wkb_parser_factory.call(value)
|
24
|
+
wkb_parser.parse(value)
|
13
25
|
else
|
14
26
|
value
|
15
27
|
end
|
@@ -19,9 +31,9 @@ class Armg::MysqlGeometry < ActiveModel::Type::Value
|
|
19
31
|
if value.nil?
|
20
32
|
nil
|
21
33
|
else
|
22
|
-
wkb_generator =
|
34
|
+
wkb_generator, srid = Armg.wkb_generator_factory.call(value)
|
23
35
|
wkb = wkb_generator.generate(value)
|
24
|
-
|
36
|
+
srid + wkb
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
data/lib/armg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: armg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- docker-compose.yml
|
129
129
|
- lib/armg.rb
|
130
130
|
- lib/armg/abstract_mysql_adapter_ext.rb
|
131
|
+
- lib/armg/armg.rb
|
131
132
|
- lib/armg/mysql_geometry.rb
|
132
133
|
- lib/armg/table_definition_ext.rb
|
133
134
|
- lib/armg/version.rb
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.6.12
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: Add MySQL geometry type to Active Record.
|