Pr0d1r2-geokit 1.3.2.1 → 1.3.2.2
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.
- data/Rakefile +2 -2
- data/generators/geokit_cached/geokit_cached_generator.rb +8 -0
- data/generators/geokit_cached/templates/model.rb +5 -0
- data/generators/geokit_cached/templates/model_spec.rb +15 -0
- data/lib/geokit.rb +1 -1
- data/lib/geokit/cached.rb +2 -0
- data/lib/geokit/cached/geocodable.rb +34 -0
- data/lib/geokit/cached/model.rb +58 -0
- data/lib/geokit/geocoders/cached_multi_geocoder.rb +19 -0
- metadata +10 -3
data/Rakefile
CHANGED
|
@@ -14,8 +14,8 @@ end
|
|
|
14
14
|
|
|
15
15
|
project=Hoe.new('geokit', Geokit::VERSION) do |p|
|
|
16
16
|
#p.rubyforge_name = 'geokit' # if different than lowercase project name
|
|
17
|
-
p.developer('Andre Lewis', 'andre@earthcode.com')
|
|
18
|
-
p.summary="Geokit provides geocoding and distance calculation in an easy-to-use API"
|
|
17
|
+
p.developer('Andre Lewis', 'andre@earthcode.com', 'pr0d1r2@gmail.com')
|
|
18
|
+
p.summary="Geokit provides geocoding and distance calculation in an easy-to-use API with caching in MultiGeocoder"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe <%= class_name %> do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@valid_attributes = {
|
|
6
|
+
<% attributes.each_with_index do |attribute, attribute_index| -%>
|
|
7
|
+
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
|
|
8
|
+
<% end -%>
|
|
9
|
+
}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should create a new instance given valid attributes" do
|
|
13
|
+
<%= class_name %>.create!(@valid_attributes)
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/geokit.rb
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Geokit
|
|
2
|
+
module Cached
|
|
3
|
+
module Geocodable
|
|
4
|
+
|
|
5
|
+
def self.included(base)
|
|
6
|
+
base.class_eval do
|
|
7
|
+
attr_accessor :provider
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def geocoder
|
|
12
|
+
if cache_locations?
|
|
13
|
+
Geokit::Geocoders::CachedMultiGeocoder
|
|
14
|
+
else
|
|
15
|
+
Geokit::Geocoders::MultiGeocoder
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def geocode_address_cached
|
|
20
|
+
@geocoder.geocode(complete_address)
|
|
21
|
+
self.lat, self.lng, self.provider = @geo.lat, @geo.lng, @geo.provider if @geo.success
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cache_location!
|
|
25
|
+
cached_location.cache!(:lat => lat, :lng => lng, :provider => provider) if cache_locations?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def cache_locations?
|
|
29
|
+
self.class::CACHE_LOCATIONS
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Geokit
|
|
2
|
+
module Cached
|
|
3
|
+
module Model
|
|
4
|
+
|
|
5
|
+
def cache!(attributes)
|
|
6
|
+
self.attributes = attributes
|
|
7
|
+
save if new_record? || changed?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def update!
|
|
11
|
+
if !by_google? && geo.success
|
|
12
|
+
self.lat, self.lng, self.provider = geo.lat, geo.lng, geo.provider
|
|
13
|
+
save if changed?
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update_and_return!
|
|
18
|
+
update!
|
|
19
|
+
geoloc
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def geo
|
|
23
|
+
@geo ||= Geokit::Geocoders::MultiGeocoder.geocode(address)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fake_geoloc
|
|
27
|
+
geoloc = Geokit::GeoLoc.new
|
|
28
|
+
geoloc.lat, geoloc.lng, geoloc.provider, geoloc.success = lat, lng, provider, true
|
|
29
|
+
geoloc
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def successful_geoloc
|
|
33
|
+
geo if geocoding_occured? && geo.success
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def geoloc
|
|
37
|
+
successful_geoloc || fake_geoloc
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def by_google?
|
|
41
|
+
provider == 'google'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def changed_to_google?
|
|
45
|
+
by_google? && provider_changed?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def changed?
|
|
49
|
+
lat_changed? || lng_changed? || changed_to_google?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def geocoding_occured?
|
|
53
|
+
!@geo.nil?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Geokit
|
|
2
|
+
module Geocoders
|
|
3
|
+
class CachedMultiGeocoder
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
def cached_location(location)
|
|
8
|
+
CachedLocation.find_by_address(location) || CachedLocation.new(:address => location)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def geocode(location)
|
|
12
|
+
cached_location(location).update_and_return!
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: Pr0d1r2-geokit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.2.
|
|
4
|
+
version: 1.3.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Andre Lewis and Bill Eisenhauer
|
|
7
|
+
- Andre Lewis and Bill Eisenhauer and Pr0d1r2 (Marcin Nowicki)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
@@ -15,7 +15,7 @@ dependencies: []
|
|
|
15
15
|
|
|
16
16
|
description: Geokit Gem
|
|
17
17
|
email:
|
|
18
|
-
- andre@earthcode.com / bill_eisenhauer@yahoo.com
|
|
18
|
+
- andre@earthcode.com / bill_eisenhauer@yahoo.com / pr0d1r2@gmail.com
|
|
19
19
|
executables: []
|
|
20
20
|
|
|
21
21
|
extensions: []
|
|
@@ -39,6 +39,13 @@ files:
|
|
|
39
39
|
- test/test_multi_geocoder.rb
|
|
40
40
|
- test/test_us_geocoder.rb
|
|
41
41
|
- test/test_yahoo_geocoder.rb
|
|
42
|
+
- generators/geokit_cached/geokit_cached_generator.rb
|
|
43
|
+
- generators/geokit_cached/templates/model.rb
|
|
44
|
+
- generators/geokit_cached/templates/model_spec.rb
|
|
45
|
+
- lib/geokit/cached.rb
|
|
46
|
+
- lib/geokit/cached/geocodable.rb
|
|
47
|
+
- lib/geokit/cached/model.rb
|
|
48
|
+
- lib/geokit/geocoders/cached_multi_geocoder.rb
|
|
42
49
|
has_rdoc: true
|
|
43
50
|
homepage: http://geokit.rubyforge.org
|
|
44
51
|
post_install_message:
|