rgeo-activerecord 4.0.0 → 4.0.1
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 +4 -4
- data/History.md +31 -0
- data/README.md +46 -3
- data/lib/rgeo/active_record/arel_spatial_queries.rb +2 -4
- data/lib/rgeo/active_record/common_adapter_elements.rb +2 -4
- data/lib/rgeo/active_record/geometry_mixin.rb +5 -5
- data/lib/rgeo/active_record/spatial_expressions.rb +44 -53
- data/lib/rgeo/active_record/version.rb +1 -1
- data/lib/rgeo/active_record.rb +8 -8
- data/lib/rgeo-activerecord.rb +1 -1
- metadata +6 -13
- data/test/basic_test.rb +0 -36
- data/test/spatial_factory_store_test.rb +0 -45
- data/test/support/fake_record.rb +0 -136
- data/test/test_helper.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8241a074715943e7dcb035f37f99151a5cf9ec2f
|
4
|
+
data.tar.gz: cb3e2543f6514a61440adab0e992e2d0a7bb26db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 518773c88ab208d156736c320460ab637af0281e46a3c40cc62ec41b28c3ffcdec82d171b8137af2f4c84b3f4eb86e6075fe8d5563b233e1c6fa7f47abf03abb
|
7
|
+
data.tar.gz: d19b96993b420ba1d3798bf77e7adcbcb7c0093da81c8c01aa5335ab91ebb57a76df5e3fe0f3f169173dbd005606b5ced4483e09c3655dc376fa8118016d633e
|
data/History.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
### 4.0.1 / 2015-12-25
|
2
|
+
|
3
|
+
* Rubocop style cleanup #31
|
4
|
+
* Do not distribute test files with gem
|
5
|
+
|
6
|
+
### 4.0.0 / 2015-05-24
|
7
|
+
|
8
|
+
* Remove GeoTableDefinitions, GeoConnectionAdapter
|
9
|
+
|
10
|
+
### 3.0.0 / 2015-05-09
|
11
|
+
|
12
|
+
* Remove AdapterTestHelper module
|
13
|
+
* Remove RGeoFactorySettings
|
14
|
+
* Remove #set_rgeo_factory_for_column, #rgeo_factory_for_column, etc
|
15
|
+
* Add SpatialFactoryStore (see https://github.com/rgeo/rgeo-activerecord/commit/b1da5cb222)
|
16
|
+
|
17
|
+
### 2.1.1 / 2015-03-18
|
18
|
+
|
19
|
+
* Fix collector calls for arel 6.0 API
|
20
|
+
|
21
|
+
### 2.1.0 / 2015-02-07
|
22
|
+
|
23
|
+
* Update visit API for arel 6.0
|
24
|
+
* Remove attribute caching (removed in AR 4.2)
|
25
|
+
* Remove support for `spatial: true` index option (use standard `using: :gist`)
|
26
|
+
|
27
|
+
### 2.0.0 / 2014-12-02
|
28
|
+
|
29
|
+
* Dump schema using new style hash - https://github.com/rgeo/rgeo-activerecord/pull/18
|
30
|
+
* Require ActiveRecord 4.2
|
31
|
+
|
1
32
|
### 1.2.0 / 2014-08-21
|
2
33
|
|
3
34
|
* Support ActiveRecord 4.2
|
data/README.md
CHANGED
@@ -32,17 +32,60 @@ gem 'rgeo-activerecord'
|
|
32
32
|
`rgeo-activerecord` has the following requirements:
|
33
33
|
|
34
34
|
* Ruby 1.9.3 or later
|
35
|
-
* ActiveRecord 4.0.0 or later
|
36
35
|
* rgeo 0.3.20 or later.
|
37
36
|
|
38
|
-
|
37
|
+
The latest version supports ActiveRecord 4.2 and later.
|
38
|
+
|
39
|
+
Version `1.1.0` supports ActiveRecord 4.0 and 4.1
|
40
|
+
|
41
|
+
Version `0.6.0` supports earlier versions of ruby and ActiveRecord:
|
39
42
|
|
40
43
|
* Ruby 1.8.7 or later
|
41
44
|
* ActiveRecord 3.0.3 - 3.2.x
|
42
45
|
* rgeo 0.3.20 or later
|
43
46
|
* arel 2.0.6 or later
|
44
47
|
|
45
|
-
|
48
|
+
### Spatial Factories for Columns
|
49
|
+
|
50
|
+
`rgeo_factory_generator` and related methods were removed in version 4.0, since column types
|
51
|
+
are no longer tied to their database column in ActiveRecord 4.2.
|
52
|
+
|
53
|
+
Register spatial factories in the `SpatialFactoryStore` singleton class. Each spatial type
|
54
|
+
in your ActiveRecord models will use the `SpatialFactoryStore` to retrieve
|
55
|
+
a factory matching the properties of its type. For example, you can set a different
|
56
|
+
spatial factory for point types, or for types matching a specific SRID, or having
|
57
|
+
a Z coordinate, or any combination of attributes.
|
58
|
+
|
59
|
+
The supported keys when registering a spatial type are listed here with their default values
|
60
|
+
and other allowed values:
|
61
|
+
|
62
|
+
```
|
63
|
+
geo_type: "geometry", # point, polygon, line_string, geometry_collection,
|
64
|
+
# multi_line_string, multi_point, multi_polygon
|
65
|
+
has_m: false, # true
|
66
|
+
has_z: false, # true
|
67
|
+
sql_type: "geometry", # geography
|
68
|
+
srid: 0, # (any valid SRID)
|
69
|
+
```
|
70
|
+
|
71
|
+
The default factories are `RGeo::Geographic.spherical_factory` for
|
72
|
+
geographic types, and `RGeo::Cartesian.preferred_factory` for geometric types.
|
73
|
+
|
74
|
+
Here is an example setup:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
|
78
|
+
# By default, use the GEOS implementation for spatial columns.
|
79
|
+
config.default = RGeo::Geos.factory_generator
|
80
|
+
|
81
|
+
# But use a geographic implementation for point columns.
|
82
|
+
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### RGeo Dependency
|
87
|
+
|
88
|
+
See the README for the [rgeo](https://github.com/rgeo/rgeo) gem, a dependency, for further
|
46
89
|
installation information.
|
47
90
|
|
48
91
|
### Development and support
|
@@ -7,7 +7,6 @@ module RGeo
|
|
7
7
|
# mysqlspatial, and mysql2spatial) for usage examples.
|
8
8
|
|
9
9
|
module SpatialToSql
|
10
|
-
|
11
10
|
# Map a standard OGC SQL function name to the actual name used by
|
12
11
|
# a particular database. This method should take a name and
|
13
12
|
# return either the changed name or the original name.
|
@@ -30,9 +29,9 @@ module RGeo
|
|
30
29
|
collector << name
|
31
30
|
collector << "("
|
32
31
|
collector << "DISTINCT " if node.distinct
|
33
|
-
collector << exprs.join(
|
32
|
+
collector << exprs.join(", ")
|
34
33
|
collector << ")"
|
35
|
-
collector << " AS #{
|
34
|
+
collector << " AS #{visit(node.alias, collector)}" if node.alias
|
36
35
|
collector
|
37
36
|
end
|
38
37
|
|
@@ -117,6 +116,5 @@ module RGeo
|
|
117
116
|
end
|
118
117
|
|
119
118
|
# :startdoc:
|
120
|
-
|
121
119
|
end
|
122
120
|
end
|
@@ -6,7 +6,7 @@ module RGeo
|
|
6
6
|
# Some default column constructors specifications for most spatial
|
7
7
|
# databases. Individual adapters may add to or override this list.
|
8
8
|
DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS = {
|
9
|
-
spatial: { :
|
9
|
+
spatial: { type: "geometry" }.freeze,
|
10
10
|
geometry: {}.freeze,
|
11
11
|
point: {}.freeze,
|
12
12
|
line_string: {}.freeze,
|
@@ -19,8 +19,7 @@ module RGeo
|
|
19
19
|
|
20
20
|
# Index definition struct with a spatial flag field.
|
21
21
|
|
22
|
-
|
23
|
-
end
|
22
|
+
SpatialIndexDefinition = Struct.new(:table, :name, :unique, :columns, :lengths, :orders, :where, :spatial)
|
24
23
|
|
25
24
|
# Returns a feature type module given a string type.
|
26
25
|
|
@@ -34,7 +33,6 @@ module RGeo
|
|
34
33
|
when /^multipoint/i then ::RGeo::Feature::MultiPoint
|
35
34
|
when /^multilinestring/i then ::RGeo::Feature::MultiLineString
|
36
35
|
when /^multipolygon/i then ::RGeo::Feature::MultiPolygon
|
37
|
-
else nil
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -6,7 +6,7 @@ module RGeo
|
|
6
6
|
|
7
7
|
module GeometryMixin
|
8
8
|
# The default JSON generator Proc. Renders geometry fields as WKT.
|
9
|
-
DEFAULT_JSON_GENERATOR = ::Proc.new
|
9
|
+
DEFAULT_JSON_GENERATOR = ::Proc.new(&:to_s)
|
10
10
|
|
11
11
|
@json_generator = DEFAULT_JSON_GENERATOR
|
12
12
|
|
@@ -26,8 +26,8 @@ module RGeo
|
|
26
26
|
if block && !value
|
27
27
|
value = block
|
28
28
|
elsif value == :geojson
|
29
|
-
require
|
30
|
-
value = ::Proc.new{ |geom_| ::RGeo::GeoJSON.encode(geom_) }
|
29
|
+
require "rgeo/geo_json"
|
30
|
+
value = ::Proc.new { |geom_| ::RGeo::GeoJSON.encode(geom_) }
|
31
31
|
end
|
32
32
|
if value.is_a?(::Proc)
|
33
33
|
@json_generator = value
|
@@ -54,5 +54,5 @@ module RGeo
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
::RGeo::Feature::MixinCollection::GLOBAL.for_type(::RGeo::Feature::Geometry)
|
58
|
-
add(::RGeo::ActiveRecord::GeometryMixin)
|
57
|
+
::RGeo::Feature::MixinCollection::GLOBAL.for_type(::RGeo::Feature::Geometry)
|
58
|
+
.add(::RGeo::ActiveRecord::GeometryMixin)
|
@@ -24,173 +24,169 @@ module RGeo
|
|
24
24
|
#++
|
25
25
|
|
26
26
|
def st_dimension
|
27
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
27
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Dimension", [self], [false, true])
|
28
28
|
end
|
29
29
|
|
30
30
|
def st_geometrytype
|
31
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
31
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_GeometryType", [self], [false, true])
|
32
32
|
end
|
33
33
|
|
34
34
|
def st_astext
|
35
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
35
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_AsText", [self], [false, true])
|
36
36
|
end
|
37
37
|
|
38
38
|
def st_asbinary
|
39
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
39
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_AsBinary", [self], [false, true])
|
40
40
|
end
|
41
41
|
|
42
42
|
def st_srid
|
43
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
43
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_SRID", [self], [false, true])
|
44
44
|
end
|
45
45
|
|
46
46
|
def st_isempty
|
47
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
47
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_IsEmpty", [self], [false, true])
|
48
48
|
end
|
49
49
|
|
50
50
|
def st_issimple
|
51
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
51
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_IsSimple", [self], [false, true])
|
52
52
|
end
|
53
53
|
|
54
54
|
def st_boundary
|
55
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
55
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Boundary", [self], [true, true])
|
56
56
|
end
|
57
57
|
|
58
58
|
def st_envelope
|
59
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
59
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Envelope", [self], [true, true])
|
60
60
|
end
|
61
61
|
|
62
62
|
def st_equals(rhs)
|
63
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
63
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Equals", [self, rhs], [false, true, true])
|
64
64
|
end
|
65
65
|
|
66
66
|
def st_disjoint(rhs)
|
67
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
67
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Disjoint", [self, rhs], [false, true, true])
|
68
68
|
end
|
69
69
|
|
70
70
|
def st_intersects(rhs)
|
71
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
71
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Intersects", [self, rhs], [false, true, true])
|
72
72
|
end
|
73
73
|
|
74
74
|
def st_touches(rhs)
|
75
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
75
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Touches", [self, rhs], [false, true, true])
|
76
76
|
end
|
77
77
|
|
78
78
|
def st_crosses(rhs)
|
79
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
79
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Crosses", [self, rhs], [false, true, true])
|
80
80
|
end
|
81
81
|
|
82
82
|
def st_within(rhs)
|
83
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
83
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Within", [self, rhs], [false, true, true])
|
84
84
|
end
|
85
85
|
|
86
86
|
def st_contains(rhs)
|
87
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
87
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Contains", [self, rhs], [false, true, true])
|
88
88
|
end
|
89
89
|
|
90
90
|
def st_overlaps(rhs)
|
91
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
91
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Overlaps", [self, rhs], [false, true, true])
|
92
92
|
end
|
93
93
|
|
94
94
|
def st_relate(rhs, matrix = nil)
|
95
95
|
args = [self, rhs]
|
96
96
|
args << matrix.to_s if matrix
|
97
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
97
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Relate", args, [false, true, true, false])
|
98
98
|
end
|
99
99
|
|
100
100
|
def st_distance(rhs, units = nil)
|
101
101
|
args = [self, rhs]
|
102
102
|
args << units.to_s if units
|
103
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
103
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Distance", args, [false, true, true, false])
|
104
104
|
end
|
105
105
|
|
106
106
|
def st_intersection(rhs)
|
107
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
107
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Intersection", [self, rhs], [true, true, true])
|
108
108
|
end
|
109
109
|
|
110
110
|
def st_difference(rhs)
|
111
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
111
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Difference", [self, rhs], [true, true, true])
|
112
112
|
end
|
113
113
|
|
114
114
|
def st_union(rhs)
|
115
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
115
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Union", [self, rhs], [true, true, true])
|
116
116
|
end
|
117
117
|
|
118
118
|
def st_symdifference(rhs)
|
119
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
119
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_SymDifference", [self, rhs], [true, true, true])
|
120
120
|
end
|
121
121
|
|
122
122
|
def st_buffer(distance, units = nil)
|
123
123
|
args = [self, distance.to_f]
|
124
124
|
args << units.to_s if units
|
125
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
125
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Buffer", args, [true, true, false])
|
126
126
|
end
|
127
127
|
|
128
128
|
def st_convexhull
|
129
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
129
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_ConvexHull", [self], [true, true])
|
130
130
|
end
|
131
131
|
|
132
|
-
|
133
132
|
#--
|
134
133
|
# Point functions
|
135
134
|
#++
|
136
135
|
|
137
136
|
def st_x
|
138
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
137
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_X", [self], [false, true])
|
139
138
|
end
|
140
139
|
|
141
140
|
def st_y
|
142
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
141
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Y", [self], [false, true])
|
143
142
|
end
|
144
143
|
|
145
144
|
def st_z
|
146
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
145
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Z", [self], [false, true])
|
147
146
|
end
|
148
147
|
|
149
148
|
def st_m
|
150
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
149
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_M", [self], [false, true])
|
151
150
|
end
|
152
151
|
|
153
|
-
|
154
152
|
#--
|
155
153
|
# Curve functions
|
156
154
|
#++
|
157
155
|
|
158
156
|
def st_startpoint
|
159
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
157
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_StartPoint", [self], [true, true])
|
160
158
|
end
|
161
159
|
|
162
160
|
def st_endpoint
|
163
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
161
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_EndPoint", [self], [true, true])
|
164
162
|
end
|
165
163
|
|
166
164
|
def st_isclosed
|
167
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
165
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_IsClosed", [self], [false, true])
|
168
166
|
end
|
169
167
|
|
170
168
|
def st_isring
|
171
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
169
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_IsRing", [self], [false, true])
|
172
170
|
end
|
173
171
|
|
174
172
|
def st_length(units = nil)
|
175
173
|
args = [self]
|
176
174
|
args << units.to_s if units
|
177
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
175
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Length", args, [false, true, false])
|
178
176
|
end
|
179
177
|
|
180
|
-
|
181
178
|
#--
|
182
179
|
# LineString functions
|
183
180
|
#++
|
184
181
|
|
185
182
|
def st_numpoints
|
186
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
183
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_NumPoints", [self], [false, true])
|
187
184
|
end
|
188
185
|
|
189
186
|
def st_pointn(n)
|
190
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
187
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_PointN", [self, n.to_i], [true, true, false])
|
191
188
|
end
|
192
189
|
|
193
|
-
|
194
190
|
#--
|
195
191
|
# Surface functions
|
196
192
|
#++
|
@@ -198,15 +194,15 @@ module RGeo
|
|
198
194
|
def st_area(units = nil)
|
199
195
|
args = [self]
|
200
196
|
args << units.to_s if units
|
201
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
197
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_StartPoint", args, [false, true, false])
|
202
198
|
end
|
203
199
|
|
204
200
|
def st_centroid
|
205
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
201
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_Centroid", [self], [true, true])
|
206
202
|
end
|
207
203
|
|
208
204
|
def st_pointonsurface
|
209
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
205
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_PointOnSurface", [self], [true, true])
|
210
206
|
end
|
211
207
|
|
212
208
|
#--
|
@@ -214,17 +210,17 @@ module RGeo
|
|
214
210
|
#++
|
215
211
|
|
216
212
|
def st_exteriorring
|
217
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
213
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_ExteriorRing", [self], [true, true])
|
218
214
|
end
|
219
215
|
|
220
216
|
def st_numinteriorrings
|
221
217
|
# Note: the name difference is intentional. The standard
|
222
218
|
# names this function incorrectly.
|
223
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
219
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_NumInteriorRing", [self], [false, true])
|
224
220
|
end
|
225
221
|
|
226
222
|
def st_interiorringn(n)
|
227
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
223
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_InteriorRingN", [self, n.to_i], [true, true, false])
|
228
224
|
end
|
229
225
|
|
230
226
|
#--
|
@@ -232,15 +228,13 @@ module RGeo
|
|
232
228
|
#++
|
233
229
|
|
234
230
|
def st_numgeometries
|
235
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
231
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_NumGeometries", [self], [false, true])
|
236
232
|
end
|
237
233
|
|
238
234
|
def st_geometryn(n)
|
239
|
-
::RGeo::ActiveRecord::SpatialNamedFunction.new(
|
235
|
+
::RGeo::ActiveRecord::SpatialNamedFunction.new("ST_GeometryN", [self, n.to_i], [true, true, false])
|
240
236
|
end
|
241
|
-
|
242
237
|
end
|
243
|
-
|
244
238
|
end
|
245
239
|
end
|
246
240
|
|
@@ -249,9 +243,7 @@ end
|
|
249
243
|
# Allow chaining of spatial expressions from attributes
|
250
244
|
::Arel::Attribute.send :include, ::RGeo::ActiveRecord::SpatialExpressions
|
251
245
|
|
252
|
-
|
253
246
|
module Arel
|
254
|
-
|
255
247
|
# Create a spatial constant node.
|
256
248
|
# This node wraps a spatial value (such as an RGeo feature or a text
|
257
249
|
# string in WKT format). It supports chaining with the functions
|
@@ -259,5 +251,4 @@ module Arel
|
|
259
251
|
def self.spatial(arg)
|
260
252
|
::RGeo::ActiveRecord::SpatialConstantNode.new(arg)
|
261
253
|
end
|
262
|
-
|
263
254
|
end
|
data/lib/rgeo/active_record.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# ActiveRecord, and a set of tools and helpers for writing RGeo-based
|
5
5
|
# spatial connection adapters.
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
7
|
+
require "rgeo"
|
8
|
+
require "active_record"
|
9
|
+
require "rgeo/active_record/version"
|
10
|
+
require "rgeo/active_record/spatial_expressions"
|
11
|
+
require "rgeo/active_record/spatial_factory_store"
|
12
|
+
require "rgeo/active_record/arel_spatial_queries"
|
13
|
+
require "rgeo/active_record/common_adapter_elements"
|
14
|
+
require "rgeo/active_record/geometry_mixin"
|
data/lib/rgeo-activerecord.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "rgeo/active_record"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rgeo
|
@@ -99,11 +99,7 @@ files:
|
|
99
99
|
- lib/rgeo/active_record/spatial_expressions.rb
|
100
100
|
- lib/rgeo/active_record/spatial_factory_store.rb
|
101
101
|
- lib/rgeo/active_record/version.rb
|
102
|
-
|
103
|
-
- test/spatial_factory_store_test.rb
|
104
|
-
- test/support/fake_record.rb
|
105
|
-
- test/test_helper.rb
|
106
|
-
homepage: http://github.com/rgeo/rgeo-activerecord
|
102
|
+
homepage: https://github.com/rgeo/rgeo-activerecord
|
107
103
|
licenses: []
|
108
104
|
metadata: {}
|
109
105
|
post_install_message:
|
@@ -122,12 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
118
|
version: '0'
|
123
119
|
requirements: []
|
124
120
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.1
|
126
122
|
signing_key:
|
127
123
|
specification_version: 4
|
128
124
|
summary: An RGeo module providing spatial extensions to ActiveRecord.
|
129
|
-
test_files:
|
130
|
-
|
131
|
-
- test/spatial_factory_store_test.rb
|
132
|
-
- test/support/fake_record.rb
|
133
|
-
- test/test_helper.rb
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|
data/test/basic_test.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BasicTest < Minitest::Test
|
4
|
-
class MyTable < ActiveRecord::Base
|
5
|
-
end
|
6
|
-
|
7
|
-
def test_version
|
8
|
-
assert RGeo::ActiveRecord::VERSION
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_default_as_json_wkt
|
12
|
-
RGeo::ActiveRecord::GeometryMixin.set_json_generator(nil)
|
13
|
-
factory = RGeo::Cartesian.preferred_factory
|
14
|
-
point = factory.point(1, 2)
|
15
|
-
assert_equal "POINT (1.0 2.0)", point.as_json
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_default_as_json_geojson
|
19
|
-
RGeo::ActiveRecord::GeometryMixin.set_json_generator(:geojson)
|
20
|
-
factory = RGeo::Cartesian.preferred_factory
|
21
|
-
point = factory.point(1, 2)
|
22
|
-
assert_equal({'type' => 'Point', 'coordinates' => [1.0, 2.0]}, point.as_json)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_arel_visit_spatial_constant_node
|
26
|
-
visitor = arel_visitor
|
27
|
-
sql = visitor.accept(Arel.spatial('POINT (1.0 2.0)'), Arel::Collectors::PlainString.new)
|
28
|
-
assert_equal("ST_WKTToSQL('POINT (1.0 2.0)')", sql.value)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def arel_visitor
|
34
|
-
Arel::Visitors::PostgreSQL.new(FakeRecord::Connection.new)
|
35
|
-
end
|
36
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class SpatialFactoryStoreTest < Minitest::Test
|
4
|
-
def test_default
|
5
|
-
store.default = nil
|
6
|
-
assert RGeo::Cartesian.preferred_factory === store.default
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_set_default
|
10
|
-
store.clear
|
11
|
-
default_factory = Object.new
|
12
|
-
store.default = default_factory
|
13
|
-
assert_equal default_factory, store.default
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_register
|
17
|
-
store.clear
|
18
|
-
default_factory = Object.new
|
19
|
-
store.default = default_factory
|
20
|
-
|
21
|
-
point_factory = Object.new
|
22
|
-
store.register point_factory, geo_type: "point", srid: 4326
|
23
|
-
assert_equal point_factory, store.factory(geo_type: "point", srid: 4326)
|
24
|
-
assert_equal 1, store.registry.size
|
25
|
-
assert_equal point_factory, store.factory(geo_type: "point", srid: 4326)
|
26
|
-
assert_equal 1, store.registry.size
|
27
|
-
|
28
|
-
polygon_factory = Object.new
|
29
|
-
store.register polygon_factory, geo_type: "polygon"
|
30
|
-
assert_equal polygon_factory, store.factory(geo_type: "polygon")
|
31
|
-
assert_equal 2, store.registry.size
|
32
|
-
|
33
|
-
z_point_factory = Object.new
|
34
|
-
store.register z_point_factory, geo_type: "point", has_z: true
|
35
|
-
assert_equal z_point_factory, store.factory(geo_type: "point", has_z: true)
|
36
|
-
|
37
|
-
assert_equal default_factory, store.factory(geo_type: "linestring")
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def store
|
43
|
-
RGeo::ActiveRecord::SpatialFactoryStore.instance
|
44
|
-
end
|
45
|
-
end
|
data/test/support/fake_record.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
# From https://github.com/rails/arel/master/test/support/fake_record.rb
|
2
|
-
module FakeRecord
|
3
|
-
class Column < Struct.new(:name, :type)
|
4
|
-
end
|
5
|
-
|
6
|
-
class Connection
|
7
|
-
attr_reader :tables
|
8
|
-
attr_accessor :visitor
|
9
|
-
|
10
|
-
def initialize(visitor = nil)
|
11
|
-
@tables = %w{ users photos developers products}
|
12
|
-
@columns = {
|
13
|
-
'users' => [
|
14
|
-
Column.new('id', :integer),
|
15
|
-
Column.new('name', :string),
|
16
|
-
Column.new('bool', :boolean),
|
17
|
-
Column.new('created_at', :date)
|
18
|
-
],
|
19
|
-
'products' => [
|
20
|
-
Column.new('id', :integer),
|
21
|
-
Column.new('price', :decimal)
|
22
|
-
]
|
23
|
-
}
|
24
|
-
@columns_hash = {
|
25
|
-
'users' => Hash[@columns['users'].map { |x| [x.name, x] }],
|
26
|
-
'products' => Hash[@columns['products'].map { |x| [x.name, x] }]
|
27
|
-
}
|
28
|
-
@primary_keys = {
|
29
|
-
'users' => 'id',
|
30
|
-
'products' => 'id'
|
31
|
-
}
|
32
|
-
@visitor = visitor
|
33
|
-
end
|
34
|
-
|
35
|
-
def columns_hash table_name
|
36
|
-
@columns_hash[table_name]
|
37
|
-
end
|
38
|
-
|
39
|
-
def primary_key name
|
40
|
-
@primary_keys[name.to_s]
|
41
|
-
end
|
42
|
-
|
43
|
-
def table_exists? name
|
44
|
-
@tables.include? name.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
def columns name, message = nil
|
48
|
-
@columns[name.to_s]
|
49
|
-
end
|
50
|
-
|
51
|
-
def quote_table_name name
|
52
|
-
"\"#{name.to_s}\""
|
53
|
-
end
|
54
|
-
|
55
|
-
def quote_column_name name
|
56
|
-
"\"#{name.to_s}\""
|
57
|
-
end
|
58
|
-
|
59
|
-
def schema_cache
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def quote thing, column = nil
|
64
|
-
if column && !thing.nil?
|
65
|
-
case column.type
|
66
|
-
when :integer
|
67
|
-
thing = thing.to_i
|
68
|
-
when :string
|
69
|
-
thing = thing.to_s
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
case thing
|
74
|
-
when DateTime
|
75
|
-
"'#{thing.strftime("%Y-%m-%d %H:%M:%S")}'"
|
76
|
-
when Date
|
77
|
-
"'#{thing.strftime("%Y-%m-%d")}'"
|
78
|
-
when true
|
79
|
-
"'t'"
|
80
|
-
when false
|
81
|
-
"'f'"
|
82
|
-
when nil
|
83
|
-
'NULL'
|
84
|
-
when Numeric
|
85
|
-
thing
|
86
|
-
else
|
87
|
-
"'#{thing.to_s.gsub("'", "\\\\'")}'"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class ConnectionPool
|
93
|
-
class Spec < Struct.new(:config)
|
94
|
-
end
|
95
|
-
|
96
|
-
attr_reader :spec, :connection
|
97
|
-
|
98
|
-
def initialize
|
99
|
-
@spec = Spec.new(:adapter => 'america')
|
100
|
-
@connection = Connection.new
|
101
|
-
@connection.visitor = Arel::Visitors::ToSql.new(connection)
|
102
|
-
end
|
103
|
-
|
104
|
-
def with_connection
|
105
|
-
yield connection
|
106
|
-
end
|
107
|
-
|
108
|
-
def table_exists? name
|
109
|
-
connection.tables.include? name.to_s
|
110
|
-
end
|
111
|
-
|
112
|
-
def columns_hash
|
113
|
-
connection.columns_hash
|
114
|
-
end
|
115
|
-
|
116
|
-
def schema_cache
|
117
|
-
connection
|
118
|
-
end
|
119
|
-
|
120
|
-
def quote thing, column = nil
|
121
|
-
connection.quote thing, column
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
class Base
|
126
|
-
attr_accessor :connection_pool
|
127
|
-
|
128
|
-
def initialize
|
129
|
-
@connection_pool = ConnectionPool.new
|
130
|
-
end
|
131
|
-
|
132
|
-
def connection
|
133
|
-
connection_pool.connection
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rgeo/active_record'
|
3
|
-
require 'support/fake_record'
|
4
|
-
|
5
|
-
Arel::Visitors::PostgreSQL.send(:include, ::RGeo::ActiveRecord::SpatialToSql)
|
6
|
-
Arel::Table.engine = FakeRecord::Base.new
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'byebug'
|
10
|
-
rescue LoadError
|
11
|
-
# ignore
|
12
|
-
end
|