activerecord-mysql2rgeo-adapter 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9db157d9de22cd8f9f841f41e80d91c3721cf656
|
4
|
+
data.tar.gz: 28e27dff6926e8ee812dccbc0446ae704b289abb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -59,50 +59,46 @@ module ActiveRecord
|
|
59
59
|
|
60
60
|
def spatial_factory
|
61
61
|
@spatial_factory ||=
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
74
|
-
# TODO
|
73
|
+
|
74
|
+
# TODO - only valid types should be allowed
|
75
75
|
# e.g. linestring is not valid for point column
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|