geo_query 0.0.2 → 0.0.3
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1700215c27817c36bd125a589ea6bc2ab66272c
|
4
|
+
data.tar.gz: 9c692a5cef1a889827fa38833e5a20481115b0b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5891c8c67bda15a82a7e6a52fbf01d00b01f0a6cb19704995864d70b179ccf4bf3688d08c14853fc17c64c4028d5c2fac852fa37817c0d97f75ec46fe152ee55
|
7
|
+
data.tar.gz: 2b8584c6158e9cbaba1695a4d5e7c7bcfd38838311f976e7e545dd7c7a323d2e521df292c88b413f2ee9ad3ec44e056c307d42d9ba77235e190440c50352b623
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class AddCoordinatesTo<%= name.camelize %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
add_column <%= ":#{name.underscore.pluralize.to_sym}" %>, :coordinates, :st_point, geographic: true
|
4
|
+
add_column <%= ":#{name.underscore.pluralize.to_sym}" %>, :location_updated_at, :datetime
|
4
5
|
add_index <%= ":#{name.underscore.pluralize.to_sym}" %>, :coordinates, using: :gist
|
5
6
|
end
|
6
7
|
end
|
@@ -5,12 +5,18 @@ module GeoQuery
|
|
5
5
|
included do
|
6
6
|
# Class vars
|
7
7
|
mattr_accessor :point_column
|
8
|
-
@@point_column =
|
8
|
+
@@point_column = :coordinates
|
9
9
|
|
10
|
+
# Accessors
|
10
11
|
attr_accessor :lat, :lng
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
def location_changed?
|
14
|
+
method("#{self.point_column}_changed?").call
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_location_updated_at
|
18
|
+
self.location_updated_at = Time.now
|
19
|
+
end
|
14
20
|
|
15
21
|
def save_coordinates
|
16
22
|
if lat.present? && lng.present?
|
@@ -27,7 +33,7 @@ module GeoQuery
|
|
27
33
|
|
28
34
|
def near(radius=500) #radius in metres
|
29
35
|
# x = longitude && y = latitude
|
30
|
-
return
|
36
|
+
return self.class.near_lat_lng(st_coordinates.y, st_coordinates.x, radius) if st_coordinates
|
31
37
|
self.class.none
|
32
38
|
end
|
33
39
|
|
@@ -56,6 +62,12 @@ module GeoQuery
|
|
56
62
|
# Init method
|
57
63
|
def geo_queryable(options = {})
|
58
64
|
self.base_class.point_column = options[:coordinates] || :coordinates
|
65
|
+
|
66
|
+
# Validations
|
67
|
+
validate :save_coordinates
|
68
|
+
|
69
|
+
# Callbacks
|
70
|
+
before_save :set_location_updated_at, if: :location_changed?
|
59
71
|
end
|
60
72
|
end
|
61
73
|
end
|
data/lib/geo_query/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|