geo_query 0.0.2 → 0.0.3

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: f4e3a23fa1c89f60d664ce9ee75373be8892286f
4
- data.tar.gz: a78743b2e1201b7005cea4ad1370c17f6bff65e4
3
+ metadata.gz: c1700215c27817c36bd125a589ea6bc2ab66272c
4
+ data.tar.gz: 9c692a5cef1a889827fa38833e5a20481115b0b1
5
5
  SHA512:
6
- metadata.gz: 51e64f9a53a33b0d6304ab27545c0f45aff4f0fa93548d2a040a03902772831ddb7c4e844d3d0be8f9020a04132790a19f73a97da764034faee276f2a5591f25
7
- data.tar.gz: 1a7dc59f46be27cfa3e221bf3f1737b893b65a91616d3e0d7deb8d2081a2e7e796e168e29be94d53e303d525904560eb9afcfe6bf60885df619ebe88f79abe27
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 = nil
8
+ @@point_column = :coordinates
9
9
 
10
+ # Accessors
10
11
  attr_accessor :lat, :lng
11
12
 
12
- # Validations
13
- validate :save_coordinates
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 User.near_lat_lng(st_coordinates.y, st_coordinates.x, radius) if st_coordinates
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
@@ -1,3 +1,3 @@
1
1
  module GeoQuery
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails