armg 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +21 -7
- data/Appraisals +7 -0
- data/README.md +36 -12
- data/armg.gemspec +1 -0
- data/docker-compose.yml +8 -2
- data/gemfiles/ar50.gemfile +7 -0
- data/gemfiles/ar51.gemfile +7 -0
- data/lib/armg.rb +4 -2
- data/lib/armg/armg.rb +10 -10
- data/lib/armg/mysql_geometry.rb +2 -5
- data/lib/armg/version.rb +1 -1
- data/lib/armg/{wkb_parser.rb → wkb_deserializer.rb} +4 -4
- data/lib/armg/wkb_serializer.rb +16 -0
- data/lib/armg/wkt_deserializer.rb +17 -0
- data/lib/armg/wkt_serializer.rb +16 -0
- data/test.rb +11 -0
- metadata +24 -4
- data/lib/armg/wkb_generator.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd750e12ff779d85ab6c3e37f061e65fbee07e2f
|
4
|
+
data.tar.gz: b17f2516d892fb0029552f2577379ff2b8709772
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6072cb270a02f58750bd7a884a73f82eba207ca57a174e7a12a7c5555f2487fc0a12245268a19ee0031616d220fa0d467ca315ba597f3eb5976fe39cbf97ba
|
7
|
+
data.tar.gz: bba7d5b0166f2f6310045b87dca715386d200bab7365ecec5f75284b62b56cab39d706ca5c03af1fa457cd8bcbe84904e3fa3c4f3d32a7683f58f2321198cf26
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,16 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
dist: trusty
|
2
|
+
sudo: required
|
3
|
+
group: edge
|
4
|
+
services:
|
5
|
+
- docker
|
3
6
|
language: ruby
|
4
7
|
rvm:
|
8
|
+
- 2.2.7
|
5
9
|
- 2.3.4
|
6
|
-
|
10
|
+
- 2.4.1
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/ar50.gemfile
|
13
|
+
- gemfiles/ar51.gemfile
|
14
|
+
before_install:
|
15
|
+
- gem install bundler
|
16
|
+
before_script:
|
17
|
+
- sudo service mysql stop
|
18
|
+
- docker-compose up -d
|
19
|
+
- function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P $1 ping; }
|
20
|
+
- for i in {1..60}; do mysql_ping 10056 && break; sleep 1; done
|
21
|
+
- for i in {1..60}; do mysql_ping 10057 && break; sleep 1; done
|
7
22
|
cache:
|
8
23
|
- bundler
|
9
24
|
- apt
|
10
|
-
services:
|
11
|
-
- mysql
|
12
25
|
env:
|
13
|
-
|
14
|
-
|
26
|
+
- ARMG_TEST_MYSQL_PORT=10056 ARMG_TEST_MYSQL_ENGINE=MyISAM
|
27
|
+
- ARMG_TEST_MYSQL_PORT=10057 ARMG_TEST_MYSQL_ENGINE=MyISAM
|
28
|
+
- ARMG_TEST_MYSQL_PORT=10057 ARMG_TEST_MYSQL_ENGINE=InnoDB
|
15
29
|
script:
|
16
30
|
- bundle exec rake
|
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -44,47 +44,71 @@ Geom.first
|
|
44
44
|
#=> #<Geom id: 1, location: #<RGeo::Cartesian::PointImpl:0x... "POINT (-122.1 47.3)">>
|
45
45
|
```
|
46
46
|
|
47
|
-
## Using
|
47
|
+
## Using WKT
|
48
48
|
|
49
49
|
```ruby
|
50
|
-
|
50
|
+
Armg.deserializer = Armg::WktDeserializer.new
|
51
|
+
Armg.serializer = Armg::WktSerializer.new
|
52
|
+
|
53
|
+
Geom.create!(location: 'Point(-122.1 47.3)')
|
54
|
+
|
55
|
+
Geom.first
|
56
|
+
#=> #<Geom id: 1, location: "Point (-122.1 47.3)">
|
57
|
+
```
|
58
|
+
|
59
|
+
## Using custom deserializer
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class CustomDeserializer
|
51
63
|
def initialize
|
52
64
|
factory = RGeo::Geographic.spherical_factory(srid: 0)
|
53
|
-
@
|
65
|
+
@wkb_parser = RGeo::WKRep::WKBParser.new(factory, support_ewkb: true)
|
54
66
|
end
|
55
67
|
|
56
|
-
def
|
68
|
+
def deserialize(wkb)
|
57
69
|
wkb_without_srid = wkb.b.slice(4..-1)
|
58
|
-
@
|
70
|
+
@wkb_parser.parse(wkb_without_srid)
|
59
71
|
end
|
60
72
|
end
|
61
73
|
|
62
|
-
Armg.
|
74
|
+
Armg.deserializer = CustomDeserializer.new
|
63
75
|
|
64
76
|
Geom.take
|
65
77
|
#=> #<Geom id: 1, location: #<RGeo::Geographic::SphericalPointImpl:0x... "POINT (-122.1 47.3)">>
|
66
78
|
```
|
67
79
|
|
68
|
-
## Using custom WKB
|
80
|
+
## Using custom WKB serializer
|
69
81
|
|
70
82
|
```ruby
|
71
|
-
class
|
83
|
+
class CustomSerializer
|
72
84
|
def initialize
|
73
85
|
@wkt_parser = RGeo::WKRep::WKTParser.new(nil, support_ewkt: true)
|
74
|
-
@
|
86
|
+
@wkb_generator = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)
|
75
87
|
end
|
76
88
|
|
77
|
-
def
|
89
|
+
def serialize(value)
|
78
90
|
if value.is_a?(String)
|
79
91
|
value = @wkt_parser.parse(value)
|
80
92
|
end
|
81
93
|
|
82
94
|
srid = "\x00\x00\x00\x00"
|
83
|
-
srid + @
|
95
|
+
srid + @wkb_generator.generate(value)
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
87
|
-
Armg.
|
99
|
+
Armg.serializer = CustomSerializer.new
|
88
100
|
|
89
101
|
Geom.create!(id: 4, location: 'Point(-122.1 47.3)')
|
90
102
|
```
|
103
|
+
|
104
|
+
## Running tests
|
105
|
+
|
106
|
+
```sh
|
107
|
+
docker-compose up -d
|
108
|
+
bundle install
|
109
|
+
bundle exec appraisal install
|
110
|
+
bundle exec appraisal ar51 rake
|
111
|
+
# bundle exec appraisal ar50 rake
|
112
|
+
# ARMG_TEST_MYSQL_PORT=10057 bundle exec appraisal ar51 rake # MySQL 5.7
|
113
|
+
# ARMG_TEST_MYSQL_PORT=10057 ARMG_TEST_MYSQL_ENGINE=InnoDB bundle exec appraisal ar51 rake
|
114
|
+
```
|
data/armg.gemspec
CHANGED
data/docker-compose.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
version: '2'
|
2
2
|
services:
|
3
|
-
|
3
|
+
mysql56:
|
4
4
|
ports:
|
5
|
-
- "
|
5
|
+
- "10056:3306"
|
6
6
|
image: "mysql:5.6"
|
7
7
|
environment:
|
8
8
|
- MYSQL_ALLOW_EMPTY_PASSWORD=1
|
9
|
+
mysql57:
|
10
|
+
ports:
|
11
|
+
- "10057:3306"
|
12
|
+
image: "mysql:5.7"
|
13
|
+
environment:
|
14
|
+
- MYSQL_ALLOW_EMPTY_PASSWORD=1
|
data/lib/armg.rb
CHANGED
@@ -4,8 +4,10 @@ require 'armg/version'
|
|
4
4
|
|
5
5
|
ActiveSupport.on_load(:active_record) do
|
6
6
|
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
7
|
-
require 'armg/
|
8
|
-
require 'armg/
|
7
|
+
require 'armg/wkb_serializer'
|
8
|
+
require 'armg/wkb_deserializer'
|
9
|
+
require 'armg/wkt_serializer'
|
10
|
+
require 'armg/wkt_deserializer'
|
9
11
|
require 'armg/abstract_mysql_adapter_ext'
|
10
12
|
require 'armg/mysql_geometry'
|
11
13
|
require 'armg/table_definition_ext'
|
data/lib/armg/armg.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module Armg
|
2
|
-
@
|
3
|
-
@
|
2
|
+
@deserializer = Armg::WkbDeserializer.new
|
3
|
+
@serializer = Armg::WkbSerializer.new
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def deserializer
|
7
|
+
@deserializer
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
@
|
10
|
+
def deserializer=(v)
|
11
|
+
@deserializer = v
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
@
|
14
|
+
def serializer
|
15
|
+
@serializer
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
@
|
18
|
+
def serializer=(v)
|
19
|
+
@serializer = v
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/armg/mysql_geometry.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
class Armg::MysqlGeometry < ActiveModel::Type::Value
|
2
|
-
DEFAULT_WKB_PARSER = Armg::WkbParser.new
|
3
|
-
DEFAULT_WKB_GENERATOR = Armg::WkbGenerator.new
|
4
|
-
|
5
2
|
def type
|
6
3
|
:geometry
|
7
4
|
end
|
8
5
|
|
9
6
|
def deserialize(value)
|
10
7
|
if value.is_a?(::String)
|
11
|
-
Armg.
|
8
|
+
Armg.deserializer.deserialize(value)
|
12
9
|
else
|
13
10
|
value
|
14
11
|
end
|
@@ -18,7 +15,7 @@ class Armg::MysqlGeometry < ActiveModel::Type::Value
|
|
18
15
|
if value.nil?
|
19
16
|
nil
|
20
17
|
else
|
21
|
-
Armg.
|
18
|
+
Armg.serializer.serialize(value)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
data/lib/armg/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
class Armg::
|
1
|
+
class Armg::WkbDeserializer
|
2
2
|
DEFAULT_OPTIONS = {
|
3
3
|
support_ewkb: true,
|
4
4
|
}
|
5
5
|
|
6
6
|
def initialize(factory = nil, options = {})
|
7
7
|
options = DEFAULT_OPTIONS.merge(options)
|
8
|
-
@
|
8
|
+
@wkb_parser = RGeo::WKRep::WKBParser.new(factory, options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def deserialize(wkb)
|
12
12
|
wkb = wkb.b
|
13
13
|
srid = wkb.slice!(0..3)
|
14
14
|
wkb[4] = "\x20"
|
15
15
|
wkb.insert(5, srid)
|
16
|
-
@
|
16
|
+
@wkb_parser.parse(wkb)
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Armg::WkbSerializer
|
2
|
+
DEFAULT_OPTIONS = {
|
3
|
+
type_format: :ewkb,
|
4
|
+
little_endian: true,
|
5
|
+
}
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
options = DEFAULT_OPTIONS.merge(options)
|
9
|
+
@wkb_generator = RGeo::WKRep::WKBGenerator.new(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize(obj)
|
13
|
+
srid = [obj.srid].pack('L<')
|
14
|
+
srid + @wkb_generator.generate(obj)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Armg::WktDeserializer < Armg::WkbDeserializer
|
2
|
+
DEFAULT_OPTIONS = {
|
3
|
+
tag_format: :ewkt,
|
4
|
+
#emit_ewkt_srid: true,
|
5
|
+
}
|
6
|
+
|
7
|
+
def initialize(factory = nil, options = {})
|
8
|
+
super(factory, options)
|
9
|
+
options = DEFAULT_OPTIONS.merge(options)
|
10
|
+
@generator = RGeo::WKRep::WKTGenerator.new(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def deserialize(wkb)
|
14
|
+
obj = super(wkb)
|
15
|
+
@generator.generate(obj)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Armg::WktSerializer < Armg::WkbSerializer
|
2
|
+
DEFAULT_OPTIONS = {
|
3
|
+
support_ewkt: true
|
4
|
+
}
|
5
|
+
|
6
|
+
def initialize(factory = nil, options = {})
|
7
|
+
super(options)
|
8
|
+
options = DEFAULT_OPTIONS.merge(options)
|
9
|
+
@wkt_parser = RGeo::WKRep::WKTParser.new(factory, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize(wkt)
|
13
|
+
obj = @wkt_parser.parse(wkt)
|
14
|
+
super(obj)
|
15
|
+
end
|
16
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rgeo'
|
3
|
+
a = "0101000000000000000000F03F000000000000F03F"
|
4
|
+
|
5
|
+
factory = RGeo::Geographic.spherical_factory(:default_srid => 4326)
|
6
|
+
parser = RGeo::WKRep::WKBParser.new(nil, support_ewkb: true, default_srid: 4326)
|
7
|
+
point = parser.parse(a)
|
8
|
+
p point.srid
|
9
|
+
|
10
|
+
generator = RGeo::WKRep::WKTGenerator.new(tag_format: :ewkt) #, emit_ewkt_srid: true)
|
11
|
+
p generator.generate(point)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: armg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: appraisal
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.2.0
|
111
125
|
description: Add MySQL geometry type to Active Record.
|
112
126
|
email:
|
113
127
|
- sugawara@cookpad.com
|
@@ -118,6 +132,7 @@ files:
|
|
118
132
|
- ".gitignore"
|
119
133
|
- ".rspec"
|
120
134
|
- ".travis.yml"
|
135
|
+
- Appraisals
|
121
136
|
- Gemfile
|
122
137
|
- LICENSE.txt
|
123
138
|
- README.md
|
@@ -126,14 +141,19 @@ files:
|
|
126
141
|
- bin/console
|
127
142
|
- bin/setup
|
128
143
|
- docker-compose.yml
|
144
|
+
- gemfiles/ar50.gemfile
|
145
|
+
- gemfiles/ar51.gemfile
|
129
146
|
- lib/armg.rb
|
130
147
|
- lib/armg/abstract_mysql_adapter_ext.rb
|
131
148
|
- lib/armg/armg.rb
|
132
149
|
- lib/armg/mysql_geometry.rb
|
133
150
|
- lib/armg/table_definition_ext.rb
|
134
151
|
- lib/armg/version.rb
|
135
|
-
- lib/armg/
|
136
|
-
- lib/armg/
|
152
|
+
- lib/armg/wkb_deserializer.rb
|
153
|
+
- lib/armg/wkb_serializer.rb
|
154
|
+
- lib/armg/wkt_deserializer.rb
|
155
|
+
- lib/armg/wkt_serializer.rb
|
156
|
+
- test.rb
|
137
157
|
homepage: https://github.com/winebarrel/armg
|
138
158
|
licenses:
|
139
159
|
- MIT
|
data/lib/armg/wkb_generator.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Armg::WkbGenerator
|
2
|
-
DEFAULT_OPTIONS = {
|
3
|
-
type_format: :ewkb,
|
4
|
-
little_endian: true,
|
5
|
-
}
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
options = DEFAULT_OPTIONS.merge(options)
|
9
|
-
@generator = RGeo::WKRep::WKBGenerator.new(options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def generate(deserialized_value)
|
13
|
-
srid = [deserialized_value.srid].pack('L<')
|
14
|
-
srid + @generator.generate(deserialized_value)
|
15
|
-
end
|
16
|
-
end
|