geo_query 0.0.3 → 0.0.4

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: c1700215c27817c36bd125a589ea6bc2ab66272c
4
- data.tar.gz: 9c692a5cef1a889827fa38833e5a20481115b0b1
3
+ metadata.gz: 6b42919fce03a439c5b52569ce78142cdb180140
4
+ data.tar.gz: 1d2bbc101cd898b836ceda5f428e7ea0f7b3baf5
5
5
  SHA512:
6
- metadata.gz: 5891c8c67bda15a82a7e6a52fbf01d00b01f0a6cb19704995864d70b179ccf4bf3688d08c14853fc17c64c4028d5c2fac852fa37817c0d97f75ec46fe152ee55
7
- data.tar.gz: 2b8584c6158e9cbaba1695a4d5e7c7bcfd38838311f976e7e545dd7c7a323d2e521df292c88b413f2ee9ad3ec44e056c307d42d9ba77235e190440c50352b623
6
+ metadata.gz: 3b9c13306bc6eb17e946bd613d7bba06def653289c99d2f52f0b99bee465692a40cc49d6ff49bff10b5d51ada7e60fd5c3e9592986fd65e8b0f1633aba15fcbb
7
+ data.tar.gz: d60f6037fe67d02b8b8f81553da38fbf70622003fbe1b6abf8ea32da4689b24f4754a1fa4b32198a8d18d5bc511e6bbd5361487f3b5cb13c0145d65a537191be
@@ -7,10 +7,13 @@ module GeoQuery
7
7
  mattr_accessor :point_column
8
8
  @@point_column = :coordinates
9
9
 
10
+ mattr_accessor :track_updates
11
+ @@track_updates = false
12
+
10
13
  # Accessors
11
- attr_accessor :lat, :lng
14
+ attr_accessor :lat, :lon
12
15
 
13
- def location_changed?
16
+ def location_did_change?
14
17
  method("#{self.point_column}_changed?").call
15
18
  end
16
19
 
@@ -19,9 +22,9 @@ module GeoQuery
19
22
  end
20
23
 
21
24
  def save_coordinates
22
- if lat.present? && lng.present?
23
- self.coordinates = "POINT(#{lng} #{lat})"
24
- elsif (lat.present? && lng.blank?) || (lng.present? && lat.blank?)
25
+ if lat.present? && lon.present?
26
+ self.coordinates = "POINT(#{lon} #{lat})"
27
+ elsif (lat.present? && lon.blank?) || (lon.present? && lat.blank?)
25
28
  errors.add(self.point_column, "requires both latitude and longitude")
26
29
  end
27
30
  end
@@ -33,7 +36,7 @@ module GeoQuery
33
36
 
34
37
  def near(radius=500) #radius in metres
35
38
  # x = longitude && y = latitude
36
- return self.class.near_lat_lng(st_coordinates.y, st_coordinates.x, radius) if st_coordinates
39
+ return self.class.near_lat_lon(st_coordinates.y, st_coordinates.x, radius) if st_coordinates
37
40
  self.class.none
38
41
  end
39
42
 
@@ -43,17 +46,17 @@ module GeoQuery
43
46
 
44
47
  # Class methods
45
48
  ## Returns other objects within the given radius of a point
46
- def self.near_lat_lng(lat, lng, radius=500) #radius in metres
47
- select("#{self.table_name}.*, ST_Distance(#{self.point_column}, ST_GeographyFromText('POINT(#{lng} #{lat})')) AS distance")
48
- .where("ST_DWithin(#{self.point_column} , ST_GeographyFromText('POINT(#{lng} #{lat})'), #{radius})")
49
+ def self.near_lat_lon(lat, lon, radius=500) #radius in metres
50
+ select("#{self.table_name}.*, ST_Distance(#{self.point_column}, ST_GeographyFromText('POINT(#{lon} #{lat})')) AS distance")
51
+ .where("ST_DWithin(#{self.table_name}.#{self.point_column} , ST_GeographyFromText('POINT(#{lon} #{lat})'), #{radius})")
49
52
  .order("distance ASC")
50
53
  end
51
54
 
52
55
  ## Returns all objects within a bounding box
53
- def self.within_bounding_box(min_lat, min_lng, max_lat, max_lng)
56
+ def self.within_bounding_box(min_lat, min_lon, max_lat, max_lon)
54
57
  select("#{self.table_name}.*").
55
- where("#{self.point_column} && ST_MakeEnvelope(?, ?, ?, ?, 4326)",
56
- min_lng, min_lat, max_lng, max_lat)
58
+ where("#{self.table_name}.#{self.point_column} && ST_MakeEnvelope(?, ?, ?, ?, 4326)",
59
+ min_lon, min_lat, max_lon, max_lat)
57
60
  end
58
61
 
59
62
  end
@@ -61,13 +64,17 @@ module GeoQuery
61
64
  module ClassMethods
62
65
  # Init method
63
66
  def geo_queryable(options = {})
64
- self.base_class.point_column = options[:coordinates] || :coordinates
67
+ self.base_class.point_column = options[:column] || :coordinates
68
+ self.base_class.track_updates = options[:track_updates] || false
65
69
 
66
70
  # Validations
67
71
  validate :save_coordinates
68
72
 
69
- # Callbacks
70
- before_save :set_location_updated_at, if: :location_changed?
73
+ if self.base_class.track_updates
74
+
75
+ # Callbacks
76
+ before_save :set_location_updated_at, if: :location_did_change?
77
+ end
71
78
  end
72
79
  end
73
80
  end
@@ -1,3 +1,3 @@
1
1
  module GeoQuery
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
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-27 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0.beta5
33
+ version: 3.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0.beta5
40
+ version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement