Pr0d1r2-geokit 1.3.2.5 → 1.3.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/geokit.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Geokit
2
- VERSION = '1.3.2.5'
2
+ VERSION = '1.3.2.6'
3
3
  # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
4
4
  @@default_units = :miles
5
5
  @@default_formula = :sphere
@@ -16,19 +16,27 @@ module Geokit
16
16
  end
17
17
  end
18
18
 
19
+ def complete_address
20
+ "%s, %s" % [address, country]
21
+ end
22
+
19
23
  def geocode_address_cached
20
24
  @geo = multi_geocoder.geocode(complete_address)
21
25
  self.lat, self.lng, self.provider = @geo.lat, @geo.lng, @geo.provider if @geo.success
22
26
  end
23
27
 
24
- def cache_location!
25
- cached_location.cache!(:lat => lat, :lng => lng, :provider => provider) if cache_locations?
26
- end
27
-
28
28
  def cache_locations?
29
29
  self.class::CACHE_LOCATIONS
30
30
  end
31
31
 
32
+ def cached_location
33
+ CachedLocation.find_by_address(complete_address) || CachedLocation.new(:address => complete_address)
34
+ end
35
+
36
+ def cache_location!
37
+ cached_location.cache!(:lat => lat, :lng => lng, :provider => provider) if cache_locations?
38
+ end
39
+
32
40
  end
33
41
  end
34
42
  end
@@ -2,6 +2,12 @@ module Geokit
2
2
  module Cached
3
3
  module Model
4
4
 
5
+ def self.included(base)
6
+ base.class_eval do
7
+ validates_presence_of :address
8
+ end
9
+ end
10
+
5
11
  def cache!(attributes)
6
12
  self.attributes = attributes
7
13
  save if new_record? || changed?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Pr0d1r2-geokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2.5
4
+ version: 1.3.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Lewis and Bill Eisenhauer and Pr0d1r2 (Marcin Nowicki)