armg 0.1.0 → 0.2.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: 64bfa6ec3175a3630c3c0cfb70778be10301c253
4
- data.tar.gz: c75657dceb039cabf0561a8d52eed721060554a5
3
+ metadata.gz: 1a7b4fe373024d59b31f19785f7da0a032b80a36
4
+ data.tar.gz: a38c06cd0ea07f5c495522eb4b491140eb1658c3
5
5
  SHA512:
6
- metadata.gz: 952ba9df602ca83e6407120f07cade09b606ed609b7007f0953ae5598b0b0b2df62f34a0b97c573c357cf64290769965ceef785270144274585fe3b935f33744
7
- data.tar.gz: e44a5c5eb8d005f8eae767da1ad149ab99dac4197154de6cd09439af253d3b5b5b83bb6921c1b9e0d501cfd068a66c1d365e5e8819267be08545e9f989e16e82
6
+ metadata.gz: 55ed05dc88ffadd02115f21e5ab3214fd9c0edb81cabf2fcdf9a3e4da7b9ca9bc25ea3669d97d24b5b97029888e8221bf96634ce8ab9fb1e5988b6e7831d209a
7
+ data.tar.gz: 950052ac3c4af3ef611643a0114223cc8cfd1f4dbb6994d0794b0f1d933c32d86d23c086859fa967251edae3e2058a2b7392b5d7ea9303a4c8b272896414b5d7
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
2
1
  --color
2
+ --require spec_helper
@@ -1,5 +1,16 @@
1
1
  sudo: false
2
+ dist: precise
2
3
  language: ruby
3
4
  rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.14.3
5
+ - 2.3.4
6
+ before_install: gem install bundler
7
+ cache:
8
+ - bundler
9
+ - apt
10
+ services:
11
+ - mysql
12
+ env:
13
+ global:
14
+ - ARMG_TEST_MYSQL_PORT=3306
15
+ script:
16
+ - bundle exec rake
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Add MySQL geometry type to Active Record.
4
4
 
5
+ [![Build Status](https://travis-ci.org/winebarrel/armg.svg?branch=master)](https://travis-ci.org/winebarrel/armg)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -24,26 +26,19 @@ Or install it yourself as:
24
26
  require 'active_record'
25
27
  require 'armg'
26
28
 
27
- ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'my_app');
29
+ ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'my_db');
28
30
 
29
- ActiveRecord::Migration.create_table :geoms do |t|
30
- t.geometry 'location'
31
+ ActiveRecord::Migration.create_table :geoms, options: 'ENGINE=MyISAM' do |t|
32
+ t.geometry 'location', null: false
33
+ t.index ['location'], name: 'idx_location', type: :spatial
31
34
  end
32
35
 
33
36
  class Geom < ActiveRecord::Base; end
34
37
 
35
- Geom.create!(geometry: [1, 1.0, 1.0])
36
- #=> #<Geom id: 15 geometry: [1, 1.0, 1.0]>
37
-
38
- # 1: Point
39
- # 2: LineString
40
- # 3: Polygon
41
- # 4: MultiPoint
42
- # 5: MultiLineString
43
- # 6: MultiPolygon
44
- # 7:GeometryCollection.
45
- # see https://dev.mysql.com/doc/refman/5.6/en/gis-data-formats.html
38
+ wkt_parser = RGeo::WKRep::WKTParser.new(nil, support_ewkt: true)
39
+ point = wkt_parser.parse('SRID=4326;Point(-122.1 47.3)')
40
+ Geom.create!(location: point)
46
41
 
47
42
  Geom.first
48
- #=> #<Geom id: 1, geometry: [1, 1.0, 1.0]>
43
+ #=> #<Geom id: 1, location: #<RGeo::Cartesian::PointImpl:0x... "POINT (-122.1 47.3)">>
49
44
  ```
@@ -22,7 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_dependency 'activerecord', '~> 5'
25
+ spec.add_dependency 'rgeo'
25
26
  spec.add_development_dependency 'bundler'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'mysql2'
30
+ spec.add_development_dependency 'rspec-match_fuzzy'
28
31
  end
@@ -0,0 +1,8 @@
1
+ version: '2'
2
+ services:
3
+ mysql:
4
+ ports:
5
+ - "6033:3306"
6
+ image: "mysql:5.6"
7
+ environment:
8
+ - MYSQL_ALLOW_EMPTY_PASSWORD=1
@@ -1,4 +1,5 @@
1
1
  require 'active_support/lazy_load_hooks'
2
+ require 'rgeo'
2
3
  require 'armg/version'
3
4
 
4
5
  ActiveSupport.on_load(:active_record) do
@@ -11,5 +12,6 @@ ActiveSupport.on_load(:active_record) do
11
12
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(Armg::AbstractMysqlAdapterExt)
12
13
  ActiveRecord::Type.register(:geometry, Armg::MysqlGeometry, adapter: :mysql2)
13
14
  ActiveRecord::ConnectionAdapters::MySQL::TableDefinition.prepend(Armg::TableDefinitionExt)
15
+ ActiveRecord::ConnectionAdapters::MySQL::Table.prepend(Armg::TableDefinitionExt)
14
16
  end
15
17
 
@@ -3,4 +3,12 @@ module Armg::AbstractMysqlAdapterExt
3
3
  super
4
4
  m.register_type %r(^geometry)i, Armg::MysqlGeometry.new
5
5
  end
6
+
7
+ def indexes(*args, &block)
8
+ super.tap do |is|
9
+ is.each do |i|
10
+ i.lengths = nil if i.type = :spatial
11
+ end
12
+ end
13
+ end
6
14
  end
@@ -7,9 +7,9 @@ class Armg::MysqlGeometry < ActiveModel::Type::Value
7
7
 
8
8
  def deserialize(value)
9
9
  if value.is_a?(::String)
10
- # https://dev.mysql.com/doc/refman/5.6/en/gis-data-formats.html
11
- value.slice!(0, 5)
12
- value.unpack("L<E2")
10
+ srid = value[0..3].unpack('L<').first
11
+ wkb_parser = RGeo::WKRep::WKBParser.new(nil, support_ewkb: true, default_srid: srid)
12
+ wkb_parser.parse(value[4..-1])
13
13
  else
14
14
  value
15
15
  end
@@ -19,7 +19,9 @@ class Armg::MysqlGeometry < ActiveModel::Type::Value
19
19
  if value.nil?
20
20
  nil
21
21
  else
22
- "\x00\x00\x00\x00\x01" + value.pack("L<E2")
22
+ wkb_generator = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)
23
+ wkb = wkb_generator.generate(value)
24
+ [value.srid].pack('L<') + wkb
23
25
  end
24
26
  end
25
27
  end
@@ -1,3 +1,3 @@
1
1
  module Armg
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
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.1.0
4
+ version: 0.2.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-10 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rgeo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,34 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-match_fuzzy
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  description: Add MySQL geometry type to Active Record.
70
112
  email:
71
113
  - sugawara@cookpad.com
@@ -83,6 +125,7 @@ files:
83
125
  - armg.gemspec
84
126
  - bin/console
85
127
  - bin/setup
128
+ - docker-compose.yml
86
129
  - lib/armg.rb
87
130
  - lib/armg/abstract_mysql_adapter_ext.rb
88
131
  - lib/armg/mysql_geometry.rb
@@ -108,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
151
  version: '0'
109
152
  requirements: []
110
153
  rubyforge_project:
111
- rubygems_version: 2.6.12
154
+ rubygems_version: 2.5.2
112
155
  signing_key:
113
156
  specification_version: 4
114
157
  summary: Add MySQL geometry type to Active Record.