rgeo-activerecord 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.4.2 / 2012-01-09
2
+
3
+ * Added an "rgeo-activerecord.rb" wrapper so bundler's auto-require will work without modification. (Reported by Mauricio Pasquier Juan.)
4
+ * Fixed unit tests so they actually pass...
5
+
1
6
  === 0.4.1 / 2011-10-26
2
7
 
3
8
  * Fixed wrong variable name crash in rgeo_factory_for_column (patch by Andy Allan).
@@ -22,10 +22,10 @@ spatial \ActiveRecord adapters based on \RGeo.
22
22
  RGeo::ActiveRecord has the following requirements:
23
23
 
24
24
  * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
25
- * \RGeo 0.3.2 or later.
26
- * \ActiveRecord 3.0.3 or later. Earlier versions will not work.
25
+ * rgeo 0.3.3 or later.
26
+ * activerecord 3.0.3 or later. Earlier versions will not work.
27
27
  Should be compatible with Rails 3.1.
28
- * \Arel 2.0.6 or later. Earlier versions will not work.
28
+ * arel 2.0.6 or later. Earlier versions will not work.
29
29
 
30
30
  Generally, \ActiveRecord adapters which depend on this module should be
31
31
  installed as gems, and they will install this module automatically as
@@ -70,7 +70,7 @@ Development of \RGeo is sponsored by GeoPage, Inc. (http://www.geopage.com).
70
70
 
71
71
  === License
72
72
 
73
- Copyright 2010-2011 Daniel Azuma
73
+ Copyright 2010-2012 Daniel Azuma
74
74
 
75
75
  All rights reserved.
76
76
 
data/Version CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -0,0 +1,36 @@
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
+
36
+ require 'rgeo/active_record'
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # ActiveRecord extensions for RGeo
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -40,23 +40,23 @@ require 'active_record'
40
40
 
41
41
 
42
42
  # RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
43
- #
43
+ #
44
44
  # The optional RGeo::ActiveRecord module provides spatial extensions for
45
45
  # ActiveRecord, and a set of tools and helpers for writing RGeo-based
46
46
  # spatial connection adapters.
47
47
 
48
48
  module RGeo
49
-
50
-
49
+
50
+
51
51
  # This module contains a set of ActiveRecord extensions for RGeo.
52
52
  # Generally, you will not need to interact with the contents of this
53
53
  # module directly, unless you are writing a spatial ActiveRecord
54
54
  # connection adapter.
55
-
55
+
56
56
  module ActiveRecord
57
57
  end
58
-
59
-
58
+
59
+
60
60
  end
61
61
 
62
62
 
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Helper methods for ActiveRecord adapter tests
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,26 +41,26 @@ require 'logger'
41
41
 
42
42
  module RGeo
43
43
  module ActiveRecord
44
-
45
-
44
+
45
+
46
46
  # A helper module for creating unit tests for adapters.
47
-
47
+
48
48
  module AdapterTestHelper
49
-
49
+
50
50
  @class_num = 0
51
-
52
-
51
+
52
+
53
53
  # When this module is included in a test case class, it
54
54
  # automatically attempts to load the database config file from the
55
55
  # path specified by the class's DATABASE_CONFIG_FILE constant.
56
56
  # It then defines the DATABASE_CONFIG and DEFAULT_AR_CLASS constants
57
57
  # in the testcase class.
58
- #
58
+ #
59
59
  # When you define your test methods, you should wrap them in a call
60
60
  # to the class method define_test_methods. This will cause them to
61
61
  # be defined conditionally based on whether the database config is
62
62
  # present.
63
-
63
+
64
64
  def self.included(klass_)
65
65
  database_config_ = ::YAML.load_file(klass_.const_get(:DATABASE_CONFIG_PATH)) rescue nil
66
66
  if database_config_
@@ -85,8 +85,8 @@ module RGeo
85
85
  end
86
86
  end
87
87
  end
88
-
89
-
88
+
89
+
90
90
  def self.new_class(param_) # :nodoc:
91
91
  base_ = param_.kind_of?(::Class) ? param_ : ::ActiveRecord::Base
92
92
  config_ = param_.kind_of?(::Hash) ? param_ : nil
@@ -99,31 +99,31 @@ module RGeo
99
99
  end
100
100
  klass_
101
101
  end
102
-
103
-
102
+
103
+
104
104
  # Default setup method that calls cleanup_tables.
105
105
  # It also defines a couple of useful factories: @factory (a
106
106
  # cartesian factory) and @geographic_factory (a spherical factory)
107
-
107
+
108
108
  def setup
109
109
  @factory = ::RGeo::Cartesian.preferred_factory(:srid => 3785)
110
110
  @geographic_factory = ::RGeo::Geographic.spherical_factory(:srid => 4326)
111
111
  cleanup_tables
112
112
  end
113
-
114
-
113
+
114
+
115
115
  # Default teardown method that calls cleanup_tables.
116
-
116
+
117
117
  def teardown
118
118
  cleanup_tables
119
119
  end
120
-
121
-
120
+
121
+
122
122
  # Utility method that attempts to clean up any table that was
123
123
  # created by a test method. Normally called automatically at setup
124
124
  # and teardown. If you override those methods, you'll need to call
125
125
  # this from your method.
126
-
126
+
127
127
  def cleanup_tables
128
128
  klass_ = self.class.const_get(:DEFAULT_AR_CLASS)
129
129
  if klass_.connection.tables.include?('spatial_test')
@@ -139,18 +139,18 @@ module RGeo
139
139
  klass_.connection.clear_cache!
140
140
  end
141
141
  end
142
-
143
-
142
+
143
+
144
144
  # Utility method that creates and returns a new ActiveRecord class
145
145
  # subclassing the DEFAULT_AR_CLASS.
146
-
146
+
147
147
  def create_ar_class(opts_={})
148
148
  @ar_class = AdapterTestHelper.new_class(self.class.const_get(:DEFAULT_AR_CLASS))
149
149
  end
150
-
151
-
150
+
151
+
152
152
  end
153
-
154
-
153
+
154
+
155
155
  end
156
156
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
3
- # Mysqlgeo adapter for ActiveRecord
4
- #
2
+ #
3
+ # Additions to ActiveRecord::Base for factory settings
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,12 +38,12 @@ require 'active_record'
38
38
 
39
39
 
40
40
  module RGeo
41
-
41
+
42
42
  module ActiveRecord
43
-
44
-
43
+
44
+
45
45
  # The default factory generator for ActiveRecord::Base.
46
-
46
+
47
47
  DEFAULT_FACTORY_GENERATOR = ::Proc.new do |config_|
48
48
  if config_.delete(:geographic)
49
49
  ::RGeo::Geographic.spherical_factory(config_)
@@ -51,35 +51,35 @@ module RGeo
51
51
  ::RGeo::Cartesian.preferred_factory(config_)
52
52
  end
53
53
  end
54
-
55
-
54
+
55
+
56
56
  # An object that manages the RGeo factories for a ConnectionPool.
57
-
57
+
58
58
  class RGeoFactorySettings
59
-
59
+
60
60
  def initialize # :nodoc:
61
61
  @factory_generators = {}
62
62
  @column_factories = {}
63
63
  end
64
-
65
-
64
+
65
+
66
66
  # Get the default factory generator for the given table
67
-
67
+
68
68
  def get_factory_generator(table_name_)
69
69
  @factory_generators[table_name_.to_s] || ::RGeo::ActiveRecord::DEFAULT_FACTORY_GENERATOR
70
70
  end
71
-
72
-
71
+
72
+
73
73
  # Set the default factory generator for the given table
74
-
74
+
75
75
  def set_factory_generator(table_name_, gen_)
76
76
  @factory_generators[table_name_.to_s] = gen_
77
77
  end
78
-
79
-
78
+
79
+
80
80
  # Get the factory or factory generator for the given table name
81
81
  # and column name.
82
-
82
+
83
83
  def get_column_factory(table_name_, column_name_, params_=nil)
84
84
  table_name_ = table_name_.to_s
85
85
  column_name_ = column_name_.to_s
@@ -90,18 +90,18 @@ module RGeo
90
90
  end
91
91
  result_
92
92
  end
93
-
94
-
93
+
94
+
95
95
  # Set the factory or factory generator for the given table name
96
96
  # and column name.
97
-
97
+
98
98
  def set_column_factory(table_name_, column_name_, factory_)
99
99
  (@column_factories[table_name_.to_s] ||= {})[column_name_.to_s] = factory_
100
100
  end
101
-
102
-
101
+
102
+
103
103
  # Clear settings for the given table name, or for all tables
104
-
104
+
105
105
  def clear!(table_name_=nil)
106
106
  if table_name_
107
107
  table_name_ = table_name_.to_s
@@ -112,25 +112,29 @@ module RGeo
112
112
  @column_factories.clear
113
113
  end
114
114
  end
115
-
116
-
115
+
116
+
117
+ DEFAULT = self.new
118
+
119
+
117
120
  end
118
-
119
-
121
+
122
+
120
123
  # Additional class methods on ::ActiveRecord::Base that provide
121
124
  # a way to control the RGeo factory used for ActiveRecord objects.
122
-
125
+
123
126
  module ActiveRecordBaseFactorySettings
124
-
125
-
127
+
128
+
126
129
  # Return the RGeoFactorySettings object associated with this
127
130
  # class's connection.
128
-
131
+
129
132
  def rgeo_factory_settings
130
- connection_pool.rgeo_factory_settings
133
+ pool_ = connection_pool
134
+ pool_ ? pool_.rgeo_factory_settings : RGeoFactorySettings::DEFAULT
131
135
  end
132
-
133
-
136
+
137
+
134
138
  # The value of this attribute is a RGeo::Feature::FactoryGenerator
135
139
  # that is used to generate the proper factory when loading geometry
136
140
  # objects from the database. For example, if the data being loaded
@@ -141,36 +145,36 @@ module RGeo
141
145
  # object. The result of this generator can be overridden by setting
142
146
  # an explicit factory for a given class and column using the
143
147
  # column_rgeo_factory method.
144
-
148
+
145
149
  def rgeo_factory_generator
146
150
  rgeo_factory_settings.get_factory_generator(table_name)
147
151
  end
148
-
149
-
152
+
153
+
150
154
  # Set the rgeo_factory_generator attribute
151
-
155
+
152
156
  def rgeo_factory_generator=(gen_)
153
157
  rgeo_factory_settings.set_factory_generator(table_name, gen_)
154
158
  end
155
-
156
-
159
+
160
+
157
161
  # This is a convenient way to set the rgeo_factory_generator by
158
162
  # passing a block.
159
-
163
+
160
164
  def to_generate_rgeo_factory(&block_)
161
165
  rgeo_factory_settings.set_factory_generator(table_name, block_)
162
166
  end
163
-
164
-
167
+
168
+
165
169
  # Set a specific factory for this ActiveRecord class and the given
166
170
  # column name. This setting, if present, overrides the result of the
167
171
  # rgeo_factory_generator.
168
-
172
+
169
173
  def set_rgeo_factory_for_column(column_name_, factory_)
170
174
  rgeo_factory_settings.set_column_factory(table_name, column_name_, factory_)
171
175
  end
172
-
173
-
176
+
177
+
174
178
  # Returns the factory generator or specific factory to use for this
175
179
  # ActiveRecord class and the given column name.
176
180
  # If an explicit factory was set for the given column, returns it.
@@ -178,28 +182,28 @@ module RGeo
178
182
  # rgeo_factory_generator for this class, and returns the resulting
179
183
  # factory. Otherwise, if no params hash is given, just returns the
180
184
  # rgeo_factory_generator for this class.
181
-
185
+
182
186
  def rgeo_factory_for_column(column_name_, params_=nil)
183
187
  rgeo_factory_settings.get_column_factory(table_name, column_name_, params_)
184
188
  end
185
-
186
-
189
+
190
+
187
191
  end
188
-
192
+
189
193
  ::ActiveRecord::Base.extend(ActiveRecordBaseFactorySettings)
190
-
191
-
194
+
195
+
192
196
  # :stopdoc:
193
-
194
-
197
+
198
+
195
199
  # Patch for connection pool to track geo factories per table name
196
-
200
+
197
201
  ::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
198
-
202
+
199
203
  def rgeo_factory_settings
200
204
  @_rgeo_factory_settings ||= RGeoFactorySettings.new
201
205
  end
202
-
206
+
203
207
  private
204
208
  alias_method :new_connection_without_rgeo_modification, :new_connection
205
209
  def new_connection
@@ -209,13 +213,13 @@ module RGeo
209
213
  end
210
214
  result_
211
215
  end
212
-
216
+
213
217
  end
214
-
215
-
218
+
219
+
216
220
  # :startdoc:
217
-
218
-
221
+
222
+
219
223
  end
220
-
224
+
221
225
  end