rgeo-ar 0.6.1 → 0.7.0
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/LICENSE.txt +29 -0
- data/lib/rgeo/active_record/adapter_test_helper.rb +0 -48
- data/lib/rgeo/active_record/ar_factory_settings.rb +1 -79
- data/lib/rgeo/active_record/arel_spatial_queries.rb +0 -40
- data/lib/rgeo/active_record/common_adapter_elements.rb +35 -76
- data/lib/rgeo/active_record/geometry_mixin.rb +0 -47
- data/lib/rgeo/active_record/spatial_expressions.rb +5 -47
- data/lib/rgeo/active_record/version.rb +1 -35
- data/lib/rgeo/active_record.rb +5 -62
- data/test/tc_basic.rb +0 -43
- metadata +5 -3
- data/lib/rgeo/active_record/task_hacker.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 884d15ce933553a27a4b32bb75f6bb4d05de3528
|
4
|
+
data.tar.gz: 2a39a44670be789d1413d0bd5f7f14dc2e36a077
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78814b6eff0aef502a235350a14d911a8dd5bf134927e3824513f490ded0e74667cf6964a543fdb8723d060e439af7efcdf54a80854891bd055733350b0418f4
|
7
|
+
data.tar.gz: 7c0ad97aa229444d9050281dc93b1565b1f37da1993b3d75a9d26ba448162a11bc15a5de78555f52ab4ca4b899c96dc7e0ec9c5fe1c9402f8f25e7b37ebdfe7a
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Copyright 2010-2012 Daniel Azuma
|
3
|
+
#
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
15
|
+
# contributors to this software, may be used to endorse or promote products
|
16
|
+
# derived from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
21
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
22
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
23
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# -----------------------------------------------------------------------------
|
@@ -1,53 +1,13 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Helper methods for ActiveRecord adapter tests
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
require 'rgeo/active_record'
|
36
2
|
require 'yaml'
|
37
3
|
require 'logger'
|
38
4
|
|
39
|
-
|
40
5
|
module RGeo
|
41
6
|
module ActiveRecord
|
42
|
-
|
43
|
-
|
44
7
|
# A helper module for creating unit tests for adapters.
|
45
|
-
|
46
8
|
module AdapterTestHelper
|
47
|
-
|
48
9
|
@class_num = 0
|
49
10
|
|
50
|
-
|
51
11
|
# When this module is included in a test case class, it
|
52
12
|
# automatically attempts to load the database config file from the
|
53
13
|
# path specified by constants defined in the class. It first tries
|
@@ -87,7 +47,6 @@ module RGeo
|
|
87
47
|
end
|
88
48
|
end
|
89
49
|
|
90
|
-
|
91
50
|
def self.new_class(param_) # :nodoc:
|
92
51
|
base_ = param_.kind_of?(::Class) ? param_ : ::ActiveRecord::Base
|
93
52
|
config_ = param_.kind_of?(::Hash) ? param_ : nil
|
@@ -101,7 +60,6 @@ module RGeo
|
|
101
60
|
klass_
|
102
61
|
end
|
103
62
|
|
104
|
-
|
105
63
|
# Default setup method that calls cleanup_tables.
|
106
64
|
# It also defines a couple of useful factories: @factory (a
|
107
65
|
# cartesian factory) and @geographic_factory (a spherical factory)
|
@@ -113,7 +71,6 @@ module RGeo
|
|
113
71
|
cleanup_caches
|
114
72
|
end
|
115
73
|
|
116
|
-
|
117
74
|
# Default teardown method that calls cleanup_tables.
|
118
75
|
|
119
76
|
def teardown
|
@@ -121,7 +78,6 @@ module RGeo
|
|
121
78
|
cleanup_caches
|
122
79
|
end
|
123
80
|
|
124
|
-
|
125
81
|
# Utility method that attempts to clean up any table that was
|
126
82
|
# created by a test method. Normally called automatically at setup
|
127
83
|
# and teardown. If you override those methods, you'll need to call
|
@@ -162,7 +118,6 @@ module RGeo
|
|
162
118
|
end
|
163
119
|
end
|
164
120
|
|
165
|
-
|
166
121
|
# Utility method that creates and returns a new ActiveRecord class
|
167
122
|
# subclassing the DEFAULT_AR_CLASS.
|
168
123
|
|
@@ -170,9 +125,6 @@ module RGeo
|
|
170
125
|
@ar_class = AdapterTestHelper.new_class(self.class.const_get(:DEFAULT_AR_CLASS))
|
171
126
|
end
|
172
127
|
|
173
|
-
|
174
128
|
end
|
175
|
-
|
176
|
-
|
177
129
|
end
|
178
130
|
end
|
@@ -1,45 +1,5 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Additions to ActiveRecord::Base for factory settings
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
|
-
require 'active_record'
|
36
|
-
|
37
|
-
|
38
1
|
module RGeo
|
39
|
-
|
40
2
|
module ActiveRecord
|
41
|
-
|
42
|
-
|
43
3
|
# The default factory generator for ActiveRecord::Base.
|
44
4
|
|
45
5
|
DEFAULT_FACTORY_GENERATOR = ::Proc.new do |config_|
|
@@ -50,9 +10,7 @@ module RGeo
|
|
50
10
|
end
|
51
11
|
end
|
52
12
|
|
53
|
-
|
54
13
|
# An object that manages the RGeo factories for a ConnectionPool.
|
55
|
-
|
56
14
|
class RGeoFactorySettings
|
57
15
|
|
58
16
|
def initialize # :nodoc:
|
@@ -60,24 +18,18 @@ module RGeo
|
|
60
18
|
@column_factories = {}
|
61
19
|
end
|
62
20
|
|
63
|
-
|
64
21
|
# Get the default factory generator for the given table
|
65
|
-
|
66
22
|
def get_factory_generator(table_name_)
|
67
23
|
@factory_generators[table_name_.to_s] || ::RGeo::ActiveRecord::DEFAULT_FACTORY_GENERATOR
|
68
24
|
end
|
69
25
|
|
70
|
-
|
71
26
|
# Set the default factory generator for the given table
|
72
|
-
|
73
27
|
def set_factory_generator(table_name_, gen_)
|
74
28
|
@factory_generators[table_name_.to_s] = gen_
|
75
29
|
end
|
76
30
|
|
77
|
-
|
78
31
|
# Get the factory or factory generator for the given table name
|
79
32
|
# and column name.
|
80
|
-
|
81
33
|
def get_column_factory(table_name_, column_name_, params_=nil)
|
82
34
|
table_name_ = table_name_.to_s
|
83
35
|
column_name_ = column_name_.to_s
|
@@ -89,17 +41,13 @@ module RGeo
|
|
89
41
|
result_
|
90
42
|
end
|
91
43
|
|
92
|
-
|
93
44
|
# Set the factory or factory generator for the given table name
|
94
45
|
# and column name.
|
95
|
-
|
96
46
|
def set_column_factory(table_name_, column_name_, factory_)
|
97
47
|
(@column_factories[table_name_.to_s] ||= {})[column_name_.to_s] = factory_
|
98
48
|
end
|
99
49
|
|
100
|
-
|
101
50
|
# Clear settings for the given table name, or for all tables
|
102
|
-
|
103
51
|
def clear!(table_name_=nil)
|
104
52
|
if table_name_
|
105
53
|
table_name_ = table_name_.to_s
|
@@ -111,22 +59,14 @@ module RGeo
|
|
111
59
|
end
|
112
60
|
end
|
113
61
|
|
114
|
-
|
115
62
|
DEFAULT = self.new
|
116
|
-
|
117
|
-
|
118
63
|
end
|
119
64
|
|
120
|
-
|
121
65
|
# Additional class methods on ::ActiveRecord::Base that provide
|
122
66
|
# a way to control the RGeo factory used for ActiveRecord objects.
|
123
|
-
|
124
67
|
module ActiveRecordBaseFactorySettings
|
125
|
-
|
126
|
-
|
127
68
|
# Return the RGeoFactorySettings object associated with this
|
128
69
|
# class's connection.
|
129
|
-
|
130
70
|
def rgeo_factory_settings
|
131
71
|
pool_ = begin
|
132
72
|
connection_pool
|
@@ -136,7 +76,6 @@ module RGeo
|
|
136
76
|
pool_ ? pool_.rgeo_factory_settings : RGeoFactorySettings::DEFAULT
|
137
77
|
end
|
138
78
|
|
139
|
-
|
140
79
|
# The value of this attribute is a RGeo::Feature::FactoryGenerator
|
141
80
|
# that is used to generate the proper factory when loading geometry
|
142
81
|
# objects from the database. For example, if the data being loaded
|
@@ -152,31 +91,24 @@ module RGeo
|
|
152
91
|
rgeo_factory_settings.get_factory_generator(table_name)
|
153
92
|
end
|
154
93
|
|
155
|
-
|
156
94
|
# Set the rgeo_factory_generator attribute
|
157
|
-
|
158
95
|
def rgeo_factory_generator=(gen_)
|
159
96
|
rgeo_factory_settings.set_factory_generator(table_name, gen_)
|
160
97
|
end
|
161
98
|
|
162
|
-
|
163
99
|
# This is a convenient way to set the rgeo_factory_generator by
|
164
100
|
# passing a block.
|
165
|
-
|
166
101
|
def to_generate_rgeo_factory(&block_)
|
167
102
|
rgeo_factory_settings.set_factory_generator(table_name, block_)
|
168
103
|
end
|
169
104
|
|
170
|
-
|
171
105
|
# Set a specific factory for this ActiveRecord class and the given
|
172
106
|
# column name. This setting, if present, overrides the result of the
|
173
107
|
# rgeo_factory_generator.
|
174
|
-
|
175
108
|
def set_rgeo_factory_for_column(column_name_, factory_)
|
176
109
|
rgeo_factory_settings.set_column_factory(table_name, column_name_, factory_)
|
177
110
|
end
|
178
111
|
|
179
|
-
|
180
112
|
# Returns the factory generator or specific factory to use for this
|
181
113
|
# ActiveRecord class and the given column name.
|
182
114
|
# If an explicit factory was set for the given column, returns it.
|
@@ -184,29 +116,23 @@ module RGeo
|
|
184
116
|
# rgeo_factory_generator for this class, and returns the resulting
|
185
117
|
# factory. Otherwise, if no params hash is given, just returns the
|
186
118
|
# rgeo_factory_generator for this class.
|
187
|
-
|
188
119
|
def rgeo_factory_for_column(column_name_, params_=nil)
|
189
120
|
rgeo_factory_settings.get_column_factory(table_name, column_name_, params_)
|
190
121
|
end
|
191
|
-
|
192
|
-
|
193
122
|
end
|
194
123
|
|
195
124
|
::ActiveRecord::Base.extend(ActiveRecordBaseFactorySettings)
|
196
125
|
|
197
|
-
|
198
126
|
# :stopdoc:
|
199
127
|
|
200
|
-
|
201
128
|
# Patch for connection pool to track geo factories per table name
|
202
|
-
|
203
129
|
::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
|
204
|
-
|
205
130
|
def rgeo_factory_settings
|
206
131
|
@_rgeo_factory_settings ||= RGeoFactorySettings.new
|
207
132
|
end
|
208
133
|
|
209
134
|
private
|
135
|
+
|
210
136
|
alias_method :new_connection_without_rgeo_modification, :new_connection
|
211
137
|
def new_connection
|
212
138
|
result_ = new_connection_without_rgeo_modification
|
@@ -215,13 +141,9 @@ module RGeo
|
|
215
141
|
end
|
216
142
|
result_
|
217
143
|
end
|
218
|
-
|
219
144
|
end
|
220
145
|
|
221
|
-
|
222
146
|
# :startdoc:
|
223
147
|
|
224
|
-
|
225
148
|
end
|
226
|
-
|
227
149
|
end
|
@@ -1,37 +1,3 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Various Arel hacks to support spatial queries
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
module RGeo
|
36
2
|
module ActiveRecord
|
37
3
|
# A set of common Arel visitor hacks for spatial ToSql visitors.
|
@@ -122,12 +88,6 @@ module RGeo
|
|
122
88
|
alias :visit_RGeo_Cartesian_BoundingBox :visit_String
|
123
89
|
end
|
124
90
|
|
125
|
-
# Add tools to build spatial structures in the AST.
|
126
|
-
|
127
|
-
# Allow chaining of spatial expressions from attributes
|
128
|
-
::Arel::Attribute.class_eval do
|
129
|
-
include ::RGeo::ActiveRecord::SpatialExpressions
|
130
|
-
end
|
131
91
|
|
132
92
|
# A NamedFunction subclass that keeps track of the spatial-ness of
|
133
93
|
# the arguments and return values, so that it can provide context to
|
@@ -1,54 +1,10 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
# Common tools for spatial adapters for ActiveRecord
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
|
-
|
36
|
-
require 'active_support/core_ext/class' # Workaround for a missing require in ActiveRecord 3.2.1
|
37
|
-
require 'active_record'
|
38
|
-
|
39
|
-
# Force AbstractAdapter to autoload
|
40
|
-
if ::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
41
|
-
end
|
42
|
-
|
1
|
+
# autoload AbstractAdapter
|
2
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
43
3
|
|
44
4
|
module RGeo
|
45
|
-
|
46
5
|
module ActiveRecord
|
47
|
-
|
48
|
-
|
49
6
|
# Some default column constructors specifications for most spatial
|
50
7
|
# databases. Individual adapters may add to or override this list.
|
51
|
-
|
52
8
|
DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS = {
|
53
9
|
:spatial => {:type => 'geometry'}.freeze,
|
54
10
|
:geometry => {}.freeze,
|
@@ -61,13 +17,11 @@ module RGeo
|
|
61
17
|
:multi_polygon => {}.freeze,
|
62
18
|
}.freeze
|
63
19
|
|
64
|
-
|
65
20
|
# Index definition struct with a spatial flag field.
|
66
21
|
|
67
22
|
class SpatialIndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths, :orders, :where, :spatial)
|
68
23
|
end
|
69
24
|
|
70
|
-
|
71
25
|
# Returns a feature type module given a string type.
|
72
26
|
|
73
27
|
def self.geometric_type_from_name(name_)
|
@@ -84,17 +38,18 @@ module RGeo
|
|
84
38
|
end
|
85
39
|
end
|
86
40
|
|
87
|
-
|
88
41
|
# :stopdoc:
|
89
42
|
|
90
|
-
|
91
43
|
# Provide methods for each geometric subtype during table definitions.
|
44
|
+
module GeoTableDefinitions
|
45
|
+
def self.included(base)
|
46
|
+
base.class_eval do
|
47
|
+
alias_method :method_missing_without_rgeo, :method_missing
|
48
|
+
alias_method :method_missing, :method_missing_with_rgeo
|
49
|
+
end
|
50
|
+
end
|
92
51
|
|
93
|
-
|
94
|
-
|
95
|
-
alias_method :method_missing_without_rgeo_modification, :method_missing
|
96
|
-
|
97
|
-
def method_missing(method_name_, *args_, &block_)
|
52
|
+
def method_missing_with_rgeo(method_name_, *args_, &block_)
|
98
53
|
if @base.respond_to?(:spatial_column_constructor) && (info_ = @base.spatial_column_constructor(method_name_))
|
99
54
|
info_ = info_.dup
|
100
55
|
type_ = (info_.delete(:type) || method_name_).to_s
|
@@ -103,20 +58,24 @@ module RGeo
|
|
103
58
|
column(name_, type_, opts_)
|
104
59
|
end
|
105
60
|
else
|
106
|
-
|
61
|
+
method_missing_without_rgeo(method_name_, *args_, &block_)
|
107
62
|
end
|
108
63
|
end
|
109
|
-
|
110
64
|
end
|
111
65
|
|
66
|
+
::ActiveRecord::ConnectionAdapters::TableDefinition.send :include, GeoTableDefinitions
|
112
67
|
|
113
|
-
# Provide methods for each geometric subtype during table changes.
|
114
|
-
|
115
|
-
::ActiveRecord::ConnectionAdapters::Table.class_eval do
|
116
68
|
|
117
|
-
|
69
|
+
# Provide methods for each geometric subtype during table changes.
|
70
|
+
module GeoConnectionAdapters
|
71
|
+
def self.included(base)
|
72
|
+
base.class_eval do
|
73
|
+
alias_method :method_missing_without_rgeo, :method_missing
|
74
|
+
alias_method :method_missing, :method_missing_with_rgeo
|
75
|
+
end
|
76
|
+
end
|
118
77
|
|
119
|
-
def
|
78
|
+
def method_missing_with_rgeo(method_name_, *args_, &block_)
|
120
79
|
if @base.respond_to?(:spatial_column_constructor) && (info_ = @base.spatial_column_constructor(method_name_))
|
121
80
|
info_ = info_.dup
|
122
81
|
type_ = (info_.delete(:type) || method_name_).to_s
|
@@ -125,22 +84,26 @@ module RGeo
|
|
125
84
|
@base.add_column(@table_name, name_, type_, opts_)
|
126
85
|
end
|
127
86
|
else
|
128
|
-
|
87
|
+
method_missing_without_rgeo(method_name_, *args_, &block_)
|
129
88
|
end
|
130
89
|
end
|
131
|
-
|
132
90
|
end
|
133
91
|
|
92
|
+
::ActiveRecord::ConnectionAdapters::Table.send :include, GeoConnectionAdapters
|
134
93
|
|
135
|
-
# Hack schema dumper to output spatial index flag
|
136
94
|
|
137
|
-
|
95
|
+
# Hack schema dumper to output spatial index flag
|
96
|
+
module GeoSchemaDumper
|
97
|
+
def self.included(base)
|
98
|
+
base.class_eval do
|
99
|
+
alias_method :indexes_without_rgeo, :indexes
|
100
|
+
alias_method :indexes, :indexes_with_rgeo
|
101
|
+
end
|
102
|
+
end
|
138
103
|
|
139
104
|
private
|
140
105
|
|
141
|
-
|
142
|
-
|
143
|
-
def indexes(table_, stream_)
|
106
|
+
def indexes_with_rgeo(table_, stream_)
|
144
107
|
if (indexes_ = @connection.indexes(table_)).any?
|
145
108
|
add_index_statements_ = indexes_.map do |index_|
|
146
109
|
statement_parts_ = [
|
@@ -158,19 +121,15 @@ module RGeo
|
|
158
121
|
stream_.puts
|
159
122
|
end
|
160
123
|
end
|
161
|
-
|
162
124
|
end
|
163
125
|
|
126
|
+
::ActiveRecord::SchemaDumper.send :include, GeoSchemaDumper
|
164
127
|
|
165
|
-
# Tell ActiveRecord to cache spatial attribute values so they don't get
|
166
|
-
# re-parsed on every access.
|
167
128
|
|
168
|
-
|
129
|
+
# Tell ActiveRecord to cache spatial attribute values so they don't get re-parsed on every access.
|
169
130
|
|
131
|
+
::ActiveRecord::Base.attribute_types_cached_by_default << :spatial
|
170
132
|
|
171
133
|
# :startdoc:
|
172
|
-
|
173
|
-
|
174
134
|
end
|
175
|
-
|
176
135
|
end
|
@@ -1,55 +1,15 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Geometry mixin for JSON serialization
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
module RGeo
|
36
|
-
|
37
2
|
module ActiveRecord
|
38
|
-
|
39
|
-
|
40
3
|
# This module is mixed into all geometry objects. It provides an
|
41
4
|
# as_json method so that ActiveRecord knows how to generate JSON
|
42
5
|
# for a geometry-valued field.
|
43
6
|
|
44
7
|
module GeometryMixin
|
45
|
-
|
46
|
-
|
47
8
|
# The default JSON generator Proc. Renders geometry fields as WKT.
|
48
9
|
DEFAULT_JSON_GENERATOR = ::Proc.new{ |geom_| geom_.to_s }
|
49
10
|
|
50
11
|
@json_generator = DEFAULT_JSON_GENERATOR
|
51
12
|
|
52
|
-
|
53
13
|
# Set the style of JSON generation used for geometry fields in an
|
54
14
|
# ActiveRecord model by default. You may pass nil to use
|
55
15
|
# DEFAULT_JSON_GENERATOR, a proc that takes a geometry as the
|
@@ -76,7 +36,6 @@ module RGeo
|
|
76
36
|
end
|
77
37
|
end
|
78
38
|
|
79
|
-
|
80
39
|
# Given a feature, returns an object that can be serialized as JSON
|
81
40
|
# (i.e. usually a hash or string), using the current json_generator.
|
82
41
|
# This is used to generate JSON for geometry-valued ActiveRecord
|
@@ -92,15 +51,9 @@ module RGeo
|
|
92
51
|
def as_json(opts_=nil)
|
93
52
|
GeometryMixin.generate_json(self)
|
94
53
|
end
|
95
|
-
|
96
|
-
|
97
54
|
end
|
98
|
-
|
99
|
-
|
100
55
|
end
|
101
|
-
|
102
56
|
end
|
103
57
|
|
104
|
-
|
105
58
|
::RGeo::Feature::MixinCollection::GLOBAL.for_type(::RGeo::Feature::Geometry).
|
106
59
|
add(::RGeo::ActiveRecord::GeometryMixin)
|
@@ -1,42 +1,5 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Spatial expressions for Arel
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
module RGeo
|
36
|
-
|
37
2
|
module ActiveRecord
|
38
|
-
|
39
|
-
|
40
3
|
# Returns true if spatial expressions (i.e. the methods in the
|
41
4
|
# SpatialExpressions module) are supported. Generally, this is true
|
42
5
|
# if Arel is at version 2.1 or later.
|
@@ -45,16 +8,12 @@ module RGeo
|
|
45
8
|
defined?(::Arel::Nodes::NamedFunction)
|
46
9
|
end
|
47
10
|
|
48
|
-
|
49
11
|
# A set of spatial expression builders.
|
50
12
|
# These methods can be chained off other spatial expressions to form
|
51
13
|
# complex expressions.
|
52
14
|
#
|
53
15
|
# These functions require Arel 2.1 or later.
|
54
|
-
|
55
16
|
module SpatialExpressions
|
56
|
-
|
57
|
-
|
58
17
|
#--
|
59
18
|
# Generic functions
|
60
19
|
#++
|
@@ -64,7 +23,6 @@ module RGeo
|
|
64
23
|
::RGeo::ActiveRecord::SpatialNamedFunction.new(function_, [self] + args_, spatial_info_)
|
65
24
|
end
|
66
25
|
|
67
|
-
|
68
26
|
#--
|
69
27
|
# Geometry functions
|
70
28
|
#++
|
@@ -255,7 +213,6 @@ module RGeo
|
|
255
213
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_PointOnSurface', [self], [true, true])
|
256
214
|
end
|
257
215
|
|
258
|
-
|
259
216
|
#--
|
260
217
|
# Polygon functions
|
261
218
|
#++
|
@@ -274,7 +231,6 @@ module RGeo
|
|
274
231
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_InteriorRingN', [self, n_.to_i], [true, true, false])
|
275
232
|
end
|
276
233
|
|
277
|
-
|
278
234
|
#--
|
279
235
|
# GeometryCollection functions
|
280
236
|
#++
|
@@ -287,14 +243,16 @@ module RGeo
|
|
287
243
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_GeometryN', [self, n_.to_i], [true, true, false])
|
288
244
|
end
|
289
245
|
|
290
|
-
|
291
246
|
end
|
292
247
|
|
293
|
-
|
294
248
|
end
|
295
|
-
|
296
249
|
end
|
297
250
|
|
251
|
+
# Add tools to build spatial structures in the AST.
|
252
|
+
|
253
|
+
# Allow chaining of spatial expressions from attributes
|
254
|
+
::Arel::Attribute.send :include, ::RGeo::ActiveRecord::SpatialExpressions
|
255
|
+
|
298
256
|
|
299
257
|
module Arel
|
300
258
|
|
@@ -1,39 +1,5 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Version of rgeo-activerecord
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
module RGeo
|
36
2
|
module ActiveRecord
|
37
|
-
VERSION = '0.
|
3
|
+
VERSION = '0.7.0'.freeze
|
38
4
|
end
|
39
5
|
end
|
data/lib/rgeo/active_record.rb
CHANGED
@@ -1,42 +1,3 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# ActiveRecord extensions for RGeo
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
|
-
# Dependencies
|
36
|
-
require 'rgeo'
|
37
|
-
require 'active_record'
|
38
|
-
|
39
|
-
|
40
1
|
# RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
|
41
2
|
#
|
42
3
|
# The optional RGeo::ActiveRecord module provides spatial extensions for
|
@@ -44,8 +5,6 @@ require 'active_record'
|
|
44
5
|
# spatial connection adapters.
|
45
6
|
|
46
7
|
module RGeo
|
47
|
-
|
48
|
-
|
49
8
|
# This module contains a set of ActiveRecord extensions for RGeo.
|
50
9
|
# Generally, you will not need to interact with the contents of this
|
51
10
|
# module directly, unless you are writing a spatial ActiveRecord
|
@@ -53,29 +12,13 @@ module RGeo
|
|
53
12
|
|
54
13
|
module ActiveRecord
|
55
14
|
end
|
56
|
-
|
57
|
-
|
58
15
|
end
|
59
16
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
module Arel
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
# The rgeo-activerecord gem installs several patches to ActiveRecord
|
69
|
-
# to support services needed by spatial adapters.
|
70
|
-
|
71
|
-
module ActiveRecord
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
# Implementation files
|
76
|
-
require 'rgeo/active_record/version.rb'
|
77
|
-
require 'rgeo/active_record/spatial_expressions.rb'
|
17
|
+
require 'rgeo'
|
18
|
+
require 'active_record'
|
19
|
+
require 'rgeo/active_record/version'
|
20
|
+
require 'rgeo/active_record/spatial_expressions'
|
78
21
|
require 'rgeo/active_record/arel_spatial_queries'
|
79
|
-
require 'rgeo/active_record/common_adapter_elements
|
22
|
+
require 'rgeo/active_record/common_adapter_elements'
|
80
23
|
require 'rgeo/active_record/ar_factory_settings'
|
81
24
|
require 'rgeo/active_record/geometry_mixin'
|
data/test/tc_basic.rb
CHANGED
@@ -1,55 +1,16 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Tests for basic ActiveRecord extensions
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
1
|
require 'test_helper'
|
36
2
|
|
37
3
|
module RGeo
|
38
4
|
module ActiveRecord
|
39
5
|
module Tests # :nodoc:
|
40
|
-
|
41
6
|
class TestBasic < ::MiniTest::Test # :nodoc:
|
42
|
-
|
43
|
-
|
44
7
|
class MyTable < ::ActiveRecord::Base
|
45
8
|
end
|
46
9
|
|
47
|
-
|
48
10
|
def test_has_version
|
49
11
|
assert ::RGeo::ActiveRecord::VERSION
|
50
12
|
end
|
51
13
|
|
52
|
-
|
53
14
|
def test_default_factory_generator
|
54
15
|
MyTable.rgeo_factory_generator = nil
|
55
16
|
factory_ = MyTable.rgeo_factory_for_column(:hello).call(:has_z_coordinate => true, :srid => 4326)
|
@@ -59,7 +20,6 @@ module RGeo
|
|
59
20
|
assert_equal(4326, factory_.srid)
|
60
21
|
end
|
61
22
|
|
62
|
-
|
63
23
|
def test_set_factory_generator
|
64
24
|
MyTable.rgeo_factory_generator = ::RGeo::Geographic.method(:spherical_factory)
|
65
25
|
factory_ = MyTable.rgeo_factory_for_column(:hello, :has_z_coordinate => true, :srid => 4326)
|
@@ -70,7 +30,6 @@ module RGeo
|
|
70
30
|
assert_equal(4326, factory_.srid)
|
71
31
|
end
|
72
32
|
|
73
|
-
|
74
33
|
def test_specific_factory_for_column
|
75
34
|
MyTable.rgeo_factory_generator = nil
|
76
35
|
MyTable.set_rgeo_factory_for_column(:foo, ::RGeo::Geographic.simple_mercator_factory(:has_z_coordinate => true))
|
@@ -82,7 +41,6 @@ module RGeo
|
|
82
41
|
assert_equal(4326, factory_.srid)
|
83
42
|
end
|
84
43
|
|
85
|
-
|
86
44
|
def test_default_as_json_wkt
|
87
45
|
GeometryMixin.set_json_generator(nil)
|
88
46
|
factory_ = ::RGeo::Cartesian.preferred_factory
|
@@ -90,7 +48,6 @@ module RGeo
|
|
90
48
|
assert_equal("POINT (1.0 2.0)", p_.as_json)
|
91
49
|
end
|
92
50
|
|
93
|
-
|
94
51
|
def test_default_as_json_geojson
|
95
52
|
GeometryMixin.set_json_generator(:geojson)
|
96
53
|
factory_ = ::RGeo::Cartesian.preferred_factory
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo-ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rgeo
|
@@ -91,6 +91,7 @@ extra_rdoc_files:
|
|
91
91
|
- README.rdoc
|
92
92
|
files:
|
93
93
|
- History.rdoc
|
94
|
+
- LICENSE.txt
|
94
95
|
- README.rdoc
|
95
96
|
- lib/rgeo-activerecord.rb
|
96
97
|
- lib/rgeo/active_record.rb
|
@@ -100,7 +101,6 @@ files:
|
|
100
101
|
- lib/rgeo/active_record/common_adapter_elements.rb
|
101
102
|
- lib/rgeo/active_record/geometry_mixin.rb
|
102
103
|
- lib/rgeo/active_record/spatial_expressions.rb
|
103
|
-
- lib/rgeo/active_record/task_hacker.rb
|
104
104
|
- lib/rgeo/active_record/version.rb
|
105
105
|
- test/support/fake_record.rb
|
106
106
|
- test/tc_basic.rb
|
@@ -129,5 +129,7 @@ signing_key:
|
|
129
129
|
specification_version: 4
|
130
130
|
summary: An RGeo module providing spatial extensions to ActiveRecord.
|
131
131
|
test_files:
|
132
|
+
- test/support/fake_record.rb
|
132
133
|
- test/tc_basic.rb
|
134
|
+
- test/test_helper.rb
|
133
135
|
has_rdoc:
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# A tool for hacking ActiveRecord's rake tasks
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
|
35
|
-
|
36
|
-
module RGeo
|
37
|
-
|
38
|
-
module ActiveRecord
|
39
|
-
|
40
|
-
|
41
|
-
# A set of tools for hacking ActiveRecord's Rake tasks.
|
42
|
-
|
43
|
-
module TaskHacker
|
44
|
-
|
45
|
-
|
46
|
-
class Action # :nodoc:
|
47
|
-
|
48
|
-
def initialize(env_, pattern_, proc_)
|
49
|
-
@env = env_
|
50
|
-
@pattern = pattern_
|
51
|
-
@proc = proc_
|
52
|
-
end
|
53
|
-
|
54
|
-
def call(task_)
|
55
|
-
env_ = @env || ::Rails.env || 'development'
|
56
|
-
config_ = ::ActiveRecord::Base.configurations[env_]
|
57
|
-
if config_
|
58
|
-
if @pattern === config_['adapter']
|
59
|
-
task_.actions.delete_if{ |a_| a_ != self }
|
60
|
-
@proc.call(config_)
|
61
|
-
end
|
62
|
-
else
|
63
|
-
puts "WARNING: Could not find environment #{env_.inspect} in your database.yml"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def arity
|
68
|
-
1
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
class << self
|
75
|
-
|
76
|
-
|
77
|
-
# Modify a named ActiveRecord rake task.
|
78
|
-
# The task must be of the form that hinges on the database adapter
|
79
|
-
# name. You must provide the fully-qualified name of the rake task
|
80
|
-
# to modify, the Rails environment for which to get the database
|
81
|
-
# configuration (which may be nil to use the current Rails.env),
|
82
|
-
# a Regexp or String identifying the adapter name for which to
|
83
|
-
# modify the rake task, and a block. If the database adapter
|
84
|
-
# associated with the given environment matches the given pattern,
|
85
|
-
# then the rake task's action(s) will be replaced by the given
|
86
|
-
# block. The block will be passed the environment's database
|
87
|
-
# configuration hash.
|
88
|
-
|
89
|
-
def modify(name_, env_, pattern_, &block_)
|
90
|
-
if ::Rake::Task.task_defined?(name_)
|
91
|
-
::Rake::Task[name_].actions.unshift(Action.new(env_, pattern_, block_))
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|