acts_as_geocodable 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/.travis.yml +36 -0
- data/CHANGELOG.md +68 -0
- data/Gemfile +12 -0
- data/{MIT-LICENSE → LICENSE.txt} +5 -3
- data/README.md +160 -0
- data/Rakefile +6 -0
- data/acts_as_geocodable.gemspec +27 -0
- data/gemfiles/rails30.gemfile +15 -0
- data/gemfiles/rails31.gemfile +14 -0
- data/gemfiles/rails32.gemfile +14 -0
- data/gemfiles/rails40.gemfile +14 -0
- data/gemfiles/rails41.gemfile +14 -0
- data/lib/acts_as_geocodable.rb +104 -105
- data/lib/acts_as_geocodable/geocode.rb +8 -8
- data/lib/acts_as_geocodable/geocoding.rb +3 -3
- data/lib/acts_as_geocodable/remote_location.rb +8 -8
- data/lib/acts_as_geocodable/version.rb +1 -1
- data/lib/generators/acts_as_geocodable/USAGE +1 -1
- data/lib/generators/acts_as_geocodable/acts_as_geocodable_generator.rb +5 -6
- data/lib/generators/acts_as_geocodable/templates/migration.rb +15 -15
- data/spec/acts_as_geocodable_generator_spec.rb +23 -0
- data/spec/acts_as_geocodable_spec.rb +318 -0
- data/spec/db/database.yml.example +8 -0
- data/spec/db/schema.rb +59 -0
- data/spec/geocode_spec.rb +84 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/factories.rb +110 -0
- data/spec/support/geocoder.rb +52 -0
- data/spec/support/models.rb +35 -0
- metadata +122 -67
- data/CHANGELOG +0 -18
- data/README.textile +0 -129
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0b58d5067d7f3dcc1cbd08812d2179df7b79350
|
4
|
+
data.tar.gz: 8edaba8e9179c7dda22299014b3ba262ee536799
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 670f4a54a7610a75ff974a999d53d2ca18a4dc15d55f05ae99afd24b3b74d1f1f44215ba6f63fa8027d90e8eef0fc6cda600e2beda554c5de399285a67c99d1c
|
7
|
+
data.tar.gz: 5d7c284d63e1ea0882b1456765d5b18815899a5b97e2bc5cf1d94f856fbe0bb630d48d644317d48ad029a354544e8f2e4f6e8fec459121da83cda52842a99b11
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.a
|
2
|
+
*.bundle
|
3
|
+
*.gem
|
4
|
+
*.o
|
5
|
+
*.rbc
|
6
|
+
*.so
|
7
|
+
.bundle
|
8
|
+
.config
|
9
|
+
.yardoc
|
10
|
+
Gemfile.lock
|
11
|
+
InstalledFiles
|
12
|
+
_yardoc
|
13
|
+
coverage
|
14
|
+
debug.log
|
15
|
+
doc/
|
16
|
+
gemfiles/*.lock
|
17
|
+
lib/bundler/man
|
18
|
+
mkmf.log
|
19
|
+
pkg
|
20
|
+
rdoc
|
21
|
+
spec/db/database.yml
|
22
|
+
spec/reports
|
23
|
+
test/tmp
|
24
|
+
test/version_tmp
|
25
|
+
tmp
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
language: ruby
|
2
|
+
branches:
|
3
|
+
only:
|
4
|
+
- master
|
5
|
+
rvm:
|
6
|
+
- 1.9.3
|
7
|
+
- "2.0"
|
8
|
+
- "2.1"
|
9
|
+
- ruby-head
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/rails30.gemfile
|
12
|
+
- gemfiles/rails31.gemfile
|
13
|
+
- gemfiles/rails32.gemfile
|
14
|
+
- gemfiles/rails40.gemfile
|
15
|
+
- gemfiles/rails41.gemfile
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
secure: | # CODECLIMATE_REPO_TOKEN
|
19
|
+
TvVATBVNhppiCRYfAAzmIfppeftAl6NchlJlPdNJGkeyoplftnr6GPFJHO1u
|
20
|
+
Yj0nznR+8OsKU6Kv7u8n+S9c3PRIBY9pw13GEWqrB9Pa5U9QK3h1xGA/ioKn
|
21
|
+
eb74qe+vux/blTpZ1/mHrIKGBX03RaW8fdvePeSXik3u5uKZzVg=
|
22
|
+
matrix:
|
23
|
+
- DB=mysql
|
24
|
+
- DB=postgresql
|
25
|
+
matrix:
|
26
|
+
allow_failures:
|
27
|
+
- rvm: ruby-head
|
28
|
+
before_script:
|
29
|
+
- cp spec/db/database.yml{.example,}
|
30
|
+
- mysql -e 'create database acts_as_geocodable_test;'
|
31
|
+
- createdb acts_as_geocodable_test -U postgres
|
32
|
+
notifications:
|
33
|
+
webhooks:
|
34
|
+
urls:
|
35
|
+
- http://buildlight.collectiveidea.com/
|
36
|
+
on_start: true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
## 2.1.0 / 2014-06-10
|
2
|
+
|
3
|
+
* [ENHANCEMENT] Whitelist attributes for mass assignment
|
4
|
+
* [FEATURE] Add Rails 4 compatibility
|
5
|
+
* [ENHANCEMENT] Add runtime dependency on Rails
|
6
|
+
* [ENHANCEMENT] Adhere to GitHub's Ruby Style Guide
|
7
|
+
* [BUGFIX] Fix dependency requirement sequence
|
8
|
+
|
9
|
+
## 2.0.3 / 2011-11-15
|
10
|
+
|
11
|
+
* [BUGFIX] Fix class attribute management across Rails versions
|
12
|
+
|
13
|
+
## 2.0.2 / 2011-01-06
|
14
|
+
|
15
|
+
* [PERFORMANCE] Optimize query clause ordering
|
16
|
+
|
17
|
+
## 2.0.1 / 2010-11-15
|
18
|
+
|
19
|
+
* [BUGFIX] Explicitly typecast PostgreSQL types
|
20
|
+
* [BUGFIX] Fix bug where origin/target locations are equal
|
21
|
+
|
22
|
+
## 2.0.0 / 2010-10-01
|
23
|
+
|
24
|
+
* [ENHANCEMENT] Rewrite for Rails 3
|
25
|
+
* [FEATURE] Implement new Rails 3/ARel finder syntax
|
26
|
+
* [FEATURE] Double Rainbows 🌈🌈
|
27
|
+
|
28
|
+
## 1.0.4 / 2010-09-20
|
29
|
+
|
30
|
+
* [ENHANCEMENT] Use `tap` rather than `returning`
|
31
|
+
|
32
|
+
## 1.0.3 / 2010-03-17
|
33
|
+
|
34
|
+
* [ENHANCEMENT] Add the `graticule` runtime gem dependency
|
35
|
+
|
36
|
+
## 1.0.2 / 2010-02-04
|
37
|
+
|
38
|
+
* [FEATURE] Allow `validates_as_geocodable` to accept a block
|
39
|
+
|
40
|
+
## 1.0.1 / 2009-12-16
|
41
|
+
|
42
|
+
* [FEATURE] Allow `validates_as_geocodable` to accept a `:precision` option
|
43
|
+
|
44
|
+
## 1.0.0 / 2009-10-21
|
45
|
+
|
46
|
+
* [FEATURE] Add an `after_geocoding` callback
|
47
|
+
* [PERFORMANCE] Add appropriate database indexes
|
48
|
+
|
49
|
+
## 0.2.1 / 2008-08-08
|
50
|
+
|
51
|
+
* [FEATURE] Make results will_paginate-compatible
|
52
|
+
|
53
|
+
## 0.2.0 / 2007-10-27
|
54
|
+
|
55
|
+
* [FEATURE] Add `validates_as_geocodable` ([Mark Van Holstyn](https://github.com/mvanholstyn))
|
56
|
+
* [FEATURE] Allow address mapping to be a single field ([Mark Van Holstyn](https://github.com/mvanholstyn))
|
57
|
+
|
58
|
+
## 0.1.0 / 2007-03-20
|
59
|
+
|
60
|
+
* [FEATURE] Add `remote_location` to get a user's location based on his or her `remote_ip`
|
61
|
+
* [ENHANCEMENT] Rename `:city` to `:locality` in address mapping to be consistent with Graticule 0.2
|
62
|
+
|
63
|
+
Create a migration with:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
rename_column :geocodes, :city, :locality
|
67
|
+
```
|
68
|
+
* [ENHANCEMENT] Replace `#full_address` with `#to_location`
|
data/Gemfile
ADDED
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
@@ -1,10 +1,12 @@
|
|
1
|
-
Copyright (c) 2006 Daniel Morrison, Collective Idea
|
1
|
+
Copyright (c) 2006 Daniel Morrison, Collective Idea
|
2
2
|
http://collectiveidea.com
|
3
3
|
|
4
|
-
Testing code was heavily influenced by Rick Olson.
|
4
|
+
Testing code was heavily influenced by Rick Olson. Thanks, Rick!
|
5
5
|
Testing Portions Copyright (c) 2006 Rick Olson
|
6
6
|
http://techno-weenie.net
|
7
7
|
|
8
|
+
MIT License
|
9
|
+
|
8
10
|
Permission is hereby granted, free of charge, to any person obtaining
|
9
11
|
a copy of this software and associated documentation files (the
|
10
12
|
"Software"), to deal in the Software without restriction, including
|
@@ -22,4 +24,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
24
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
25
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
26
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# acts_as_geocodable
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/acts_as_geocodable.svg?style=flat)](http://rubygems.org/gems/acts_as_geocodable)
|
4
|
+
[![Build Status](https://img.shields.io/travis/collectiveidea/acts_as_geocodable/master.svg?style=flat)](https://travis-ci.org/collectiveidea/acts_as_geocodable)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/collectiveidea/acts_as_geocodable.svg?style=flat)](https://codeclimate.com/github/collectiveidea/acts_as_geocodable)
|
6
|
+
[![Code Coverage](http://img.shields.io/codeclimate/coverage/github/collectiveidea/acts_as_geocodable.svg?style=flat)](https://codeclimate.com/github/collectiveidea/acts_as_geocodable)
|
7
|
+
[![Dependency Status](https://img.shields.io/gemnasium/collectiveidea/acts_as_geocodable.svg?style=flat)](https://gemnasium.com/collectiveidea/acts_as_geocodable)
|
8
|
+
|
9
|
+
acts_as_geocodable helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.
|
10
|
+
|
11
|
+
**Beginning with version 2, we require Rails 3. Use one of the 1.0.x tags to work with Rails 2.3.**
|
12
|
+
|
13
|
+
We've adopted the ARel style syntax for finding records.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
event = Event.create(
|
19
|
+
street: "777 NE Martin Luther King, Jr. Blvd.",
|
20
|
+
locality: "Portland",
|
21
|
+
region: "Oregon",
|
22
|
+
postal_code: 97232
|
23
|
+
)
|
24
|
+
|
25
|
+
event.geocode.latitude # => 45.529100000000
|
26
|
+
event.geocode.longitude # => -122.644200000000
|
27
|
+
|
28
|
+
event.distance_to("49423") # => 1807.66560483205
|
29
|
+
|
30
|
+
Event.origin("97232", within: 50)
|
31
|
+
|
32
|
+
Event.origin("Portland, OR").nearest
|
33
|
+
```
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
|
37
|
+
Install as a gem
|
38
|
+
|
39
|
+
```
|
40
|
+
gem install acts_as_geocodable
|
41
|
+
```
|
42
|
+
|
43
|
+
or add it to your Gemfile
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem "acts_as_geocodable"
|
47
|
+
```
|
48
|
+
|
49
|
+
[Graticule](http://github.com/collectiveidea/graticule) is used for all the heavy lifting and will be installed too.
|
50
|
+
|
51
|
+
## Upgrading
|
52
|
+
|
53
|
+
Before October 2008, precision wasn't included in the `Geocode` model. Make sure you add a string precision column to your geocode table if you're upgrading from an older version, and update Graticule.
|
54
|
+
|
55
|
+
Also, if you're upgrading from a previous version of this plugin, note that `:city` has been renamed to `:locality` to be consistent with Graticule 0.2. Create a migration that has:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
rename_column :geocodes, :city, :locality
|
59
|
+
```
|
60
|
+
|
61
|
+
Also remember to change your mapping in your geocodable classes to use the `:locality` key instead of `:city`:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class Event < ActiveRecord::Base
|
65
|
+
acts_as_geocodable address: { street: :address1, locality: :city, region: :state, postal_code: :zip }
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
## Configuration
|
70
|
+
|
71
|
+
Create the required tables
|
72
|
+
|
73
|
+
```
|
74
|
+
rails generate acts_as_geocodable
|
75
|
+
rake db:migrate
|
76
|
+
```
|
77
|
+
|
78
|
+
Set the default geocoder in your environment.rb file.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Geocode.geocoder = Graticule.service(:yahoo).new("your_api_key")
|
82
|
+
```
|
83
|
+
|
84
|
+
Then, in each model you want to make geocodable, add `acts_as_geocodable`.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Event < ActiveRecord::Base
|
88
|
+
acts_as_geocodable
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
The only requirement is that your model must have address fields. By default, acts_as_geocodable looks for attributes called _street_, _locality_, _region_, _postal_code_, and _country_. To change these, you can provide a mapping in the `:address` option:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class Event < ActiveRecord::Base
|
96
|
+
acts_as_geocodable address: { street: :address1, locality: :city, region: :state, postal_code: :zip }
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
If that doesn't meet your needs, simply override the default `to_location` method in your model, and return a `Graticule::Location` with those attributes set.
|
101
|
+
|
102
|
+
acts_as_geocodable can also update your address fields with the data returned from the geocoding service:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
class Event < ActiveRecord::Base
|
106
|
+
acts_as_geocodable normalize_address: true
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## IP-based Geocoding
|
111
|
+
|
112
|
+
acts_as_geocodable adds a `remote_location` method in your controllers that uses http://hostip.info to guess remote users location based on their IP address.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
def index
|
116
|
+
@nearest = Store.origin(remote_location).nearest if remote_location
|
117
|
+
@stores = Store.all
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
Keep in mind that IP-based geocoding is not always accurate, and often will not return any results.
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
|
126
|
+
|
127
|
+
Here are some ways **you** can contribute:
|
128
|
+
|
129
|
+
* using alpha, beta, and prerelease versions
|
130
|
+
* reporting bugs
|
131
|
+
* suggesting new features
|
132
|
+
* writing or editing documentation
|
133
|
+
* writing specifications
|
134
|
+
* writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
135
|
+
* refactoring code
|
136
|
+
* closing [issues](https://github.com/collectiveidea/acts_as_geocodable/issues/)
|
137
|
+
* reviewing patches
|
138
|
+
|
139
|
+
## Submitting an Issue
|
140
|
+
|
141
|
+
We use the [GitHub issue tracker](https://github.com/collectiveidea/acts_as_geocodable/issues/) to track bugs
|
142
|
+
and features. Before submitting a bug report or feature request, check to make sure it hasn't already
|
143
|
+
been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
|
144
|
+
bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any
|
145
|
+
details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
|
146
|
+
operating system. Ideally, a bug report should include a pull request with failing specs.
|
147
|
+
|
148
|
+
## Submitting a Pull Request
|
149
|
+
|
150
|
+
1. Fork the project.
|
151
|
+
2. Create a topic branch.
|
152
|
+
3. Implement your feature or bug fix.
|
153
|
+
4. Add specs for your feature or bug fix.
|
154
|
+
5. Run `bundle exec rake`. If your changes are not 100% covered and passing, go back to step 4.
|
155
|
+
6. Commit and push your changes.
|
156
|
+
7. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
157
|
+
|
158
|
+
### To Do
|
159
|
+
|
160
|
+
* configurable formulas
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "acts_as_geocodable/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "acts_as_geocodable"
|
10
|
+
spec.version = ActsAsGeocodable::VERSION
|
11
|
+
|
12
|
+
spec.authors = ["Daniel Morrison", "Brandon Keepers", "Brian Ryckbost"]
|
13
|
+
spec.email = "info@collectiveidea.com"
|
14
|
+
spec.summary = "Simple geocoding for Active Record models"
|
15
|
+
spec.description = "Simple geocoding for Active Record models. See the README for more details."
|
16
|
+
spec.homepage = "https://github.com/collectiveidea/acts_as_geocodable"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.test_files = spec.files.grep(/^spec/)
|
21
|
+
|
22
|
+
spec.add_dependency "graticule", "~> 2.0"
|
23
|
+
spec.add_dependency "rails", ">= 3", "< 4.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: ".."
|
4
|
+
|
5
|
+
gem "rails", "~> 3.0.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "activerecord-mysql2-adapter"
|
9
|
+
gem "codeclimate-test-reporter", require: false
|
10
|
+
gem "database_cleaner"
|
11
|
+
gem "factory_girl"
|
12
|
+
gem "mysql2"
|
13
|
+
gem "pg"
|
14
|
+
gem "rspec", "~> 3.0"
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: ".."
|
4
|
+
|
5
|
+
gem "rails", "~> 3.1.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "codeclimate-test-reporter", require: false
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "factory_girl"
|
11
|
+
gem "mysql2"
|
12
|
+
gem "pg"
|
13
|
+
gem "rspec", "~> 3.0"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: ".."
|
4
|
+
|
5
|
+
gem "rails", "~> 3.2.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "codeclimate-test-reporter", require: false
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "factory_girl"
|
11
|
+
gem "mysql2"
|
12
|
+
gem "pg"
|
13
|
+
gem "rspec", "~> 3.0"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: ".."
|
4
|
+
|
5
|
+
gem "rails", "~> 4.0.0"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "codeclimate-test-reporter", require: false
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "factory_girl"
|
11
|
+
gem "mysql2"
|
12
|
+
gem "pg"
|
13
|
+
gem "rspec", "~> 3.0"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: ".."
|
4
|
+
|
5
|
+
gem "rails", "~> 4.1.0", ">= 4.1.2.rc"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "codeclimate-test-reporter", require: false
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "factory_girl"
|
11
|
+
gem "mysql2"
|
12
|
+
gem "pg"
|
13
|
+
gem "rspec", "~> 3.0"
|
14
|
+
end
|