spatial_features 2.17.3 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0a8fb7f4886f07f02b8b110f7975d91538324d6cf2c5a70b3b247dfb6719c98
4
- data.tar.gz: 15c681c5de6fccb10a515c8ff1f8a423a7c9fa1c1fded8955c2072dd76f5d4f2
3
+ metadata.gz: 41b8326969b8e58e74200ad16194cbc2e6307ba9a1e1b81cc1bc0339ead5ecd5
4
+ data.tar.gz: aeee4a1a92da17454c61f853cd6cb9917b727dbc4a5bc8095cc74d17846642f5
5
5
  SHA512:
6
- metadata.gz: 0a9224909db6dd85bf20cf9b9561e78cdc12f094423c86b0280f0e2a96e2dad9ae24030c4a4014b448f566e232b7dd37620d2a8890c411af97487a0047261346
7
- data.tar.gz: 740174a0882bc82edd053e4adf31318c6afc51860a66a3d50068e3c106cc8ac9351061f9d4990c652c5f41704815e2d5b8c8ef3d6b7aaa47525d9663f01acce4
6
+ metadata.gz: 4f793c92a7c6018655bf8cd20f77f0b7b3b106cd8922fede6090c7c3e8513df966fedddbd1f1e5614a9b14f41b47fd3658e0b8db642cd7287138b611b398735a
7
+ data.tar.gz: 4b965732b239b2fde43d1449fe31862255d03c5e84f34011707cf26ffffd3b9775646712f754863305f1375e3cb64136bef028558c40dc0f823d58db69408eed
@@ -49,8 +49,7 @@ class AbstractFeature < ActiveRecord::Base
49
49
  where(:feature_type => 'point')
50
50
  end
51
51
 
52
- def self.within_distance(lat, lng, distance_in_meters)
53
- # where("ST_DWithin(features.geog, ST_SetSRID( ST_Point( -71.104, 42.315), 4326)::geography, :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
52
+ def self.within_distance_of_point(lat, lng, distance_in_meters)
54
53
  where("ST_DWithin(features.geog, ST_Point(:lng, :lat), :distance)", :lat => lat, :lng => lng, :distance => distance_in_meters)
55
54
  end
56
55
 
@@ -73,6 +72,10 @@ class AbstractFeature < ActiveRecord::Base
73
72
  join_other_features(other).where('ST_Intersects(features.geom_lowres, other_features.geom_lowres)').uniq
74
73
  end
75
74
 
75
+ def self.within_distance(other, distance_in_meters)
76
+ join_other_features(other).where('ST_DWithin(features.geom_lowres, other_features.geom_lowres, ?)', distance_in_meters).uniq
77
+ end
78
+
76
79
  def self.invalid(column = 'geog::geometry')
77
80
  select("features.*, ST_IsValidReason(#{column}) AS invalid_geometry_message").where.not("ST_IsValid(#{column})")
78
81
  end
@@ -11,7 +11,22 @@ module SpatialFeatures
11
11
  end
12
12
 
13
13
  def updating_features?
14
- running_feature_update_jobs.exists?
14
+ case spatial_processing_status(:update_features!)
15
+ when :queued, :processing
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ def updating_features_failed?
23
+ spatial_processing_status(:update_features!) == :failure
24
+ end
25
+
26
+ def spatial_processing_status(method_name)
27
+ if has_attribute?(:spatial_processing_status_cache)
28
+ spatial_processing_status_cache[method_name.to_s]&.to_sym
29
+ end
15
30
  end
16
31
 
17
32
  def feature_update_error
@@ -27,17 +42,58 @@ module SpatialFeatures
27
42
  end
28
43
 
29
44
  def spatial_processing_jobs(suffix = nil)
30
- Delayed::Job.where('queue LIKE ?', "#{spatial_processing_queue_name}#{suffix}%")
45
+ Delayed::Job.where(:queue => "#{spatial_processing_queue_name}#{suffix}")
31
46
  end
32
47
 
33
48
  private
34
49
 
35
50
  def queue_spatial_task(method_name, *args)
36
- delay(:queue => spatial_processing_queue_name + method_name).send(method_name, *args)
51
+ Delayed::Job.enqueue SpatialProcessingJob.new(self, method_name, *args), :queue => spatial_processing_queue_name + method_name
37
52
  end
38
53
 
39
54
  def spatial_processing_queue_name
40
- "#{self.class}/#{self.id}/"
55
+ "#{model_name}/#{id}/"
56
+ end
57
+
58
+ # CLASSES
59
+
60
+ class SpatialProcessingJob
61
+ def initialize(record, method_name, *args)
62
+ @record = record
63
+ @method_name = method_name
64
+ @args = args
65
+ end
66
+
67
+ def enqueue(job)
68
+ update_cached_status(:queued)
69
+ end
70
+
71
+ def perform
72
+ update_cached_status(:processing)
73
+ @record.send(@method_name, *@args)
74
+ end
75
+
76
+ def success(job)
77
+ update_cached_status(:success)
78
+ end
79
+
80
+ def error(job)
81
+ update_cached_status(:failure)
82
+ end
83
+
84
+ def failure(job)
85
+ update_cached_status(:failure)
86
+ end
87
+
88
+ private
89
+
90
+ def update_cached_status(state)
91
+ if @record.has_attribute?(:spatial_processing_status_cache)
92
+ cache = @record.spatial_processing_status_cache || {}
93
+ cache[@method_name] = state
94
+ @record.update_column(:spatial_processing_status_cache, cache)
95
+ end
96
+ end
41
97
  end
42
98
  end
43
99
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.17.3"
2
+ VERSION = "2.18.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_features
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.3
4
+ version: 2.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
8
8
  - Nicholas Jakobsen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-04 00:00:00.000000000 Z
12
+ date: 2021-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -175,7 +175,7 @@ homepage: https://github.com/culturecode/spatial_features
175
175
  licenses:
176
176
  - MIT
177
177
  metadata: {}
178
- post_install_message:
178
+ post_install_message:
179
179
  rdoc_options: []
180
180
  require_paths:
181
181
  - lib
@@ -190,8 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.0.8
194
- signing_key:
193
+ rubygems_version: 3.0.3.1
194
+ signing_key:
195
195
  specification_version: 4
196
196
  summary: Adds spatial methods to a model.
197
197
  test_files: []