ip_lookup 1.0.5 → 1.0.6
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 +4 -4
- data/lib/ip_lookup/db.rb +16 -6
- data/lib/ip_lookup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da2edd11ee6ec57de8ceb5b4309c2f44b9d87c74e0a6641d3c655cf37e1b8476
|
4
|
+
data.tar.gz: fd1d398f16e05338bee0d187b5cd581cf59f656a0b5908619df149fbbf49958b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b7b082909b9d9627e003f2038bcb5a587a205b895ecd9b0555833c29d2f6647ca4ff00667acc25da99d6e4628f86ba7dfcf00aa7ab7e43a6abbec56cb85a6ac
|
7
|
+
data.tar.gz: 4596ce4113b386871de1910891b3553ce4b98daf41457f9d98a8fc007b5dbbaa7a0610e819debfde8bc16f6bc258d00a8b3c38f98ec5fb4764f752772b2cf87b
|
data/lib/ip_lookup/db.rb
CHANGED
@@ -29,7 +29,7 @@ class IPLookup
|
|
29
29
|
def db
|
30
30
|
self.class.mutex.synchronize do
|
31
31
|
@db ||= begin
|
32
|
-
MaxMindDB.new self.class.
|
32
|
+
MaxMindDB.new self.class.full_db_path
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -52,7 +52,9 @@ class IPLookup
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def save_db(result)
|
55
|
-
|
55
|
+
Dir.mkdir(db_path) unless File.exist?(db_path)
|
56
|
+
|
57
|
+
File.open(full_db_path, 'w') do |file|
|
56
58
|
flock(file) do |f|
|
57
59
|
f.write(result)
|
58
60
|
end
|
@@ -77,18 +79,26 @@ class IPLookup
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def db_exists?
|
80
|
-
File.file?
|
82
|
+
File.file? full_db_path
|
81
83
|
end
|
82
84
|
|
83
85
|
def db_age
|
84
|
-
(Time.now - File.mtime(
|
86
|
+
(Time.now - File.mtime(full_db_path)) / (24 * 60 * 60)
|
87
|
+
end
|
88
|
+
|
89
|
+
def full_db_path
|
90
|
+
File.join(db_path, db_filename)
|
91
|
+
end
|
92
|
+
|
93
|
+
def db_filename
|
94
|
+
"/geolite-city.mmdb"
|
85
95
|
end
|
86
96
|
|
87
97
|
def db_path
|
88
98
|
if Gem.loaded_specs["ip_lookup"]
|
89
|
-
File.join(Gem.loaded_specs["ip_lookup"].full_gem_path, "/support
|
99
|
+
File.join(Gem.loaded_specs["ip_lookup"].full_gem_path, "/support")
|
90
100
|
else
|
91
|
-
File.join(File.expand_path("../..", File.dirname(__FILE__)), "/support
|
101
|
+
File.join(File.expand_path("../..", File.dirname(__FILE__)), "/support")
|
92
102
|
end
|
93
103
|
end
|
94
104
|
end
|
data/lib/ip_lookup/version.rb
CHANGED