Pr0d1r2-geokit-cached 0.1.1

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/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.1.0 2009-06-01
2
+
3
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,23 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/geokit-cached.rb
7
+ lib/geokit-cached/geocodable.rb
8
+ lib/geokit-cached/model.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/geokit-cached_spec.rb
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ tasks/rspec.rake
16
+ generators/geokit_cached
17
+ generators/geokit_cached/geokit_cached_generator.rb
18
+ generators//geokit_cached/templates
19
+ generators/geokit_cached/templates/model.rb
20
+ generators/geokit_cached/templates/model_spec.rb
21
+ generators/geokit_cached/geokit_cached_generator.rb
22
+ generators/geokit_cached/templates/model.rb
23
+ generators/geokit_cached/templates/model_spec.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+
2
+ For more information on geokit-cached, see http://geokit-cached.rubyforge.org
3
+
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ = geokit-cached
2
+
3
+ * http://github.com/Pr0d1r2/geokit-cached
4
+
5
+ == DESCRIPTION:
6
+
7
+ Caching support to Geokit. It prevents from exceeding limit of queres to geocoding services.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Store cached locations in database.
12
+ * Use ActiveRecord
13
+ * only address, lat, lng and provider are stored.
14
+ * FIX: convince ./script/generate geokit_cached to create complete model
15
+
16
+ == SYNOPSIS:
17
+
18
+ ./script/generate geokit_cached
19
+
20
+ # table which locations are stored (./script/generate geokit-cached)
21
+ class CachedLocation < ActiveRecord::Base
22
+ include Geokit::Cached::Model
23
+ end
24
+
25
+ # table for which locations will be cached
26
+ class Profile < ActiveRecord::Base
27
+ include Geokit::Cached::Geocodable
28
+ before_save :geocode_address_cached
29
+ cache_locations true
30
+ default_country 'Poland'
31
+ end
32
+
33
+ == REQUIREMENTS:
34
+
35
+ * geokit gem
36
+ * rails
37
+ * rspec
38
+ * rspec-rails
39
+
40
+ == INSTALL:
41
+
42
+ * sudo gem install geokit-cached
43
+
44
+ == LICENSE:
45
+
46
+ (The MIT License)
47
+
48
+ Copyright (c) 2009 FIXME full name
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of this software and associated documentation files (the
52
+ 'Software'), to deal in the Software without restriction, including
53
+ without limitation the rights to use, copy, modify, merge, publish,
54
+ distribute, sublicense, and/or sell copies of the Software, and to
55
+ permit persons to whom the Software is furnished to do so, subject to
56
+ the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be
59
+ included in all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
62
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
64
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
65
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
66
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
67
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ %w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
3
+ require File.dirname(__FILE__) + '/lib/geokit-cached'
4
+
5
+ # Generate all the Rake tasks
6
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
+ $hoe = Hoe.new('geokit-cached', Geokit::Cached::VERSION) do |p|
8
+ p.developer('Marcin Nowicki', 'pr0d1r2@gmail.com')
9
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
11
+ p.rubyforge_name = p.name # TODO this is default value
12
+ p.extra_deps = [
13
+ ['rspec-rails','>= 1.1.12'],
14
+ ['rspec','>= 1.1.12'],
15
+ ['geokit','>= 1.2.6'],
16
+ ]
17
+ p.extra_dev_deps = [
18
+ ['newgem', ">= #{::Newgem::VERSION}"]
19
+ ]
20
+
21
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
22
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
23
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
24
+ p.rsync_args = '-av --delete --ignore-errors'
25
+ end
26
+
27
+ require 'newgem/tasks' # load /tasks/*.rake
28
+ Dir['tasks/**/*.rake'].each { |t| load t }
29
+
30
+ # TODO - want other tests/tasks run by default? Add them to the list
31
+ # task :default => [:spec, :features]
@@ -0,0 +1,8 @@
1
+ class GeokitCachedGenerator < RspecModelGenerator
2
+
3
+ def initialize(runtime_args, runtime_options = {})
4
+ runtime_args = ['CachedLocation', 'address:string', 'provider:string', 'lng:float', 'lat:float']
5
+ super
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+
3
+ include Geokit::Cached::Model
4
+
5
+ end
@@ -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
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'geokit-cached/geocodable'
5
+ require 'geokit-cached/model'
6
+
7
+ module Geokit
8
+ module Cached
9
+ VERSION = '0.1.1'
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+ module Geokit
2
+ module Cached
3
+ module Geocodable
4
+
5
+ @@cache_locations = true
6
+ @@default_country = 'Poland'
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ base.class_eval do
11
+ attr_accessor :provider
12
+ end
13
+ end
14
+
15
+ def selected_country
16
+ country || @@default_country
17
+ end
18
+
19
+ def complete_address
20
+ "%s, %s" % [address, selected_country]
21
+ end
22
+
23
+ def cached_location_for_address
24
+ CachedLocation.find_by_address(complete_address)
25
+ end
26
+
27
+ def cached_location_for_address?
28
+ !cached_location_for_address.nil?
29
+ end
30
+
31
+ def cached_location
32
+ cached_location_for_address || CachedLocation.new(:address => complete_address)
33
+ end
34
+
35
+ def cache_locations?
36
+ @@cache_locations
37
+ end
38
+
39
+ def cache_location!
40
+ cached_location.cache!(:lat => lat, :lng => lng, :provider => provider) if cache_locations?
41
+ end
42
+
43
+ def geocode_address_cached
44
+ if cached_location_for_address?
45
+ self.lat, self.lng, self.provider = cached_location.lat, cached_location.lng, cached_location.provider
46
+ else
47
+ @geo = Geokit::Geocoders::MultiGeocoder.geocode(complete_address)
48
+ if @geo.success
49
+ self.lat, self.lng, self.provider = @geo.lat, @geo.lng, @geo.provider
50
+ cache_location! if cache_locations?
51
+ end
52
+ end
53
+ end
54
+
55
+ module ClassMethods
56
+ def cache_locations(value)
57
+ @@cache_locations = value
58
+ end
59
+
60
+ def default_country(value)
61
+ @@default_country = value
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,24 @@
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 by_google?
11
+ provider == 'google'
12
+ end
13
+
14
+ def changed_to_google?
15
+ by_google? && provider_changed?
16
+ end
17
+
18
+ def changed?
19
+ lat_changed? || lng_changed? || changed_to_google?
20
+ end
21
+
22
+ end
23
+ end
24
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/geokit-cached.rb'}"
9
+ puts "Loading geokit-cached gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'geokit-cached'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Pr0d1r2-geokit-cached
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Nowicki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec-rails
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.12
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.12
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: geokit
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.6
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: newgem
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.1
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ version:
65
+ description: Caching support to Geokit. It prevents from exceeding limit of queres to geocoding services.
66
+ email:
67
+ - pr0d1r2@gmail.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - PostInstall.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - PostInstall.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - lib/geokit-cached.rb
84
+ - lib/geokit-cached/geocodable.rb
85
+ - lib/geokit-cached/model.rb
86
+ - script/console
87
+ - script/destroy
88
+ - script/generate
89
+ - spec/geokit-cached_spec.rb
90
+ - spec/spec.opts
91
+ - spec/spec_helper.rb
92
+ - tasks/rspec.rake
93
+ - generators/geokit_cached
94
+ - generators/geokit_cached/geokit_cached_generator.rb
95
+ - generators/geokit_cached/templates
96
+ - generators/geokit_cached/templates/model.rb
97
+ - generators/geokit_cached/templates/model_spec.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/Pr0d1r2/geokit-cached
100
+ post_install_message: PostInstall.txt
101
+ rdoc_options:
102
+ - --main
103
+ - README.rdoc
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ version:
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ version:
118
+ requirements: []
119
+
120
+ rubyforge_project: geokit-cached
121
+ rubygems_version: 1.2.0
122
+ signing_key:
123
+ specification_version: 2
124
+ summary: Caching support to Geokit
125
+ test_files: []
126
+