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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a7b4fe373024d59b31f19785f7da0a032b80a36
4
- data.tar.gz: a38c06cd0ea07f5c495522eb4b491140eb1658c3
3
+ metadata.gz: 84e6b3ee252fb5c11271a5ef0ae7ab318d4a509d
4
+ data.tar.gz: 2c2be3dad6a3db05718938e80b238debc0c13168
5
5
  SHA512:
6
- metadata.gz: 55ed05dc88ffadd02115f21e5ab3214fd9c0edb81cabf2fcdf9a3e4da7b9ca9bc25ea3669d97d24b5b97029888e8221bf96634ce8ab9fb1e5988b6e7831d209a
7
- data.tar.gz: 950052ac3c4af3ef611643a0114223cc8cfd1f4dbb6994d0794b0f1d933c32d86d23c086859fa967251edae3e2058a2b7392b5d7ea9303a4c8b272896414b5d7
6
+ metadata.gz: 4d9aa995ba5b6b5a228ab6f6eac7c2640a2e9db5a37de2e71e759c3b6104026277d18e688fbf451853a9258257be461470719e4be8049b5fcda7e3ee978d2b6c
7
+ data.tar.gz: 1f609a7196e10b8c29e71399988f45389443df8960084347cce53e3992b2920ced2b8051b034776c5391907091006272aade83b9f88efb5f966ed393172c66e2
@@ -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
-
@@ -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
@@ -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
- 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])
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 = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)
34
+ wkb_generator, srid = Armg.wkb_generator_factory.call(value)
23
35
  wkb = wkb_generator.generate(value)
24
- [value.srid].pack('L<') + wkb
36
+ srid + wkb
25
37
  end
26
38
  end
27
39
  end
@@ -1,3 +1,3 @@
1
1
  module Armg
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.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.5.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.