activerecord-postgis-adapter 3.0.0.beta4 → 3.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c4921aa89cd6c33269ff6f2850140020602440b
4
- data.tar.gz: 6a32214e6ccc587ee9ca8c7bdcf29290725d9143
3
+ metadata.gz: da8f856d4cf24c6499865f61ffca7aa83dfde847
4
+ data.tar.gz: bb1f2d2716ef65650d7a438a62554e5f07cea2b0
5
5
  SHA512:
6
- metadata.gz: c4b7f244e186d445554d57be503cd02d6f9cc3f6ead1d3d0f2db5bba7300f9b3a34b0f4f12184984fa7bbf4a3048a4114e6a80be148f2d871cdf1ed59fd286e8
7
- data.tar.gz: aac5a7ac04094aca372a331f1c560f9a208c35a119d520d02cebb7258675a7615c7dd262079ed765f15b2e375b5156d1cbd4152a8532f97ca3d081193d608171
6
+ metadata.gz: 0aae508c94cd5a4d07e72e451b024f69fefb955db49213700490d7a71007cf3f0c7306479b6292e1b98fc841a7b3868bb26b3f91eb6ec916f0d9a47246dea898
7
+ data.tar.gz: 68e42bce528929b082443e7afc6736e80a4d1c89084300e3a648f0574486bae913937a46650153fb357f4f90be69619bbecf9325479e6376821b6d9ccf147179
@@ -30,10 +30,6 @@ module ActiveRecord # :nodoc:
30
30
  # PostGISAdapter::SchemaCreation.new self
31
31
  # end
32
32
 
33
- def set_rgeo_factory_settings(factory_settings)
34
- @rgeo_factory_settings = factory_settings
35
- end
36
-
37
33
  def adapter_name
38
34
  "PostGIS".freeze
39
35
  end
@@ -10,13 +10,8 @@ module ActiveRecord
10
10
  # "geometry(Polygon,4326) NOT NULL"
11
11
  # "geometry(Geography,4326)"
12
12
  def initialize(oid, sql_type)
13
+ @sql_type = sql_type
13
14
  @geo_type, @srid, @has_z, @has_m = self.class.parse_sql_type(sql_type)
14
- if oid =~ /geography/
15
- factory_opts = {srid: (@srid || 4326)}
16
- factory_opts[:has_z_coordinate] = @has_z
17
- factory_opts[:has_m_coordinate] = @has_m
18
- @factory_generator = RGeo::Geographic.spherical_factory(factory_opts)
19
- end
20
15
  end
21
16
 
22
17
  # sql_type: geometry, geometry(Point), geometry(Point,4326), ...
@@ -52,12 +47,19 @@ module ActiveRecord
52
47
  [geo_type, srid, has_z, has_m]
53
48
  end
54
49
 
55
- def factory_generator
56
- @factory_generator
50
+ def spatial_factory
51
+ @spatial_factory ||=
52
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
53
+ geo_type: @geo_type,
54
+ has_m: @has_m,
55
+ has_z: @has_z,
56
+ sql_type: @sql_type,
57
+ srid: @srid,
58
+ )
57
59
  end
58
60
 
59
61
  def geographic?
60
- !!factory_generator
62
+ @sql_type =~ /geography/
61
63
  end
62
64
 
63
65
  def spatial?
@@ -90,16 +92,14 @@ module ActiveRecord
90
92
 
91
93
  def cast_value(value)
92
94
  return if value.nil?
93
- RGeo::WKRep::WKBParser.new(@factory_generator, support_ewkb: true).parse(value)
95
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true).parse(value)
94
96
  rescue RGeo::Error::ParseError
95
97
  nil
96
98
  end
97
99
 
98
100
  # convert WKT string into RGeo object
99
101
  def parse_wkt(string)
100
- # factory = factory_settings.get_column_factory(table_name, column, constraints)
101
- factory = @factory_generator || RGeo::ActiveRecord::RGeoFactorySettings.new
102
- wkt_parser(factory, string).parse(string)
102
+ wkt_parser(string).parse(string)
103
103
  rescue RGeo::Error::ParseError
104
104
  nil
105
105
  end
@@ -108,14 +108,13 @@ module ActiveRecord
108
108
  string[0] == "\x00" || string[0] == "\x01" || string[0, 4] =~ /[0-9a-fA-F]{4}/
109
109
  end
110
110
 
111
- def wkt_parser(factory, string)
111
+ def wkt_parser(string)
112
112
  if binary_string?(string)
113
- RGeo::WKRep::WKBParser.new(factory, support_ewkb: true, default_srid: @srid)
113
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid)
114
114
  else
115
- RGeo::WKRep::WKTParser.new(factory, support_ewkt: true, default_srid: @srid)
115
+ RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
116
116
  end
117
117
  end
118
-
119
118
  end
120
119
  end
121
120
  end
@@ -23,8 +23,7 @@ module ActiveRecord
23
23
 
24
24
  column_info = spatial_column_info(table_name).get(column_name, sql_type)
25
25
 
26
- SpatialColumn.new(@rgeo_factory_settings,
27
- table_name,
26
+ SpatialColumn.new(table_name,
28
27
  column_name,
29
28
  default,
30
29
  cast_type,
@@ -9,8 +9,7 @@ module ActiveRecord # :nodoc:
9
9
  # cast_type example classes:
10
10
  # OID::Spatial
11
11
  # OID::Integer
12
- def initialize(factory_settings, table_name, name, default, cast_type, sql_type = nil, null = true, default_function = nil, opts = nil)
13
- @factory_settings = factory_settings
12
+ def initialize(table_name, name, default, cast_type, sql_type = nil, null = true, default_function = nil, opts = nil)
14
13
  @table_name = table_name
15
14
  @geographic = !!(sql_type =~ /geography\(/i)
16
15
  if opts
@@ -62,11 +61,6 @@ module ActiveRecord # :nodoc:
62
61
  cast_type.respond_to?(:spatial?) && cast_type.spatial?
63
62
  end
64
63
 
65
- # TODO: delete - unused?
66
- def has_spatial_constraints?
67
- !!@srid
68
- end
69
-
70
64
  private
71
65
 
72
66
  def set_geometric_type_from_name(name)
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGISAdapter
4
- VERSION = '3.0.0.beta4'.freeze
4
+ VERSION = '3.0.0.beta5'.freeze
5
5
  end
6
6
  end
7
7
  end
data/test/basic_test.rb CHANGED
@@ -87,19 +87,25 @@ class BasicTest < ActiveSupport::TestCase # :nodoc:
87
87
 
88
88
  def test_custom_factory
89
89
  klass = SpatialModel
90
- klass.connection.create_table(:spatial_test, force: true) do |t|
91
- t.st_point(:latlon, srid: 4326)
92
- end
93
- factory = RGeo::Geographic.simple_mercator_factory
94
- klass.class_eval do
95
- set_rgeo_factory_for_column(:latlon, factory)
90
+ klass.connection.create_table(:spatial_models, force: true) do |t|
91
+ t.st_polygon(:area, srid: 4326)
96
92
  end
97
- assert_equal factory, klass.rgeo_factory_for_column(:latlon)
93
+ klass.reset_column_information
94
+ custom_factory = RGeo::Geographic.spherical_factory(buffer_resolution: 8, srid: 4326)
95
+ spatial_factory_store.register(custom_factory, geo_type: "polygon", srid: 4326)
98
96
  object = klass.new
99
- assert_equal factory, object.class.rgeo_factory_for_column(:latlon)
97
+ area = custom_factory.point(1, 2).buffer(3)
98
+ object.area = area
99
+ object.save!
100
+ object.reload
101
+ assert_equal area.to_s, object.area.to_s
102
+ spatial_factory_store.clear
100
103
  end
101
104
 
102
105
  def test_readme_example
106
+ spatial_factory_store.register(
107
+ RGeo::Geographic.spherical_factory, geo_type: "point", sql_type: "geography")
108
+
103
109
  klass = SpatialModel
104
110
  klass.connection.create_table(:spatial_models, force: true) do |t|
105
111
  t.column(:shape, :geometry)
@@ -111,16 +117,15 @@ class BasicTest < ActiveSupport::TestCase # :nodoc:
111
117
  klass.connection.change_table(:spatial_models) do |t|
112
118
  t.index(:latlon, using: :gist)
113
119
  end
114
- klass.class_eval do
115
- self.rgeo_factory_generator = RGeo::Geos.method(:factory)
116
- set_rgeo_factory_for_column(:latlon, RGeo::Geographic.spherical_factory)
117
- end
120
+
118
121
  object = klass.new
119
122
  object.latlon = 'POINT(-122 47)'
120
123
  point = object.latlon
121
124
  assert_equal 47, point.latitude
122
125
  object.shape = point
123
126
  # assert_equal true, RGeo::Geos.is_geos?(object.shape)
127
+
128
+ spatial_factory_store.clear
124
129
  end
125
130
 
126
131
  def test_point_to_json
@@ -148,5 +153,8 @@ class BasicTest < ActiveSupport::TestCase # :nodoc:
148
153
  end
149
154
  SpatialModel.reset_column_information
150
155
  end
151
- end
152
156
 
157
+ def spatial_factory_store
158
+ RGeo::ActiveRecord::SpatialFactoryStore.instance
159
+ end
160
+ end
data/test/ddl_test.rb CHANGED
@@ -30,7 +30,7 @@ class DDLTest < ActiveSupport::TestCase # :nodoc:
30
30
  assert_equal 1, count_geometry_columns
31
31
  col = klass.columns.last
32
32
  assert_equal RGeo::Feature::Geometry, col.geometric_type
33
- assert_equal true, col.has_spatial_constraints?
33
+ assert_equal true, col.spatial?
34
34
  assert_equal false, col.geographic?
35
35
  assert_equal 0, col.srid
36
36
  klass.connection.drop_table(:spatial_models)
@@ -44,7 +44,7 @@ class DDLTest < ActiveSupport::TestCase # :nodoc:
44
44
  klass.reset_column_information
45
45
  col = klass.columns.last
46
46
  assert_equal RGeo::Feature::Geometry, col.geometric_type
47
- assert_equal true, col.has_spatial_constraints?
47
+ assert_equal true, col.spatial?
48
48
  assert_equal true, col.geographic?
49
49
  assert_equal 4326, col.srid
50
50
  assert_equal 0, count_geometry_columns
@@ -82,13 +82,13 @@ class DDLTest < ActiveSupport::TestCase # :nodoc:
82
82
  columns = klass.columns
83
83
  assert_equal RGeo::Feature::Geometry, columns[-3].geometric_type
84
84
  assert_equal 0, columns[-3].srid
85
- assert_equal true, columns[-3].has_spatial_constraints?
85
+ assert_equal true, columns[-3].spatial?
86
86
  assert_equal RGeo::Feature::Point, columns[-2].geometric_type
87
87
  assert_equal 4326, columns[-2].srid
88
88
  assert_equal false, columns[-2].geographic?
89
- assert_equal true, columns[-2].has_spatial_constraints?
89
+ assert_equal true, columns[-2].spatial?
90
90
  assert_nil columns[-1].geometric_type
91
- assert_equal false, columns[-1].has_spatial_constraints?
91
+ assert_equal false, columns[-1].spatial?
92
92
  end
93
93
 
94
94
  def test_add_geometry_column_null_false
@@ -117,13 +117,13 @@ class DDLTest < ActiveSupport::TestCase # :nodoc:
117
117
  cols_ = klass.columns
118
118
  assert_equal RGeo::Feature::Geometry, cols_[-3].geometric_type
119
119
  assert_equal 0, cols_[-3].srid
120
- assert_equal true, cols_[-3].has_spatial_constraints?
120
+ assert_equal true, cols_[-3].spatial?
121
121
  assert_equal RGeo::Feature::Point, cols_[-2].geometric_type
122
122
  assert_equal 4326, cols_[-2].srid
123
123
  assert_equal true, cols_[-2].geographic?
124
- assert_equal true, cols_[-2].has_spatial_constraints?
124
+ assert_equal true, cols_[-2].spatial?
125
125
  assert_nil cols_[-1].geometric_type
126
- assert_equal false, cols_[-1].has_spatial_constraints?
126
+ assert_equal false, cols_[-1].spatial?
127
127
  end
128
128
 
129
129
  def test_drop_geometry_column
data/test/test_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
3
  require 'mocha/mini_test'
4
- require 'rgeo/active_record/adapter_test_helper'
4
+ require 'active_record'
5
+ require 'activerecord-postgis-adapter'
5
6
 
6
7
  begin
7
8
  require 'byebug'
@@ -26,4 +27,7 @@ class ActiveSupport::TestCase
26
27
  RGeo::Geographic.spherical_factory(srid: 4326)
27
28
  end
28
29
 
30
+ def spatial_factory_store
31
+ RGeo::ActiveRecord::SpatialFactoryStore.instance
32
+ end
29
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta4
4
+ version: 3.0.0.beta5
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-04-26 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement