spatial_features 2.11.1 → 2.13.0

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
  SHA256:
3
- metadata.gz: 6c14269424ac2b30935b7f291f51080271e0932c400036bf5156223325ead8ba
4
- data.tar.gz: d715d47e9dfa87eee07e01bc71b03dc9af5ceb6415552f24663eef9a8d81bda6
3
+ metadata.gz: 88c320989e3fc2fa794540eceda94ca135c83992bdb8d95beae96cb23547253b
4
+ data.tar.gz: '08acd270a048acc72c637876d36f7d4d39b4270f47f02f8cd51d80a834348c07'
5
5
  SHA512:
6
- metadata.gz: 2b7fef2ae89493b544b46896136bddcd59afc470db34be530c2763cede9dca82082c695056583aa7665f03dab0c21f87d16429cc37d74682cf9ac984956c83cb
7
- data.tar.gz: 16bc0f99d7249a85f0c48e07f0b9dd5b02058fa307c4eea20142dedf6e695b9c035528d26b26c22dc9ec420247d36a4f8476f8e5b5a0fe865bac68650d64ecfb
6
+ metadata.gz: 4597a17999f3503d80ae00d40072c9335a9a0141fc277f952328a868b3d339cdcc236929b2bdc914f42eafe1229cde317202eb7064cab956d467257747d44152
7
+ data.tar.gz: e859fc1b6fb70a1f2ad453d5e8017799f2d7b6c9212fd04f8abaf3c4c7958e7383ebd71b23fd51accb9f5ed168955afcfa49ae20b5d0486b44f0580a907a2586
@@ -17,7 +17,8 @@ class AbstractFeature < ActiveRecord::Base
17
17
  after_save :cache_derivatives, :if => :saved_change_to_geog?
18
18
 
19
19
  def self.cache_key
20
- "#{maximum(:id)}-#{count}"
20
+ result = connection.select_one(all.select('max(id) AS max, count(*) AS count').to_sql)
21
+ "#{result['max']}-#{result['count']}"
21
22
  end
22
23
 
23
24
  def self.with_metadata(k, v)
@@ -1,8 +1,8 @@
1
1
  module PostGISTypes
2
- def initialize_type_map(mapping)
2
+ def initialize_type_map(m = type_map)
3
3
  super
4
- register_class_with_limit mapping, 'geometry', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
5
- register_class_with_limit mapping, 'geography', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
4
+ register_class_with_limit m, 'geometry', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
5
+ register_class_with_limit m, 'geography', ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::SpecializedString
6
6
  end
7
7
  end
8
8
 
@@ -36,12 +36,8 @@ module SpatialFeatures
36
36
  true
37
37
  end
38
38
 
39
- # Add methods to generate cache keys for a record or all records of this class
40
- # NOTE: features are never updated, only deleted and created, therefore we can
41
- # tell if they have changed by finding the maximum id and count instead of needing timestamps
42
39
  def features_cache_key
43
- # Do two separate queries because it is much faster for some reason
44
- "#{name}/#{features.cache_key}"
40
+ "#{name}/#{aggregate_features.cache_key}"
45
41
  end
46
42
 
47
43
  def intersecting(other, options = {})
@@ -81,6 +77,15 @@ module SpatialFeatures
81
77
  end
82
78
  end
83
79
 
80
+ def aggregate_features
81
+ type = base_class.to_s # Rails stores polymorphic foreign keys as the base class
82
+ if all == unscoped
83
+ AggregateFeature.where(:spatial_model_type => type)
84
+ else
85
+ AggregateFeature.where(:spatial_model_type => type, :spatial_model_id => all.unscope(:select))
86
+ end
87
+ end
88
+
84
89
  # Returns true if the model stores a hash of the features so we don't need to process the features if they haven't changed
85
90
  def has_spatial_features_hash?
86
91
  column_names.include? 'features_hash'
@@ -163,7 +168,7 @@ module SpatialFeatures
163
168
  end
164
169
 
165
170
  def features_cache_key
166
- "#{self.class.name}/#{self.id}-#{features.cache_key}"
171
+ "#{self.class.name}/#{id}-#{has_spatial_features_hash? ? features_hash : aggregate_feature.cache_key}"
167
172
  end
168
173
 
169
174
  def polygons?
@@ -179,7 +184,11 @@ module SpatialFeatures
179
184
  end
180
185
 
181
186
  def features?
182
- features.present?
187
+ if features.loaded?
188
+ features.present?
189
+ else
190
+ features.exists?
191
+ end
183
192
  end
184
193
 
185
194
  def intersects?(other)
@@ -67,9 +67,10 @@ module SpatialFeatures
67
67
  private
68
68
 
69
69
  def spatial_feature_imports(import_options, make_valid)
70
- import_options.collect do |data_method, importer_name|
71
- data = send(data_method)
72
- spatial_importer_from_name(importer_name).new(data, :make_valid => make_valid) if data.present?
70
+ import_options.flat_map do |data_method, importer_name|
71
+ Array.wrap(send(data_method)).map do |data|
72
+ spatial_importer_from_name(importer_name).new(data, :make_valid => make_valid) if data.present?
73
+ end
73
74
  end.compact
74
75
  end
75
76
 
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.11.1"
2
+ VERSION = "2.13.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_features
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.1
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-11 00:00:00.000000000 Z
12
+ date: 2020-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '4.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.2'
23
+ version: '6.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '4.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '6.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: delayed_job_active_record
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '3.0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rubyzip
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -220,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.7.9
223
+ rubygems_version: 3.0.3
225
224
  signing_key:
226
225
  specification_version: 4
227
226
  summary: Adds spatial methods to a model.