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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09e0e685a3ded9712b09523f1ab17e6b0b2cb0a7'
4
- data.tar.gz: ef5f593a129fa7a6d50183fafd750bbe3ae8c838
3
+ metadata.gz: cd750e12ff779d85ab6c3e37f061e65fbee07e2f
4
+ data.tar.gz: b17f2516d892fb0029552f2577379ff2b8709772
5
5
  SHA512:
6
- metadata.gz: 7d2cfa2b8b982726afa09b410f4f027d30c3bff84809c357e900f8f834802827e63285330821862c53787bd7ac9781aec2b87bee08a99bbdc7dd235f19c48e78
7
- data.tar.gz: 918c8676a146dcfcd8d16446ff4d31850ecc971ab909efb5fac133eeff63f7c842a2ec635d7fab29bf2a0ebea9d87b01cdf627f9c4fca30ec1c7bbfdac9605ed
6
+ metadata.gz: 6a6072cb270a02f58750bd7a884a73f82eba207ca57a174e7a12a7c5555f2487fc0a12245268a19ee0031616d220fa0d467ca315ba597f3eb5976fe39cbf97ba
7
+ data.tar.gz: bba7d5b0166f2f6310045b87dca715386d200bab7365ecec5f75284b62b56cab39d706ca5c03af1fa457cd8bcbe84904e3fa3c4f3d32a7683f58f2321198cf26
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ /gemfiles/*.lock
@@ -1,16 +1,30 @@
1
- sudo: false
2
- dist: precise
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
- before_install: gem install bundler
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
- global:
14
- - ARMG_TEST_MYSQL_PORT=3306
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
@@ -0,0 +1,7 @@
1
+ appraise 'ar50' do
2
+ gem 'activerecord', '~> 5.0'
3
+ end
4
+
5
+ appraise 'ar51' do
6
+ gem 'activerecord', '~> 5.1'
7
+ end
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 custom WKB parser
47
+ ## Using WKT
48
48
 
49
49
  ```ruby
50
- class CustomParser
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
- @parser = RGeo::WKRep::WKBParser.new(factory, support_ewkb: true)
65
+ @wkb_parser = RGeo::WKRep::WKBParser.new(factory, support_ewkb: true)
54
66
  end
55
67
 
56
- def parse(wkb)
68
+ def deserialize(wkb)
57
69
  wkb_without_srid = wkb.b.slice(4..-1)
58
- @parser.parse(wkb_without_srid)
70
+ @wkb_parser.parse(wkb_without_srid)
59
71
  end
60
72
  end
61
73
 
62
- Armg.wkb_parser = CustomParser.new
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 generator
80
+ ## Using custom WKB serializer
69
81
 
70
82
  ```ruby
71
- class CustomGenerator
83
+ class CustomSerializer
72
84
  def initialize
73
85
  @wkt_parser = RGeo::WKRep::WKTParser.new(nil, support_ewkt: true)
74
- @generator = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)
86
+ @wkb_generator = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)
75
87
  end
76
88
 
77
- def generate(value)
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 + @generator.generate(value)
95
+ srid + @wkb_generator.generate(value)
84
96
  end
85
97
  end
86
98
 
87
- Armg.wkb_generator = CustomGenerator.new
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
+ ```
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
29
  spec.add_development_dependency 'mysql2'
30
30
  spec.add_development_dependency 'rspec-match_fuzzy'
31
+ spec.add_development_dependency 'appraisal', '>= 2.2.0'
31
32
  end
@@ -1,8 +1,14 @@
1
1
  version: '2'
2
2
  services:
3
- mysql:
3
+ mysql56:
4
4
  ports:
5
- - "6033:3306"
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
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1"
6
+
7
+ gemspec path: "../"
@@ -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/wkb_generator'
8
- require 'armg/wkb_parser'
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'
@@ -1,22 +1,22 @@
1
1
  module Armg
2
- @wkb_parser = Armg::MysqlGeometry::DEFAULT_WKB_PARSER
3
- @wkb_generator = Armg::MysqlGeometry::DEFAULT_WKB_GENERATOR
2
+ @deserializer = Armg::WkbDeserializer.new
3
+ @serializer = Armg::WkbSerializer.new
4
4
 
5
5
  class << self
6
- def wkb_parser
7
- @wkb_parser
6
+ def deserializer
7
+ @deserializer
8
8
  end
9
9
 
10
- def wkb_parser=(parser)
11
- @wkb_parser = parser
10
+ def deserializer=(v)
11
+ @deserializer = v
12
12
  end
13
13
 
14
- def wkb_generator
15
- @wkb_generator
14
+ def serializer
15
+ @serializer
16
16
  end
17
17
 
18
- def wkb_generator=(generator)
19
- @wkb_generator = generator
18
+ def serializer=(v)
19
+ @serializer = v
20
20
  end
21
21
  end
22
22
  end
@@ -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.wkb_parser.parse(value)
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.wkb_generator.generate(value)
18
+ Armg.serializer.serialize(value)
22
19
  end
23
20
  end
24
21
  end
@@ -1,3 +1,3 @@
1
1
  module Armg
2
- VERSION = '0.4.4'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,18 +1,18 @@
1
- class Armg::WkbParser
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
- @parser = RGeo::WKRep::WKBParser.new(factory, options)
8
+ @wkb_parser = RGeo::WKRep::WKBParser.new(factory, options)
9
9
  end
10
10
 
11
- def parse(wkb)
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
- @parser.parse(wkb)
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.4
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-12 00:00:00.000000000 Z
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/wkb_generator.rb
136
- - lib/armg/wkb_parser.rb
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
@@ -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