Skip to content

Commit 2862fd1

Browse files
committed
Several fixes for Rails 3.2
1 parent 33139e6 commit 2862fd1

File tree

4 files changed

+80
-20
lines changed

4 files changed

+80
-20
lines changed

Rakefile

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# -----------------------------------------------------------------------------
2-
#
3-
# MySQL2 Spatial ActiveRecord Adapter Rakefile
4-
#
2+
#
3+
# Generic Gem Rakefile
4+
#
55
# -----------------------------------------------------------------------------
6-
# Copyright 2010 Daniel Azuma
7-
#
6+
# Copyright 2010-2012 Daniel Azuma
7+
#
88
# All rights reserved.
9-
#
9+
#
1010
# Redistribution and use in source and binary forms, with or without
1111
# modification, are permitted provided that the following conditions are met:
12-
#
12+
#
1313
# * Redistributions of source code must retain the above copyright notice,
1414
# this list of conditions and the following disclaimer.
1515
# * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
1818
# * Neither the name of the copyright holder, nor the names of any other
1919
# contributors to this software, may be used to endorse or promote products
2020
# derived from this software without specific prior written permission.
21-
#
21+
#
2222
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2323
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2424
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,9 +34,11 @@
3434
;
3535

3636

37-
RAKEFILE_CONFIG = {
38-
:product_visible_name => 'MySQL2 Spatial ActiveRecord Adapter',
39-
}
37+
# Load config if present
38+
39+
config_path_ = ::File.expand_path('rakefile_config.rb', ::File.dirname(__FILE__))
40+
load(config_path_) if ::File.exists?(config_path_)
41+
RAKEFILE_CONFIG = {} unless defined?(::RAKEFILE_CONFIG)
4042

4143

4244
# Gemspec
@@ -45,12 +47,11 @@ require 'rubygems'
4547
gemspec_ = eval(::File.read(::Dir.glob('*.gemspec').first))
4648
release_gemspec_ = eval(::File.read(::Dir.glob('*.gemspec').first))
4749
release_gemspec_.version = gemspec_.version.to_s.sub(/\.build\d+$/, '')
48-
RAKEFILE_CONFIG = {} unless defined?(::RAKEFILE_CONFIG)
4950

5051

5152
# Platform info
5253

53-
dlext_ = ::Config::CONFIG['DLEXT']
54+
dlext_ = ::RbConfig::CONFIG['DLEXT']
5455

5556
platform_ =
5657
case ::RUBY_DESCRIPTION
@@ -147,9 +148,9 @@ end
147148
clean_files_ = [doc_directory_, pkg_directory_, tmp_directory_] +
148149
::Dir.glob('ext/**/Makefile*') +
149150
::Dir.glob('ext/**/*.{o,class,log,dSYM}') +
150-
::Dir.glob("**/*.{#{dlext_},rbc,jar}") +
151+
::Dir.glob("**/*.{bundle,so,dll,rbc,jar}") +
151152
(::RAKEFILE_CONFIG[:extra_clean_files] || [])
152-
task :clean do
153+
task :clean do
153154
clean_files_.each{ |path_| rm_rf path_ }
154155
end
155156

@@ -184,13 +185,15 @@ end
184185

185186
# Gem release tasks
186187

187-
task :build_gem do
188+
task :build_other
189+
190+
task :build_gem => :build_other do
188191
::Gem::Builder.new(gemspec_).build
189192
mkdir_p(pkg_directory_)
190193
mv "#{gemspec_.name}-#{gemspec_.version}.gem", "#{pkg_directory_}/"
191194
end
192195

193-
task :build_release do
196+
task :build_release => :build_other do
194197
::Gem::Builder.new(release_gemspec_).build
195198
mkdir_p(pkg_directory_)
196199
mv "#{release_gemspec_.name}-#{release_gemspec_.version}.gem", "#{pkg_directory_}/"
@@ -205,7 +208,7 @@ end
205208

206209
# Unit test task
207210

208-
task :test => :build_ext do
211+
task :test => [:build_ext, :build_other] do
209212
$:.unshift(::File.expand_path('lib', ::File.dirname(__FILE__)))
210213
if ::ENV['TESTCASE']
211214
test_files_ = ::Dir.glob("test/#{::ENV['TESTCASE']}.rb")

lib/active_record/connection_adapters/mysql2spatial_adapter/main_adapter.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ class MainAdapter < ConnectionAdapters::Mysql2Adapter
4949
NATIVE_DATABASE_TYPES = Mysql2Adapter::NATIVE_DATABASE_TYPES.merge(:spatial => {:name => "geometry"})
5050

5151

52+
def initialize(*args_)
53+
super
54+
# Rails 3.2 way of defining the visitor: do so in the constructor
55+
if defined?(@visitor) && @visitor
56+
@visitor = ::Arel::Visitors::MySQL2Spatial.new(self)
57+
end
58+
end
59+
60+
5261
def set_rgeo_factory_settings(factory_settings_)
5362
@rgeo_factory_settings = factory_settings_
5463
end

lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ module ConnectionAdapters
4343
module Mysql2SpatialAdapter
4444

4545

46-
class SpatialColumn < ConnectionAdapters::Mysql2Column
46+
# ActiveRecord 3.2 uses ConnectionAdapters::Mysql2Adapter::Column
47+
# whereas 3.0 and 3.1 use ConnectionAdapters::Mysql2Column
48+
column_base_class_ = defined?(ConnectionAdapters::Mysql2Adapter::Column) ?
49+
ConnectionAdapters::Mysql2Adapter::Column : ConnectionAdapters::Mysql2Column
50+
51+
class SpatialColumn < column_base_class_
52+
53+
54+
FACTORY_SETTINGS_CACHE = {}
4755

4856

4957
def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, null_=true)
@@ -54,6 +62,7 @@ def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, n
5462
if type == :spatial
5563
@limit = {:type => @geometric_type.type_name.underscore}
5664
end
65+
FACTORY_SETTINGS_CACHE[factory_settings_.object_id] = factory_settings_
5766
end
5867

5968

@@ -82,7 +91,8 @@ def type_cast(value_)
8291
def type_cast_code(var_name_)
8392
if type == :spatial
8493
"::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn.convert_to_geometry("+
85-
"#{var_name_}, self.class.rgeo_factory_settings, self.class.table_name, #{name.inspect})"
94+
"#{var_name_}, ::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn::"+
95+
"FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, #{name.inspect})"
8696
else
8797
super
8898
end

rakefile_config.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -----------------------------------------------------------------------------
2+
#
3+
# MySQL2 Spatial Adapter Rakefile configuration
4+
#
5+
# -----------------------------------------------------------------------------
6+
# Copyright 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+
RAKEFILE_CONFIG = {
37+
:product_visible_name => 'MySQL2 Spatial ActiveRecord Adapter',
38+
}

0 commit comments

Comments
 (0)