activerecord-mysql2rgeo-adapter 1.0.2 → 1.0.3

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: ebf8862e5aa9cc0a6ad9358eb11ef336c6d6121d
4
- data.tar.gz: b0d45b2ce970040c8f7a4c86bf62a74f9e7867b8
3
+ metadata.gz: 9db157d9de22cd8f9f841f41e80d91c3721cf656
4
+ data.tar.gz: 28e27dff6926e8ee812dccbc0446ae704b289abb
5
5
  SHA512:
6
- metadata.gz: f2008b6ddec86dd4bdf2677d692a34fed1c34036892cdb049692b394cced198abbf053e51d9e5a9befa2a73580e8f926e61d96192508c9e925e75a44ef57f5b5
7
- data.tar.gz: 7f9479cded7e02999a7d52a3719e8b0280f674b7da7dd6b561d507fddf0841f2bfa612d9af2830e6e9c521b64c2064aadeff023f00424f2d334170440a3aeafd
6
+ metadata.gz: fd946b2d8f998030b2e0478b6df556509e7a727f93fd3086d3151d3eb2ddfdd64ba558fe6852e210029aa8ed0a409821280b86d602383e549951a5e5f5e16522
7
+ data.tar.gz: '09a2ad7169d0051e7a749781a2c1f43846396f5dfcd66cc46b86b4cffcbeea8fb1687db71d34b818748d79b53145a79b1a1fe334253303685244e518a8ee6368'
@@ -24,30 +24,6 @@ module Arel # :nodoc:
24
24
  FUNC_MAP[standard_name.downcase] || standard_name
25
25
  end
26
26
 
27
- def visit_Arel_Nodes_SelectCore(o, collector)
28
- len = o.projections.length - 1
29
- if len == 0
30
- if !o.projections.first.nil? && o.projections.first.respond_to?(:relation)
31
- projections = []
32
- @connection.columns(o.projections.first.relation.name).each do |x|
33
- projections << o.projections.first.relation[x.name.to_sym]
34
- end
35
- o.projections = projections
36
- end
37
- end
38
- super
39
- end
40
-
41
- def visit_Arel_Attributes_Attribute(o, collector)
42
- join_name = o.relation.table_alias || o.relation.name
43
-
44
- collector << if (!column_for(o).nil? && column_for(o).type == :geometry) && !collector.value.include?(" WHERE ")
45
- "ST_AsText(#{quote_table_name join_name}.#{quote_column_name o.name}) as #{quote_column_name o.name}"
46
- else
47
- "#{quote_table_name join_name}.#{quote_column_name o.name}"
48
- end
49
- end
50
-
51
27
  def visit_String(node, collector)
52
28
  collector << "#{st_func('ST_WKTToSQL')}(#{quote(node)})"
53
29
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module Mysql2Rgeo
4
- VERSION = "1.0.2".freeze
4
+ VERSION = "1.0.3".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -59,50 +59,46 @@ module ActiveRecord
59
59
 
60
60
  def spatial_factory
61
61
  @spatial_factory ||=
62
- RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
63
- geo_type: @geo_type,
64
- sql_type: @sql_type,
65
- srid: @srid
66
- )
62
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
63
+ geo_type: @geo_type,
64
+ sql_type: @sql_type,
65
+ srid: @srid
66
+ )
67
67
  end
68
68
 
69
69
  # support setting an RGeo object or a WKT string
70
70
  def serialize(value)
71
71
  return if value.nil?
72
72
  geo_value = cast_value(value)
73
- geo_value
74
- # TODO: - only valid types should be allowed
73
+
74
+ # TODO - only valid types should be allowed
75
75
  # e.g. linestring is not valid for point column
76
- # raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
77
- # RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(geo_value)
76
+ raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
77
+ geo_value
78
78
  end
79
79
 
80
80
  private
81
81
 
82
- # Convenience method for types which do not need separate type casting
83
- # behavior for user and database inputs. Called by Value#cast for
84
- # values except +nil+.
85
- def cast_value(value) # :doc:
82
+ def cast_value(value)
86
83
  return if value.nil?
87
- value.class === "String" ? parse_wkt(value) : parse_wkt(value.to_s)
88
- end
89
-
90
- # convert WKT string into RGeo object
91
- def parse_wkt(string)
92
- wkt_parser(string).parse(string)
93
- rescue RGeo::Error::ParseError
94
- nil
95
- end
96
-
97
- def binary_string?(string)
98
- string[0] == "\x00" || string[0] == "\x01" || string[0, 4] =~ /[0-9a-fA-F]{4}/
99
- end
100
-
101
- def wkt_parser(string)
102
- if binary_string?(string)
103
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid)
104
- else
105
- RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
84
+ case value
85
+ when ::RGeo::Feature::Geometry
86
+ value
87
+ # RGeo::Feature.cast(value, spatial_factory) rescue nil
88
+ when ::String
89
+ marker = value[4, 1]
90
+ if marker == "\x00" || marker == "\x01"
91
+ srid = value[0, 4].unpack(marker == "\x01" ? 'V' : 'N').first
92
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[4..-1]) rescue nil
93
+ elsif value[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
94
+ srid = value[0, 8].to_i(16)
95
+ srid = [srid].pack('V').unpack('N').first if value[9, 1] == '1'
96
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[8..-1]) rescue nil
97
+ else
98
+ RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(value) rescue nil
99
+ end
100
+ else
101
+ nil
106
102
  end
107
103
  end
108
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-mysql2rgeo-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yongdae Hwang