option name and dependency check

stvnrlly 9 years ago
parent
commit
c1a54ec365
1 changed files with 6 additions and 4 deletions
  1. 6 4
      app/models/agents/user_location_agent.rb

+ 6 - 4
app/models/agents/user_location_agent.rb

@@ -1,12 +1,14 @@
1 1
 require 'securerandom'
2
-require 'haversine'
3 2
 
4 3
 module Agents
5 4
   class UserLocationAgent < Agent
6 5
     cannot_be_scheduled!
7 6
 
7
+    gem_dependency_check { defined?(Haversine) }
8
+
8 9
     description do
9 10
       <<-MD
11
+        #{'## Include `haversine` in your Gemfile to use this Agent!' if dependencies_missing?}
10 12
         The UserLocationAgent creates events based on WebHook POSTS that contain a `latitude` and `longitude`.  You can use the [POSTLocation](https://github.com/cantino/post_location) or [PostGPS](https://github.com/chriseidhof/PostGPS) iOS app to post your location.
11 13
 
12 14
 
@@ -14,7 +16,7 @@ module Agents
14 16
 
15 17
         If you want to only keep more precise locations, set `max_accuracy` to the upper bound, in meters. The default name for this field is `accuracy`, but you can change this by setting a value for `accuracy_field`.
16 18
 
17
-        If you want to require a certain distance traveled, set `distance` to the minimum distance, in meters. Note that GPS readings and the measurement itself aren't exact, so don't rely on this for precision filtering.
19
+        If you want to require a certain distance traveled, set `min_distance` to the minimum distance, in meters. Note that GPS readings and the measurement itself aren't exact, so don't rely on this for precision filtering.
18 20
       MD
19 21
     end
20 22
 
@@ -42,7 +44,7 @@ module Agents
42 44
       {
43 45
         'secret' => SecureRandom.hex(7),
44 46
         'max_accuracy' => '',
45
-        'distance' => '',
47
+        'min_distance' => '',
46 48
       }
47 49
     end
48 50
 
@@ -86,7 +88,7 @@ module Agents
86 88
       def far_enough?(payload)
87 89
         if memory['last_location'].present?
88 90
           travel = Haversine.distance(memory['last_location']['latitude'].to_i, memory['last_location']['longitude'].to_i, payload['latitude'].to_i, payload['longitude'].to_i).to_meters
89
-          !interpolated[:distance].present? || travel > interpolated[:distance].to_i
91
+          !interpolated[:min_distance].present? || travel > interpolated[:min_distance].to_i
90 92
         else # for the first run, before "last_location" exists
91 93
           true
92 94
         end