geolocal 0.9.3 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8792c02f07fa1ef48a72bb33f2d4023ec213e09e
4
- data.tar.gz: d2f653dc43c43adf4525c93028dc3743dd14c4a7
3
+ metadata.gz: 7ee0a56261b1f3f51f2415d9caa95a4aa5b85b00
4
+ data.tar.gz: c40f16d2a55e3b31c161383f61cbd02ab656cbc5
5
5
  SHA512:
6
- metadata.gz: 57320e94ff4c7edb61b73ba4c00e9475c44bc2f992ae52926ec3f26bf495fcde9270605e17f18d29b10d6d079967c22761dc4875a2d1a85ac3864b9220dfd42d
7
- data.tar.gz: f753383614e00db0dd56101e9915300f7082e00e050ab8179a7469e1089067c52bb659598982191994dc0f7e1ed9a24b6ed6bae7f8689e4038a8c75ce7ca5fb3
6
+ metadata.gz: 1ea108d018f1218f49a0c40213a5a87dd8c96f935e99c95fc86e4946a1b5a92a2f8d799bf07fbfc581203f9688e61c4cbc359074cb1c55275bd665f21951f7e9
7
+ data.tar.gz: 5686fbdee7424dd1892889e2609db759f77a0d65862a5b73afd7ea70de4d22aa0614bf88cab362b1ddbf01e37e6e15dd88ae9a73bc8090db084a120c066bca90
@@ -0,0 +1,3 @@
1
+ ## 1.0
2
+
3
+ * Things are stable, time to draw the line! Commence backward compatibility.
data/Gemfile CHANGED
@@ -1,8 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- group :development do
5
- gem 'guard'
6
- gem 'guard-rspec'
7
- gem 'guard-bundler'
8
- end
data/README.md CHANGED
@@ -28,10 +28,12 @@ require 'geolocal/tasks'
28
28
 
29
29
  ## Usage
30
30
 
31
- If you're using Rails, run `rails generate geolocal` to create the configuration file.
31
+ Geolocal creates routines that return true or false depending on whether a particular IP address is within an area.
32
+ A config file describes the areas you're interested in.
33
+
34
+ If you're using Rails, run `rails generate geolocal` to create the config file.
32
35
  Otherwise, crib from [config/geolocal.rb](https://github.com/bronson/geolocal/tree/master/config/geolocal.rb).
33
36
 
34
- The configuration file describes the ranges you're interested in.
35
37
  Here's an example that creates three queries: `in_us?`, `in_spain?`,
36
38
  and `in_central_america?`:
37
39
 
@@ -109,7 +111,16 @@ Run them like this:
109
111
  ```sh
110
112
  git clone https://github.com/bronson/geolocal
111
113
  cd geolocal
112
- rake geolocal config=contrib/continents.rb
114
+ rake geolocal config=contrib/continents
115
+ ```
116
+
117
+ Now look at the `tmp/geolocal.rb` file. Beware, it's big!
118
+
119
+ Here's an example of using it from a command. The `-Itmp` argument ensures `require` will
120
+ load `tmp/geolocal.rb`, then we just look up the IP address `8.8.8.8`.
121
+
122
+ ```bash
123
+ ruby -Itmp -e 'require "geolocal"; puts Geolocal.in_north_america?("8.8.8.8") ? "yes!" : "nope"'
113
124
  ```
114
125
 
115
126
 
@@ -121,7 +132,7 @@ to create a `Geolocal.in_eu?(ip_addr)` method:
121
132
  ```ruby
122
133
  require 'countries'
123
134
 
124
- eu_codes = Country.find_all_by_eu_member(true).map(&:first)
135
+ eu_codes = ISO3166::Country.find_all_by_eu_member(true).map(&:first)
125
136
 
126
137
  Geolocal.configure do |config|
127
138
  config.countries = { us: 'US', eu: eu_codes }
@@ -143,7 +154,7 @@ expect to do better than a million lookups every two seconds.
143
154
  To see for yourself, run the continents benchmark:
144
155
 
145
156
  ```sh
146
- rake geolocal config=contrib/continents.rb
157
+ rake geolocal config=contrib/continents
147
158
  ruby contrib/benchmark-continents.rb
148
159
  ```
149
160
 
@@ -5,22 +5,17 @@
5
5
  # Now you can call Geolocal.in_africa?, in_antarcitca?, in_asia?, etc.
6
6
 
7
7
 
8
- require 'geolocal'
8
+ require 'geolocal/configuration'
9
9
  require 'countries'
10
10
 
11
11
 
12
12
  # creates in_x? methods for each continent: in_north_america?, in_europe?, etc.
13
13
 
14
14
  Geolocal.configure do |config|
15
- all_countries = Country.all.map { |c| Country[c[1]] }
16
-
17
- # { 'antarctica' => ['AQ', 'BV', ...], 'australia' => ['AS', 'AU', ...], ... }
18
- by_continent = all_countries.reduce({}) { |hash,country|
19
- continent = country.continent.downcase;
20
- hash[continent] ||= [];
21
- hash[continent] << country.alpha2;
22
- hash
23
- }
15
+ continents = ISO3166::Country.all.group_by(&:continent)
16
+ by_continent = continents.merge(continents) do |continent, countries|
17
+ countries.map(&:alpha2)
18
+ end
24
19
 
25
20
  config.countries = by_continent
26
21
  config.ipv6 = false
@@ -1,3 +1,3 @@
1
1
  module Geolocal
2
- VERSION = "0.9.3"
2
+ VERSION = "1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geolocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Bronson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".rspec"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - Guardfile
81
82
  - LICENSE.txt
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  requirements: []
122
123
  rubyforge_project:
123
- rubygems_version: 2.4.6
124
+ rubygems_version: 2.4.5
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Generates plain Ruby if statements to geocode IP addresses