activerecord-mysql2spatial-adapter 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ === 0.4.0 / 2011-08-15
2
+
3
+ * Various fixes for Rails 3.1 compatibility.
4
+ * Now requires rgeo-activerecord 0.4.0.
5
+ * INCOMPATIBLE CHANGE: simple queries (e.g. MyClass.where(:latlon => my_point)) use an objective rather than spatial equality test. Earlier versions transformed this form to use st_equals, but now if you need to test for spatial equality, you'll need to call st_equals explicitly. I'm still evaluating which direction we want to go with this in the future, but we may be stuck with the current behavior because the hack required to transform these queries to use spatial equality was egregious and broke in Rails 3.1 with no clear workaround.
6
+
7
+ === 0.3.3 / 2011-06-21
8
+
9
+ * Require latest rgeo-activerecord to get some fixes.
10
+ * Support hex format for attribute setting.
11
+ * No longer raises exceptions if parse fails on attribute setting. (Reported by Daniel Hackney)
12
+
1
13
  === 0.3.2 / 2011-04-11
2
14
 
3
15
  * A .gemspec file is now available for gem building and bundler git integration.
data/README.rdoc CHANGED
@@ -77,7 +77,7 @@ Now you can interact with the data using the RGeo types:
77
77
 
78
78
  === Spatial Queries
79
79
 
80
- You can create simple queries based on spatial equality in the same way
80
+ You can create simple queries based on objective equality in the same way
81
81
  you would on a scalar column:
82
82
 
83
83
  rec = MySpatialTable.where(:latlon => RGeo::Geos.factory.point(-122, 47)).first
@@ -101,9 +101,10 @@ This adapter has the following requirements:
101
101
  * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
102
102
  * MySQL server 5.0 or later required for spatial extensions.
103
103
  * \ActiveRecord 3.0.3 or later. Earlier versions will not work.
104
- * mysql2 gem 0.2.6 or later.
105
- * rgeo gem 0.2.8 or later.
106
- * rgeo-activerecord gem 0.3.3 or later.
104
+ Appears to be compatible with Rails 3.1rc5.
105
+ * mysql2 gem 0.3.6 or later.
106
+ * rgeo gem 0.3.2 or later.
107
+ * rgeo-activerecord gem 0.4.0 or later.
107
108
 
108
109
  Install this adapter as a gem:
109
110
 
@@ -156,6 +157,8 @@ Contributions are welcome. Fork the project on Github.
156
157
 
157
158
  Report bugs on Github issues at http://github.org/dazuma/activerecord-mysql2spatial-adapter/issues
158
159
 
160
+ Support available on the rgeo-users google group at http://groups.google.com/group/rgeo-users
161
+
159
162
  Contact the author at dazuma at gmail dot com.
160
163
 
161
164
  === Acknowledgments
data/Version CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -49,6 +49,11 @@ module ActiveRecord
49
49
  NATIVE_DATABASE_TYPES = Mysql2Adapter::NATIVE_DATABASE_TYPES.merge(:spatial => {:name => "geometry"})
50
50
 
51
51
 
52
+ def set_rgeo_factory_settings(factory_settings_)
53
+ @rgeo_factory_settings = factory_settings_
54
+ end
55
+
56
+
52
57
  def adapter_name
53
58
  Mysql2SpatialAdapter::ADAPTER_NAME
54
59
  end
@@ -100,7 +105,8 @@ module ActiveRecord
100
105
  result_ = execute("SHOW FIELDS FROM #{quote_table_name(table_name_)}", :skip_logging)
101
106
  columns_ = []
102
107
  result_.each(:symbolize_keys => true, :as => :hash) do |field_|
103
- columns_ << SpatialColumn.new(field_[:Field], field_[:Default], field_[:Type], field_[:Null] == "YES")
108
+ columns_ << SpatialColumn.new(@rgeo_factory_settings, table_name_.to_s,
109
+ field_[:Field], field_[:Default], field_[:Type], field_[:Null] == "YES")
104
110
  end
105
111
  columns_
106
112
  end
@@ -46,18 +46,14 @@ module ActiveRecord
46
46
  class SpatialColumn < ConnectionAdapters::Mysql2Column
47
47
 
48
48
 
49
- def initialize(name_, default_, sql_type_=nil, null_=true)
49
+ def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, null_=true)
50
+ @factory_settings = factory_settings_
51
+ @table_name = table_name_
50
52
  super(name_, default_,sql_type_, null_)
51
53
  @geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(sql_type_)
52
54
  if type == :spatial
53
55
  @limit = {:type => @geometric_type.type_name.underscore}
54
56
  end
55
- @ar_class = ::ActiveRecord::Base
56
- end
57
-
58
-
59
- def set_ar_class(val_)
60
- @ar_class = val_
61
57
  end
62
58
 
63
59
 
@@ -75,12 +71,21 @@ module ActiveRecord
75
71
 
76
72
 
77
73
  def type_cast(value_)
78
- type == :spatial ? SpatialColumn.convert_to_geometry(value_, @ar_class, name) : super
74
+ if type == :spatial
75
+ SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name)
76
+ else
77
+ super
78
+ end
79
79
  end
80
80
 
81
81
 
82
82
  def type_cast_code(var_name_)
83
- type == :spatial ? "::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn.convert_to_geometry(#{var_name_}, self.class, #{name.inspect})" : super
83
+ if type == :spatial
84
+ "::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn.convert_to_geometry("+
85
+ "#{var_name_}, self.class.rgeo_factory_settings, self.class.table_name, #{name.inspect})"
86
+ else
87
+ super
88
+ end
84
89
  end
85
90
 
86
91
 
@@ -91,19 +96,27 @@ module ActiveRecord
91
96
  end
92
97
 
93
98
 
94
- def self.convert_to_geometry(input_, ar_class_, column_)
99
+ def self.convert_to_geometry(input_, factory_settings_, table_name_, column_)
95
100
  case input_
96
101
  when ::RGeo::Feature::Geometry
97
- factory_ = ar_class_.rgeo_factory_for_column(column_, :srid => input_.srid)
98
- ::RGeo::Feature.cast(input_, factory_)
102
+ factory_ = factory_settings_.get_column_factory(table_name_, column_, :srid => input_.srid)
103
+ ::RGeo::Feature.cast(input_, factory_) rescue nil
99
104
  when ::String
100
105
  marker_ = input_[4,1]
101
106
  if marker_ == "\x00" || marker_ == "\x01"
102
- factory_ = ar_class_.rgeo_factory_for_column(column_, :srid => input_[0,4].unpack(marker_ == "\x01" ? 'V' : 'N').first)
103
- ::RGeo::WKRep::WKBParser.new(factory_).parse(input_[4..-1])
107
+ factory_ = factory_settings_.get_column_factory(table_name_, column_,
108
+ :srid => input_[0,4].unpack(marker_ == "\x01" ? 'V' : 'N').first)
109
+ ::RGeo::WKRep::WKBParser.new(factory_).parse(input_[4..-1]) rescue nil
110
+ elsif input_[0,10] =~ /[0-9a-fA-F]{8}0[01]/
111
+ srid_ = input_[0,8].to_i(16)
112
+ if input[9,1] == '1'
113
+ srid_ = [srid_].pack('V').unpack('N').first
114
+ end
115
+ factory_ = factory_settings_.get_column_factory(table_name_, column_, :srid => srid_)
116
+ ::RGeo::WKRep::WKBParser.new(factory_).parse(input_[8..-1]) rescue nil
104
117
  else
105
- factory_ = ar_class_.rgeo_factory_for_column(column_)
106
- ::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true).parse(input_)
118
+ factory_ = factory_settings_.get_column_factory(table_name_, column_)
119
+ ::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true).parse(input_) rescue nil
107
120
  end
108
121
  else
109
122
  nil
data/test/tc_basic.rb CHANGED
@@ -105,7 +105,7 @@ module RGeo
105
105
  assert_nil(obj_.latlon)
106
106
  obj_.latlon = @factory.point(1, 2)
107
107
  assert_equal(@factory.point(1, 2), obj_.latlon)
108
- assert_equal(4326, obj_.latlon.srid)
108
+ assert_equal(3785, obj_.latlon.srid)
109
109
  end
110
110
 
111
111
 
@@ -127,7 +127,7 @@ module RGeo
127
127
  id_ = obj_.id
128
128
  obj2_ = klass_.find(id_)
129
129
  assert_equal(@factory.point(1, 2), obj2_.latlon)
130
- assert_equal(4326, obj2_.latlon.srid)
130
+ assert_equal(3785, obj2_.latlon.srid)
131
131
  end
132
132
 
133
133
 
@@ -72,14 +72,14 @@ module RGeo
72
72
  obj_.latlon = @factory.point(1, 2)
73
73
  obj_.save!
74
74
  id_ = obj_.id
75
- obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
75
+ obj2_ = klass_.where(:latlon => @factory.point(1, 2)).first
76
76
  assert_equal(id_, obj2_.id)
77
77
  obj3_ = klass_.where(:latlon => @factory.point(2, 2)).first
78
78
  assert_nil(obj3_)
79
79
  end
80
80
 
81
81
 
82
- def test_query_point_wkt
82
+ def _test_query_point_wkt
83
83
  klass_ = populate_ar_class(:latlon_point)
84
84
  obj_ = klass_.new
85
85
  obj_.latlon = @factory.point(1, 2)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: activerecord-mysql2spatial-adapter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Azuma
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-11 00:00:00 Z
13
+ date: 2011-08-15 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rgeo-activerecord
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.3.3
23
+ version: 0.4.0
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.2.6
34
+ version: 0.3.6
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  description: This is an ActiveRecord connection adapter for MySQL Spatial Extensions. It is based on the stock MySQL2 adapter, but provides built-in support for spatial columns. It uses the RGeo library to represent spatial data in Ruby.
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  requirements: []
78
78
 
79
79
  rubyforge_project: virtuoso
80
- rubygems_version: 1.7.2
80
+ rubygems_version: 1.8.7
81
81
  signing_key:
82
82
  specification_version: 3
83
83
  summary: An ActiveRecord adapter for MySQL Spatial Extensions, based on RGeo and the mysql2 gem.