acts_as_geocodable 1.0.4 → 2.0.0

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.
@@ -1,10 +1,10 @@
1
1
  class Geocode < ActiveRecord::Base
2
2
  has_many :geocodings, :dependent => :destroy
3
-
3
+
4
4
  validates_uniqueness_of :query
5
5
 
6
6
  cattr_accessor :geocoder
7
-
7
+
8
8
  def distance_to(destination, units = :miles, formula = :haversine)
9
9
  if destination && destination.latitude && destination.longitude
10
10
  Graticule::Distance.const_get(formula.to_s.camelize).distance(self, destination, units)
@@ -14,42 +14,42 @@ class Geocode < ActiveRecord::Base
14
14
  def geocoded?
15
15
  !latitude.blank? && !longitude.blank?
16
16
  end
17
-
17
+
18
18
  def self.find_or_create_by_query(query)
19
19
  find_by_query(query) || create_by_query(query)
20
20
  end
21
-
21
+
22
22
  def self.create_by_query(query)
23
23
  create geocoder.locate(query).attributes.merge(:query => query)
24
24
  end
25
-
25
+
26
26
  def self.find_or_create_by_location(location)
27
27
  find_by_query(location.to_s) || create_from_location(location)
28
28
  end
29
-
29
+
30
30
  def self.create_from_location(location)
31
31
  create geocoder.locate(location).attributes.merge(:query => location.to_s)
32
32
  rescue Graticule::Error => e
33
33
  logger.warn e.message
34
34
  nil
35
35
  end
36
-
36
+
37
37
  def precision
38
- Graticule::Precision.new(self[:precision].to_s)
38
+ Graticule::Precision.new(self[:precision])
39
39
  end
40
-
40
+
41
41
  def precision=(name)
42
42
  self[:precision] = name.to_s
43
43
  end
44
-
44
+
45
45
  def geocoded
46
46
  @geocoded ||= geocodings.collect { |geocoding| geocoding.geocodable }
47
47
  end
48
-
48
+
49
49
  def on(geocodable)
50
50
  geocodings.create :geocodable => geocodable
51
51
  end
52
-
52
+
53
53
  def coordinates
54
54
  "#{longitude},#{latitude}"
55
55
  end
@@ -57,7 +57,7 @@ class Geocode < ActiveRecord::Base
57
57
  def to_s
58
58
  coordinates
59
59
  end
60
-
60
+
61
61
  # Create a Graticule::Location
62
62
  def to_location
63
63
  Graticule::Location.new(attributes.except('id', 'query'))
@@ -1,6 +1,6 @@
1
- module CollectiveIdea #:nodoc:
1
+ module ActsAsGeocodable #:nodoc:
2
2
  module RemoteLocation #:nodoc:
3
-
3
+
4
4
  # Get the remote location of the request IP using http://hostip.info
5
5
  def remote_location
6
6
  if request.remote_ip == '127.0.0.1'
@@ -13,6 +13,8 @@ module CollectiveIdea #:nodoc:
13
13
  logger.warn "An error occurred while looking up the location of '#{request.remote_ip}': #{e.message}"
14
14
  nil
15
15
  end
16
-
16
+
17
17
  end
18
- end
18
+ end
19
+
20
+ ActionController::Base.send :include, ActsAsGeocodable::RemoteLocation
@@ -0,0 +1,3 @@
1
+ module ActsAsGeocodable
2
+ VERSION = '2.0.0' unless defined?(::ActsAsGeocodable::VERSION)
3
+ end
@@ -0,0 +1,12 @@
1
+ Description:
2
+ The geocodable migration generator creates a migration which you can use to generate two tables:
3
+
4
+ geocodes - Contains the latitude and longitude coordinates, with the address they refer to.
5
+ geocodings - The polymorphic join table.
6
+
7
+
8
+ Example:
9
+ rails generate acts_as_geocodable
10
+
11
+ With 4 existing migrations, this will create an AddGeocodableTables migration in the
12
+ file db/migrate/5_add_geocodable_tables.rb
@@ -0,0 +1,28 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class ActsAsGeocodableGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ # Implement the required interface for Rails::Generators::Migration.
12
+ #
13
+ def self.next_migration_number(dirname) #:nodoc:
14
+ next_migration_number = current_migration_number(dirname) + 1
15
+ if ActiveRecord::Base.timestamped_migrations
16
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
17
+ else
18
+ "%.3d" % next_migration_number
19
+ end
20
+ end
21
+
22
+ def create_migration_file
23
+ if defined?(ActiveRecord)
24
+ migration_template 'migration.rb', 'db/migrate/add_geocodable_tables.rb'
25
+ end
26
+ end
27
+
28
+ end
@@ -1,4 +1,4 @@
1
- class <%= class_name %> < ActiveRecord::Migration
1
+ class AddGeocodableTables < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table "geocodes" do |t|
4
4
  t.column "latitude", :decimal, :precision => 15, :scale => 12
@@ -20,7 +20,7 @@ class <%= class_name %> < ActiveRecord::Migration
20
20
  add_index "geocodes", ["postal_code"], :name => "geocodes_postal_code_index"
21
21
  add_index "geocodes", ["country"], :name => "geocodes_country_index"
22
22
  add_index "geocodes", ["precision"], :name => "geocodes_precision_index"
23
-
23
+
24
24
 
25
25
  create_table "geocodings" do |t|
26
26
  t.column "geocodable_id", :integer
metadata CHANGED
@@ -3,36 +3,127 @@ name: acts_as_geocodable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
6
+ - 2
7
7
  - 0
8
- - 4
9
- version: 1.0.4
8
+ - 0
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Morrison
13
13
  - Brandon Keepers
14
+ - Brian Ryckbost
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-09-20 00:00:00 -04:00
19
+ date: 2010-10-01 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ version: 2.0.0
34
+ requirement: *id001
22
35
  name: graticule
36
+ - !ruby/object:Gem::Dependency
23
37
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
38
+ type: :development
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
25
40
  requirements:
26
41
  - - ">="
27
42
  - !ruby/object:Gem::Version
28
43
  segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ name: rails
48
+ - !ruby/object:Gem::Dependency
49
+ prerelease: false
50
+ type: :development
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 5
59
+ version: 1.2.5
60
+ requirement: *id003
61
+ name: sqlite3-ruby
62
+ - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ type: :development
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 8
29
72
  - 1
73
+ version: 2.8.1
74
+ requirement: *id004
75
+ name: mysql
76
+ - !ruby/object:Gem::Dependency
77
+ prerelease: false
78
+ type: :development
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 2
30
85
  - 0
31
86
  - 0
32
- - pre2
33
- version: 1.0.0.pre2
34
- type: :runtime
35
- version_requirements: *id001
87
+ - beta
88
+ version: 2.0.0.beta
89
+ requirement: *id005
90
+ name: rspec
91
+ - !ruby/object:Gem::Dependency
92
+ prerelease: false
93
+ type: :development
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirement: *id006
102
+ name: factory_girl
103
+ - !ruby/object:Gem::Dependency
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: &id007 !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirement: *id007
114
+ name: database_cleaner
115
+ - !ruby/object:Gem::Dependency
116
+ prerelease: false
117
+ type: :development
118
+ version_requirements: &id008 !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirement: *id008
126
+ name: ruby-debug
36
127
  description: Simple geocoding for Rails ActiveRecord models. See the README for more details.
37
128
  email: info@collectiveidea.com
38
129
  executables: []
@@ -42,36 +133,17 @@ extensions: []
42
133
  extra_rdoc_files:
43
134
  - README
44
135
  files:
45
- - .gitignore
46
- - CHANGELOG
47
- - Gemfile
48
- - Gemfile.lock
49
- - MIT-LICENSE
50
- - README
51
- - Rakefile
52
- - VERSION
53
- - about.yml
54
- - acts_as_geocodable.gemspec
55
- - generators/geocodable_migration/USAGE
56
- - generators/geocodable_migration/geocodable_migration_generator.rb
57
- - generators/geocodable_migration/templates/migration.rb
58
- - install.rb
59
- - lib/acts_as_geocodable.rb
60
136
  - lib/acts_as_geocodable/geocode.rb
61
137
  - lib/acts_as_geocodable/geocoding.rb
62
138
  - lib/acts_as_geocodable/remote_location.rb
63
- - lib/acts_as_geocodable/tasks/acts_as_geocodable_tasks.rake
64
- - rails/init.rb
65
- - test/acts_as_geocodable_test.rb
66
- - test/db/database.yml
67
- - test/db/schema.rb
68
- - test/fixtures/cities.yml
69
- - test/fixtures/geocodes.yml
70
- - test/fixtures/geocodings.yml
71
- - test/fixtures/vacations.yml
72
- - test/geocode_test.rb
73
- - test/test_helper.rb
74
- - uninstall.rb
139
+ - lib/acts_as_geocodable/version.rb
140
+ - lib/acts_as_geocodable.rb
141
+ - lib/generators/acts_as_geocodable/acts_as_geocodable_generator.rb
142
+ - lib/generators/acts_as_geocodable/templates/migration.rb
143
+ - lib/generators/acts_as_geocodable/USAGE
144
+ - CHANGELOG
145
+ - MIT-LICENSE
146
+ - README
75
147
  has_rdoc: true
76
148
  homepage: http://github.com/collectiveidea/acts_as_geocodable
77
149
  licenses: []
@@ -102,8 +174,5 @@ rubygems_version: 1.3.6
102
174
  signing_key:
103
175
  specification_version: 3
104
176
  summary: Simple geocoding for Rails ActiveRecord models
105
- test_files:
106
- - test/acts_as_geocodable_test.rb
107
- - test/db/schema.rb
108
- - test/geocode_test.rb
109
- - test/test_helper.rb
177
+ test_files: []
178
+
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- debug.log
2
- pkg
3
- rdoc
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source :rubygems
2
- gemspec
@@ -1,23 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- acts_as_geocodable (1.0.3)
5
- graticule (>= 1.0.0.pre2)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activesupport (3.0.0)
11
- graticule (1.0.0.pre2)
12
- activesupport
13
- happymapper (>= 0.3.0)
14
- happymapper (0.3.2)
15
- libxml-ruby (~> 1.1.3)
16
- libxml-ruby (1.1.4)
17
-
18
- PLATFORMS
19
- ruby
20
-
21
- DEPENDENCIES
22
- acts_as_geocodable!
23
- graticule (>= 1.0.0.pre2)
data/Rakefile DELETED
@@ -1,39 +0,0 @@
1
- require 'rake'
2
- require 'load_multi_rails_rake_tasks'
3
- require 'rake/testtask'
4
- require 'rake/rdoctask'
5
-
6
- desc 'Default: run unit tests.'
7
- task :default => :test
8
-
9
- desc 'Test the acts_as_geocodable plugin.'
10
- Rake::TestTask.new(:test) do |t|
11
- t.libs << 'lib'
12
- t.pattern = 'test/**/*_test.rb'
13
- t.verbose = true
14
- end
15
-
16
- desc 'Generate documentation for the acts_as_geocodable plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'ActsAsGeocodable'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
24
-
25
- begin
26
- require 'jeweler'
27
- Jeweler::Tasks.new do |gemspec|
28
- gemspec.name = 'acts_as_geocodable'
29
- gemspec.summary = 'Simple geocoding for Rails ActiveRecord models'
30
- gemspec.description = 'Simple geocoding for Rails ActiveRecord models. See the README for more details.'
31
- gemspec.email = 'info@collectiveidea.com'
32
- gemspec.homepage = 'http://github.com/collectiveidea/acts_as_geocodable'
33
- gemspec.authors = ['Daniel Morrison', 'Brandon Keepers']
34
- gemspec.add_dependency 'graticule', '>=1.0.0.pre2'
35
- end
36
- Jeweler::GemcutterTasks.new
37
- rescue LoadError
38
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
39
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.4
data/about.yml DELETED
@@ -1,7 +0,0 @@
1
- author:
2
- name: Brandon Keepers and Daniel Morrison, Collective Idea
3
- homepage: http://collectiveidea.com
4
- summary: A plugin to help build geo-aware applications
5
- homepage: http://opensoul.org/2007/2/13/geocoding-as-easy-as-1-2
6
- plugin: http://source.collectiveidea.com/public/rails/plugins/acts_as_geocodable
7
- license: MIT
@@ -1,75 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{acts_as_geocodable}
8
- s.version = "1.0.4"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Daniel Morrison", "Brandon Keepers"]
12
- s.date = %q{2010-09-20}
13
- s.description = %q{Simple geocoding for Rails ActiveRecord models. See the README for more details.}
14
- s.email = %q{info@collectiveidea.com}
15
- s.extra_rdoc_files = [
16
- "README"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "CHANGELOG",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "MIT-LICENSE",
24
- "README",
25
- "Rakefile",
26
- "VERSION",
27
- "about.yml",
28
- "acts_as_geocodable.gemspec",
29
- "generators/geocodable_migration/USAGE",
30
- "generators/geocodable_migration/geocodable_migration_generator.rb",
31
- "generators/geocodable_migration/templates/migration.rb",
32
- "install.rb",
33
- "lib/acts_as_geocodable.rb",
34
- "lib/acts_as_geocodable/geocode.rb",
35
- "lib/acts_as_geocodable/geocoding.rb",
36
- "lib/acts_as_geocodable/remote_location.rb",
37
- "lib/acts_as_geocodable/tasks/acts_as_geocodable_tasks.rake",
38
- "rails/init.rb",
39
- "test/acts_as_geocodable_test.rb",
40
- "test/db/database.yml",
41
- "test/db/schema.rb",
42
- "test/fixtures/cities.yml",
43
- "test/fixtures/geocodes.yml",
44
- "test/fixtures/geocodings.yml",
45
- "test/fixtures/vacations.yml",
46
- "test/geocode_test.rb",
47
- "test/test_helper.rb",
48
- "uninstall.rb"
49
- ]
50
- s.homepage = %q{http://github.com/collectiveidea/acts_as_geocodable}
51
- s.rdoc_options = ["--charset=UTF-8"]
52
- s.require_paths = ["lib"]
53
- s.rubygems_version = %q{1.3.6}
54
- s.summary = %q{Simple geocoding for Rails ActiveRecord models}
55
- s.test_files = [
56
- "test/acts_as_geocodable_test.rb",
57
- "test/db/schema.rb",
58
- "test/geocode_test.rb",
59
- "test/test_helper.rb"
60
- ]
61
-
62
- if s.respond_to? :specification_version then
63
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 3
65
-
66
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<graticule>, [">= 1.0.0.pre2"])
68
- else
69
- s.add_dependency(%q<graticule>, [">= 1.0.0.pre2"])
70
- end
71
- else
72
- s.add_dependency(%q<graticule>, [">= 1.0.0.pre2"])
73
- end
74
- end
75
-