sparoid 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/sparoid.rb +26 -11
- data/lib/sparoid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12dad3dbab45bb38650465dab2b26f356c051569b06d20ba1bcfd6af11eb9701
|
4
|
+
data.tar.gz: 0b17fe457b36978f1b682153cb14578192cb657a846fadcbb3abb2cf82e07bb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c31f7b1fa30e2d064b0e92e79b2b567bdfa4021995d7f52c25b6b4373d08062ed091aab8187aeb42051c11e0c7c1b994d158878e64311eed28e68d1e3fe4008
|
7
|
+
data.tar.gz: cacd2adf45ed9fa8e31b063809e01cf0371c6d13670e24b5bdb17f7c2623c2f9592c7e38b6df18a5f529db9628d4197baf323a9d58124b8eb6ea75762c3a6d78
|
data/CHANGELOG.md
CHANGED
data/lib/sparoid.rb
CHANGED
@@ -76,23 +76,38 @@ module Sparoid
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def cached_public_ip
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Resolv::IPv4.create f.read
|
84
|
-
end
|
79
|
+
if up_to_date_cache?
|
80
|
+
read_cache
|
81
|
+
else
|
82
|
+
write_cache
|
85
83
|
end
|
86
84
|
rescue StandardError => e
|
87
85
|
warn "Sparoid: #{e.inspect}"
|
88
86
|
public_ip
|
89
87
|
end
|
90
88
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
def up_to_date_cache?
|
90
|
+
mtime = File.mtime("/tmp/.sparoid_public_ip")
|
91
|
+
(Time.now - mtime) <= 60 # cache is valid for 1 min
|
92
|
+
rescue Errno::ENOENT
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
def read_cache
|
97
|
+
File.open("/tmp/.sparoid_public_ip", "r") do |f|
|
98
|
+
f.flock(File::LOCK_SH)
|
99
|
+
Resolv::IPv4.create f.read
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def write_cache
|
104
|
+
File.open("/tmp/.sparoid_public_ip", File::WRONLY | File::CREAT, 0o0644) do |f|
|
105
|
+
f.flock(File::LOCK_EX)
|
106
|
+
ip = public_ip
|
107
|
+
f.truncate(0)
|
108
|
+
f.write ip.to_s
|
109
|
+
ip
|
110
|
+
end
|
96
111
|
end
|
97
112
|
|
98
113
|
def public_ip
|
data/lib/sparoid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Hörberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|