world-flags 0.4.8.2 → 0.4.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/world_flags/helper/geo.rb +8 -1
- data/lib/world_flags/helper/locale.rb +7 -1
- data/lib/world_flags/util/config.rb +14 -2
- data/world-flags.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.8.
|
1
|
+
0.4.8.3
|
@@ -7,16 +7,23 @@ module WorldFlags
|
|
7
7
|
ip ||= request.remote_ip
|
8
8
|
raise WorldFlags::GeoIPError, "IP address #{ip} is a localhost address" if local_ip?(ip)
|
9
9
|
|
10
|
+
puts "find country code for ip: #{ip}" if debug?
|
11
|
+
|
10
12
|
@geoip ||= ::GeoIP.new WorldFlags.geo_ip_db_path
|
11
13
|
country = @geoip.country(ip)
|
12
14
|
return country[2] unless country.nil?
|
13
|
-
|
15
|
+
rescue Exception => e
|
16
|
+
raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip} - #{e}"
|
14
17
|
end
|
15
18
|
|
16
19
|
def self.local_ip? ip
|
17
20
|
WorldFlags.localhost_list.include?(ip)
|
18
21
|
end
|
19
22
|
|
23
|
+
def self.debug?
|
24
|
+
WorldFlags.debug?
|
25
|
+
end
|
26
|
+
|
20
27
|
def country_code_from_ip ip = nil
|
21
28
|
WorldFlags::Helper::Geo.country_code_from_ip ip
|
22
29
|
end
|
@@ -35,12 +35,18 @@ module WorldFlags
|
|
35
35
|
when :browser
|
36
36
|
browser_locale # http://www.metamodpro.com/browser-language-codes
|
37
37
|
when :ip
|
38
|
-
|
38
|
+
get_country_by_ip
|
39
39
|
when :default
|
40
40
|
I18n.default_locale
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def get_country_by_ip
|
45
|
+
country_code_from_ip browser_ip
|
46
|
+
rescue WorldFlags::GeoIPError
|
47
|
+
I18n.default_locale
|
48
|
+
end
|
49
|
+
|
44
50
|
def browser_ip
|
45
51
|
request.remote_ip
|
46
52
|
end
|
@@ -1,16 +1,28 @@
|
|
1
1
|
module WorldFlags
|
2
2
|
module Util
|
3
3
|
module Config
|
4
|
-
attr_accessor :auto_select, :raise_error
|
4
|
+
attr_accessor :auto_select, :raise_error, :debug
|
5
5
|
attr_accessor :default_code, :default_locale
|
6
6
|
attr_writer :locale_source_priority, :geo_ip_db_path, :localhost_list
|
7
7
|
|
8
|
+
def debug?
|
9
|
+
@debug
|
10
|
+
end
|
11
|
+
|
12
|
+
def debug_on!
|
13
|
+
@debug = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def debug_off!
|
17
|
+
@debug = false
|
18
|
+
end
|
19
|
+
|
8
20
|
def geo_ip_db_path
|
9
21
|
@geo_ip_db_path ||= ::Rails.root.join 'db', 'GeoIP.dat'
|
10
22
|
end
|
11
23
|
|
12
24
|
def localhost_list
|
13
|
-
@localhost_list ||= ["127.0.0.1"]
|
25
|
+
@localhost_list ||= ["127.0.0.1", "localhost", "0.0.0.0"]
|
14
26
|
end
|
15
27
|
|
16
28
|
def locale_source_priority
|
data/world-flags.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world-flags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.8.
|
4
|
+
version: 0.4.8.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -263,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
263
263
|
version: '0'
|
264
264
|
segments:
|
265
265
|
- 0
|
266
|
-
hash:
|
266
|
+
hash: 3232077924717246299
|
267
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
268
268
|
none: false
|
269
269
|
requirements:
|