geolocal 0.9.2 → 0.9.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7cad64f85f04f0bd9971651e2470ad2f344640
4
- data.tar.gz: 3e309a0a2464feb9c2431e34b2aacddfea18635c
3
+ metadata.gz: 8792c02f07fa1ef48a72bb33f2d4023ec213e09e
4
+ data.tar.gz: d2f653dc43c43adf4525c93028dc3743dd14c4a7
5
5
  SHA512:
6
- metadata.gz: c9735c98cb5e6268510d41d792c9dcfb88428d4123f69855f74e03f2c48e133fdac101d6ee7a9dd6c3a90093f5bd0fa7b41a96b9a16508e1fa2f90282f1c57d8
7
- data.tar.gz: 04cee72abe241e39642c681b87f003a6ab963d30d16182e1f206c438b1cdf5ec51711c1b0b4618deb462232a714c667856bff656fe174c404c7ffadc58c71148
6
+ metadata.gz: 57320e94ff4c7edb61b73ba4c00e9475c44bc2f992ae52926ec3f26bf495fcde9270605e17f18d29b10d6d079967c22761dc4875a2d1a85ac3864b9220dfd42d
7
+ data.tar.gz: f753383614e00db0dd56101e9915300f7082e00e050ab8179a7469e1089067c52bb659598982191994dc0f7e1ed9a24b6ed6bae7f8689e4038a8c75ce7ca5fb3
data/README.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  Geocode IP addresses with a single Ruby if statement.
4
4
  No network access, no context switches, no delay,
5
- just one low-calorie lookup like `Geolocal.in_spain?(request.remote_ip)`.
5
+ just one low-calorie lookup.
6
+
7
+ ```ruby
8
+ Geolocal.in_spain?(request.remote_ip)
9
+ ```
6
10
 
7
11
  500,000 individual lookups per second is fairly typical performance.
8
12
 
@@ -21,13 +25,15 @@ And this line to your Rakefile:
21
25
  require 'geolocal/tasks'
22
26
  ```
23
27
 
28
+
24
29
  ## Usage
25
30
 
26
31
  If you're using Rails, run `rails generate geolocal` to create the configuration file.
27
32
  Otherwise, crib from [config/geolocal.rb](https://github.com/bronson/geolocal/tree/master/config/geolocal.rb).
28
33
 
29
34
  The configuration file describes the ranges you're interested in.
30
- Here's an example:
35
+ Here's an example that creates three queries: `in_us?`, `in_spain?`,
36
+ and `in_central_america?`:
31
37
 
32
38
  ```ruby
33
39
  require 'geolocal/configuration'
@@ -43,7 +49,7 @@ end
43
49
 
44
50
  Now run `rake geolocal:update`. Geolocal downloads the geocoding data
45
51
  from the default provider (see the [providers](#providers) section) and
46
- creates the desired methods:
52
+ generates the methods:
47
53
 
48
54
  ```ruby
49
55
  require 'geolocal'
@@ -55,7 +61,7 @@ Geolocal.in_central_america?('200.16.66.0')
55
61
 
56
62
  #### The in\_*area*? method
57
63
 
58
- The `rake geolocal:update` task generates a Ruby file defining the methods you asked for.
64
+ Call this routine to discover whether an address is inside or outside the given area.
59
65
  You can pass:
60
66
 
61
67
  * a string: `Geolocal.in_us?("10.1.2.3")`
@@ -65,6 +71,10 @@ You can pass:
65
71
 
66
72
  It returns true if the IP address is in the area, false if not.
67
73
 
74
+ It works by generating a static array of ranges. `in_area?` binary
75
+ searches the appropriate array to determine whether the desired
76
+ address is contained or not.
77
+
68
78
 
69
79
  ## Config
70
80
 
@@ -77,6 +87,11 @@ Here are the supported configuration options:
77
87
  for countries, hundreds for cities). Default: `./tmp/geolocal`
78
88
  * **countries**: the ISO-codes of the countries to include in the lookup.
79
89
  * **ipv6**: whether the ranges should support ipv6 addresses.
90
+ * **ipv4**: whether the ranges should support ipv4 addresses.
91
+
92
+ If you don't compile in an address family, but you pass Geolocal an address in that
93
+ family (say, you omit ipv6 but call `Geolocal.in_us?('::1')`), then Geolocal will
94
+ return false. It will always assume the address is outside your ranges.
80
95
 
81
96
 
82
97
  ## Providers
@@ -144,6 +159,9 @@ with oddball environments like Heroku.
144
159
 
145
160
  ## Roadmap
146
161
 
162
+ Geolocal is running on multiple production sites. It has proven itself to be fast and stable.
163
+ Therefore, we may or may not ever get around to implementing these. Just depends on interest.
164
+
147
165
  * Add support for cities
148
166
  * other sources for this data? [MainFacts](http://mainfacts.com/ip-address-space-addresses), [NirSoft](http://www.nirsoft.net/countryip/)
149
167
  Also maybe allow providers to accept their own options?
@@ -154,7 +172,7 @@ with oddball environments like Heroku.
154
172
 
155
173
  ## License
156
174
 
157
- Pain-free MIT. Downloaded data is copyrighted by the provider you downloaded it from.
175
+ MIT. Any downloaded data is copyrighted by the provider you downloaded it from.
158
176
 
159
177
 
160
178
  ## Contributing
@@ -140,7 +140,7 @@ module #{modname}
140
140
  when Socket::AF_INET6 then mod = v6module
141
141
  else raise "Unknown family \#{family} for address \#{address}"
142
142
  end
143
- raise "ipv\#{family == 2 ? 4 : 6} was not compiled in" unless mod
143
+ return false unless mod # if we didn't compile in ipv6, assume nothing's local
144
144
  true if mod.bsearch { |range| num > range.max ? 1 : num < range.min ? -1 : 0 }
145
145
  end
146
146
 
@@ -8,7 +8,6 @@ namespace :geolocal do
8
8
  # but you can specify the config file on the command line:
9
9
  # `rake geolocal config=contrib/continents`
10
10
  config=ENV['config'] if ENV['config']
11
- puts "loading geolocal configuration from #{config}"
12
11
  require './' + config
13
12
 
14
13
  Geolocal.configuration.load_provider.new
@@ -1,3 +1,3 @@
1
1
  module Geolocal
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -146,7 +146,7 @@ describe Geolocal::Provider::Base do
146
146
  expect(io.string).not_to include '34605568..34606591'
147
147
 
148
148
  eval io.string
149
- expect{ Geolocal_v6.in_us? '2.16.13.255' }.to raise_error(/ipv4 was not compiled in/)
149
+ expect( Geolocal_v6.in_us? '2.16.13.255' ).to eq false
150
150
  expect( Geolocal_v6.in_us? '2001:400::' ).to eq true
151
151
  end
152
152
 
@@ -162,7 +162,7 @@ describe Geolocal::Provider::Base do
162
162
  expect(io.string).not_to include '0..42540528726795050063891204319802818559'
163
163
 
164
164
  eval io.string
165
- expect{ Geolocal_v4.in_us? '2001:400::' }.to raise_error(/ipv6 was not compiled in/)
165
+ expect( Geolocal_v4.in_us? '2001:400::' ).to eq false
166
166
  expect( Geolocal_v4.in_us? '2.16.13.255' ).to eq true
167
167
  end
168
168
 
@@ -72,7 +72,7 @@ module Geolocal
72
72
  when Socket::AF_INET6 then mod = v6module
73
73
  else raise "Unknown family \#{family} for address \#{address}"
74
74
  end
75
- raise "ipv\#{family == 2 ? 4 : 6} was not compiled in" unless mod
75
+ return false unless mod # if we didn't compile in ipv6, assume nothing's local
76
76
  true if mod.bsearch { |range| num > range.max ? 1 : num < range.min ? -1 : 0 }
77
77
  end
78
78
 
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.2
4
+ version: 0.9.3
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-02-11 00:00:00.000000000 Z
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.4.5
123
+ rubygems_version: 2.4.6
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Generates plain Ruby if statements to geocode IP addresses