online 0.0.1 → 0.1.0
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/Gemfile +4 -4
- data/Gemfile.lock +17 -17
- data/README.md +20 -0
- data/lib/online.rb +3 -1
- data/online.gemspec +2 -2
- metadata +2 -21
- data/.0pdd.yml +0 -8
- data/.gitattributes +0 -7
- data/.github/workflows/actionlint.yml +0 -25
- data/.github/workflows/codecov.yml +0 -25
- data/.github/workflows/copyrights.yml +0 -19
- data/.github/workflows/markdown-lint.yml +0 -23
- data/.github/workflows/pdd.yml +0 -19
- data/.github/workflows/rake.yml +0 -28
- data/.github/workflows/reuse.yml +0 -19
- data/.github/workflows/typos.yml +0 -19
- data/.github/workflows/xcop.yml +0 -19
- data/.github/workflows/yamllint.yml +0 -19
- data/.gitignore +0 -13
- data/.pdd +0 -7
- data/.rubocop.yml +0 -53
- data/.rultor.yml +0 -26
- data/renovate.json +0 -6
- data/test/test__helper.rb +0 -31
- data/test/test_online.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b676e3f37ff58fe5ad57c2bebe0afafeb9c522e18113ff6098f456f18b4d4df0
|
4
|
+
data.tar.gz: c388c79309f619b4f9c5ffc58a680859281396d029ebf6fb3dbb2feddcf3571c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5576f41fd242027a3401a428c491b9b507550460dab23505ae24b17ea833f5d352336a8485b6099b01de031d9b9d5b3ecdcc52ba4d32fb929aadddfcef38fd49
|
7
|
+
data.tar.gz: '0068189a76b8a4da93194471c7d0798fb102c608f09c8e5cbccb9ada926e44b6dbed4f95939da4276d9c52ba364571fbb40b00a6913b270b0e793ac7bcb00e2b'
|
data/Gemfile
CHANGED
@@ -10,10 +10,10 @@ gem 'minitest', '~>5.25', require: false
|
|
10
10
|
gem 'minitest-reporters', '~>1.7', require: false
|
11
11
|
gem 'rake', '~>13.2', require: false
|
12
12
|
gem 'rubocop', '~>1.73', require: false
|
13
|
-
gem 'rubocop-minitest', '
|
14
|
-
gem 'rubocop-performance', '
|
15
|
-
gem 'rubocop-rake', '
|
13
|
+
gem 'rubocop-minitest', '~>0.38', require: false
|
14
|
+
gem 'rubocop-performance', '~>1.25', require: false
|
15
|
+
gem 'rubocop-rake', '~>0.7', require: false
|
16
16
|
gem 'simplecov', '~>0.22', require: false
|
17
|
-
gem 'simplecov-cobertura', '~>
|
17
|
+
gem 'simplecov-cobertura', '~>3.0', require: false
|
18
18
|
gem 'webmock', '~>3.25', require: false
|
19
19
|
gem 'yard', '~>0.9', require: false
|
data/Gemfile.lock
CHANGED
@@ -18,7 +18,7 @@ GEM
|
|
18
18
|
rexml
|
19
19
|
docile (1.4.1)
|
20
20
|
hashdiff (1.2.0)
|
21
|
-
json (2.
|
21
|
+
json (2.13.2)
|
22
22
|
language_server-protocol (3.17.0.5)
|
23
23
|
lint_roller (1.1.0)
|
24
24
|
minitest (5.25.5)
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
minitest (>= 5.0)
|
29
29
|
ruby-progressbar
|
30
30
|
parallel (1.27.0)
|
31
|
-
parser (3.3.
|
31
|
+
parser (3.3.9.0)
|
32
32
|
ast (~> 2.4.1)
|
33
33
|
racc
|
34
34
|
prism (1.4.0)
|
@@ -36,9 +36,9 @@ GEM
|
|
36
36
|
racc (1.8.1)
|
37
37
|
rainbow (3.1.1)
|
38
38
|
rake (13.3.0)
|
39
|
-
regexp_parser (2.
|
40
|
-
rexml (3.4.
|
41
|
-
rubocop (1.
|
39
|
+
regexp_parser (2.11.2)
|
40
|
+
rexml (3.4.2)
|
41
|
+
rubocop (1.80.2)
|
42
42
|
json (~> 2.3)
|
43
43
|
language_server-protocol (~> 3.17.0.2)
|
44
44
|
lint_roller (~> 1.1.0)
|
@@ -46,20 +46,20 @@ GEM
|
|
46
46
|
parser (>= 3.3.0.2)
|
47
47
|
rainbow (>= 2.2.2, < 4.0)
|
48
48
|
regexp_parser (>= 2.9.3, < 3.0)
|
49
|
-
rubocop-ast (>= 1.
|
49
|
+
rubocop-ast (>= 1.46.0, < 2.0)
|
50
50
|
ruby-progressbar (~> 1.7)
|
51
51
|
unicode-display_width (>= 2.4.0, < 4.0)
|
52
|
-
rubocop-ast (1.
|
52
|
+
rubocop-ast (1.46.0)
|
53
53
|
parser (>= 3.3.7.2)
|
54
54
|
prism (~> 1.4)
|
55
|
-
rubocop-minitest (0.38.
|
55
|
+
rubocop-minitest (0.38.2)
|
56
56
|
lint_roller (~> 1.1)
|
57
57
|
rubocop (>= 1.75.0, < 2.0)
|
58
58
|
rubocop-ast (>= 1.38.0, < 2.0)
|
59
|
-
rubocop-performance (1.
|
59
|
+
rubocop-performance (1.26.0)
|
60
60
|
lint_roller (~> 1.1)
|
61
61
|
rubocop (>= 1.75.0, < 2.0)
|
62
|
-
rubocop-ast (>= 1.
|
62
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
63
63
|
rubocop-rake (0.7.1)
|
64
64
|
lint_roller (~> 1.1)
|
65
65
|
rubocop (>= 1.72.1)
|
@@ -68,13 +68,13 @@ GEM
|
|
68
68
|
docile (~> 1.1)
|
69
69
|
simplecov-html (~> 0.11)
|
70
70
|
simplecov_json_formatter (~> 0.1)
|
71
|
-
simplecov-cobertura (
|
71
|
+
simplecov-cobertura (3.1.0)
|
72
72
|
rexml
|
73
73
|
simplecov (~> 0.19)
|
74
|
-
simplecov-html (0.13.
|
74
|
+
simplecov-html (0.13.2)
|
75
75
|
simplecov_json_formatter (0.1.4)
|
76
76
|
timeout (0.4.3)
|
77
|
-
unicode-display_width (3.1.
|
77
|
+
unicode-display_width (3.1.5)
|
78
78
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
79
79
|
unicode-emoji (4.0.4)
|
80
80
|
webmock (3.25.1)
|
@@ -99,11 +99,11 @@ DEPENDENCIES
|
|
99
99
|
online!
|
100
100
|
rake (~> 13.2)
|
101
101
|
rubocop (~> 1.73)
|
102
|
-
rubocop-minitest (
|
103
|
-
rubocop-performance (
|
104
|
-
rubocop-rake (
|
102
|
+
rubocop-minitest (~> 0.38)
|
103
|
+
rubocop-performance (~> 1.25)
|
104
|
+
rubocop-rake (~> 0.7)
|
105
105
|
simplecov (~> 0.22)
|
106
|
-
simplecov-cobertura (~>
|
106
|
+
simplecov-cobertura (~> 3.0)
|
107
107
|
webmock (~> 3.25)
|
108
108
|
yard (~> 0.9)
|
109
109
|
|
data/README.md
CHANGED
@@ -26,6 +26,26 @@ if online?
|
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
+
You can also check a particular URL:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
if online?(uri: 'https://api.github.com')
|
33
|
+
# GitHub API is accessible
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
The `online?()` function doesn't make an HTTP request on each call, but
|
38
|
+
instead caches the previous result for five minutes. You can change this
|
39
|
+
interval to three seconds, for example:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
if online?(ttl: 3)
|
43
|
+
# We are online, let's run integration tests!
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
That's it.
|
48
|
+
|
29
49
|
## How to contribute
|
30
50
|
|
31
51
|
Read
|
data/lib/online.rb
CHANGED
@@ -86,6 +86,8 @@ module Kernel
|
|
86
86
|
# and unreachable hosts
|
87
87
|
# @note Results are cached with a default TTL of 5 minutes to reduce network requests
|
88
88
|
def online?(uri: 'http://www.google.com', ttl: 300)
|
89
|
+
raise 'The URI is nil' if uri.nil?
|
90
|
+
raise 'The TTL is nil' if ttl.nil?
|
89
91
|
key = uri.to_s
|
90
92
|
OnlineOrOffline.mutex.synchronize do
|
91
93
|
entry = OnlineOrOffline.cache[key]
|
@@ -95,7 +97,7 @@ module Kernel
|
|
95
97
|
Net::HTTP.get_response(URI(uri)).is_a?(Net::HTTPSuccess)
|
96
98
|
rescue \
|
97
99
|
Timeout::Error, Timeout::ExitException, Socket::ResolutionError,
|
98
|
-
Errno::EHOSTUNREACH, Errno::EINVAL, Errno::EADDRNOTAVAIL
|
100
|
+
Errno::EHOSTUNREACH, Errno::EINVAL, Errno::EADDRNOTAVAIL, Errno::EBADF
|
99
101
|
false
|
100
102
|
end
|
101
103
|
OnlineOrOffline.cache[key] = { status: status, time: Time.now }
|
data/online.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
10
10
|
s.required_ruby_version = '>=3.2'
|
11
11
|
s.name = 'online'
|
12
|
-
s.version = '0.0
|
12
|
+
s.version = '0.1.0'
|
13
13
|
s.license = 'MIT'
|
14
14
|
s.summary = 'Checks whether we are currently online or offline'
|
15
15
|
s.description =
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.authors = ['Yegor Bugayenko']
|
19
19
|
s.email = 'yegor256@gmail.com'
|
20
20
|
s.homepage = 'https://github.com/yegor256/online'
|
21
|
-
s.files = `git ls-files`.split($RS)
|
21
|
+
s.files = `git ls-files | grep -v -E '^(test/|\\.|renovate)'`.split($RS)
|
22
22
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
23
|
s.rdoc_options = ['--charset=UTF-8']
|
24
24
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: online
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -33,22 +33,6 @@ extra_rdoc_files:
|
|
33
33
|
- LICENSE.txt
|
34
34
|
- README.md
|
35
35
|
files:
|
36
|
-
- ".0pdd.yml"
|
37
|
-
- ".gitattributes"
|
38
|
-
- ".github/workflows/actionlint.yml"
|
39
|
-
- ".github/workflows/codecov.yml"
|
40
|
-
- ".github/workflows/copyrights.yml"
|
41
|
-
- ".github/workflows/markdown-lint.yml"
|
42
|
-
- ".github/workflows/pdd.yml"
|
43
|
-
- ".github/workflows/rake.yml"
|
44
|
-
- ".github/workflows/reuse.yml"
|
45
|
-
- ".github/workflows/typos.yml"
|
46
|
-
- ".github/workflows/xcop.yml"
|
47
|
-
- ".github/workflows/yamllint.yml"
|
48
|
-
- ".gitignore"
|
49
|
-
- ".pdd"
|
50
|
-
- ".rubocop.yml"
|
51
|
-
- ".rultor.yml"
|
52
36
|
- Gemfile
|
53
37
|
- Gemfile.lock
|
54
38
|
- LICENSE.txt
|
@@ -58,9 +42,6 @@ files:
|
|
58
42
|
- Rakefile
|
59
43
|
- lib/online.rb
|
60
44
|
- online.gemspec
|
61
|
-
- renovate.json
|
62
|
-
- test/test__helper.rb
|
63
|
-
- test/test_online.rb
|
64
45
|
homepage: https://github.com/yegor256/online
|
65
46
|
licenses:
|
66
47
|
- MIT
|
@@ -81,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
62
|
- !ruby/object:Gem::Version
|
82
63
|
version: '0'
|
83
64
|
requirements: []
|
84
|
-
rubygems_version: 3.6.
|
65
|
+
rubygems_version: 3.6.9
|
85
66
|
specification_version: 4
|
86
67
|
summary: Checks whether we are currently online or offline
|
87
68
|
test_files: []
|
data/.0pdd.yml
DELETED
data/.gitattributes
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: actionlint
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
actionlint:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- name: Download actionlint
|
20
|
-
id: get_actionlint
|
21
|
-
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
|
22
|
-
shell: bash
|
23
|
-
- name: Check workflow files
|
24
|
-
run: ${{ steps.get_actionlint.outputs.executable }} -color
|
25
|
-
shell: bash
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: codecov
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
jobs:
|
11
|
-
codecov:
|
12
|
-
timeout-minutes: 15
|
13
|
-
runs-on: ubuntu-24.04
|
14
|
-
steps:
|
15
|
-
- uses: actions/checkout@v4
|
16
|
-
- uses: ruby/setup-ruby@v1
|
17
|
-
with:
|
18
|
-
ruby-version: 3.3
|
19
|
-
bundler-cache: true
|
20
|
-
- run: bundle config set --global path "$(pwd)/vendor/bundle"
|
21
|
-
- run: bundle install --no-color
|
22
|
-
- run: bundle exec rake
|
23
|
-
- uses: codecov/codecov-action@v5
|
24
|
-
with:
|
25
|
-
token: ${{ secrets.CODECOV_TOKEN }}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: copyrights
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
copyrights:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: yegor256/copyrights-action@0.0.12
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: markdown-lint
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
paths-ignore: ['paper/**', 'sandbox/**']
|
14
|
-
concurrency:
|
15
|
-
group: markdown-lint-${{ github.ref }}
|
16
|
-
cancel-in-progress: true
|
17
|
-
jobs:
|
18
|
-
markdown-lint:
|
19
|
-
timeout-minutes: 15
|
20
|
-
runs-on: ubuntu-24.04
|
21
|
-
steps:
|
22
|
-
- uses: actions/checkout@v4
|
23
|
-
- uses: DavidAnson/markdownlint-cli2-action@v20.0.0
|
data/.github/workflows/pdd.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: pdd
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
pdd:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: volodya-lombrozo/pdd-action@master
|
data/.github/workflows/rake.yml
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: rake
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
rake:
|
15
|
-
strategy:
|
16
|
-
matrix:
|
17
|
-
os: [ubuntu-24.04, macos-15]
|
18
|
-
ruby: [3.3]
|
19
|
-
runs-on: ${{ matrix.os }}
|
20
|
-
steps:
|
21
|
-
- uses: actions/checkout@v4
|
22
|
-
- uses: ruby/setup-ruby@v1
|
23
|
-
with:
|
24
|
-
ruby-version: ${{ matrix.ruby }}
|
25
|
-
bundler-cache: true
|
26
|
-
- run: bundle config set --global path "$(pwd)/vendor/bundle"
|
27
|
-
- run: bundle install --no-color
|
28
|
-
- run: bundle exec rake
|
data/.github/workflows/reuse.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: reuse
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
reuse:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: fsfe/reuse-action@v5
|
data/.github/workflows/typos.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: typos
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
typos:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: crate-ci/typos@v1.33.1
|
data/.github/workflows/xcop.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: xcop
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
xcop:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: g4s8/xcop-action@master
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
name: yamllint
|
6
|
-
'on':
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
pull_request:
|
11
|
-
branches:
|
12
|
-
- master
|
13
|
-
jobs:
|
14
|
-
yamllint:
|
15
|
-
timeout-minutes: 15
|
16
|
-
runs-on: ubuntu-24.04
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: ibiqlik/action-yamllint@v3
|
data/.gitignore
DELETED
data/.pdd
DELETED
data/.rubocop.yml
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
AllCops:
|
5
|
-
Exclude:
|
6
|
-
- 'bin/**/*'
|
7
|
-
- 'assets/**/*'
|
8
|
-
- 'vendor/**/*'
|
9
|
-
DisplayCopNames: true
|
10
|
-
TargetRubyVersion: 3.2
|
11
|
-
SuggestExtensions: false
|
12
|
-
NewCops: enable
|
13
|
-
plugins:
|
14
|
-
- rubocop-minitest
|
15
|
-
- rubocop-performance
|
16
|
-
- rubocop-rake
|
17
|
-
Minitest/EmptyLineBeforeAssertionMethods:
|
18
|
-
Enabled: false
|
19
|
-
Metrics/ParameterLists:
|
20
|
-
Enabled: false
|
21
|
-
Style/GlobalVars:
|
22
|
-
Enabled: false
|
23
|
-
Metrics/MethodLength:
|
24
|
-
Enabled: false
|
25
|
-
Gemspec/RequiredRubyVersion:
|
26
|
-
Enabled: false
|
27
|
-
Style/ClassAndModuleChildren:
|
28
|
-
Enabled: false
|
29
|
-
Layout/MultilineMethodCallIndentation:
|
30
|
-
Enabled: false
|
31
|
-
Metrics/AbcSize:
|
32
|
-
Enabled: false
|
33
|
-
Metrics/ClassLength:
|
34
|
-
Enabled: false
|
35
|
-
Metrics/BlockLength:
|
36
|
-
Enabled: false
|
37
|
-
Metrics/CyclomaticComplexity:
|
38
|
-
Enabled: false
|
39
|
-
Metrics/PerceivedComplexity:
|
40
|
-
Enabled: false
|
41
|
-
Layout/EmptyLineAfterGuardClause:
|
42
|
-
Enabled: false
|
43
|
-
Layout/CaseIndentation:
|
44
|
-
Enabled: false
|
45
|
-
Naming/MethodParameterName:
|
46
|
-
MinNameLength: 2
|
47
|
-
Layout/EndOfLine:
|
48
|
-
EnforcedStyle: lf
|
49
|
-
Layout/MultilineAssignmentLayout:
|
50
|
-
Enabled: true
|
51
|
-
Layout/FirstHashElementIndentation:
|
52
|
-
EnforcedStyle: consistent
|
53
|
-
require: []
|
data/.rultor.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
---
|
4
|
-
# yamllint disable rule:line-length
|
5
|
-
docker:
|
6
|
-
image: yegor256/ruby
|
7
|
-
assets:
|
8
|
-
rubygems.yml: yegor256/home#assets/rubygems.yml
|
9
|
-
install: |
|
10
|
-
pdd -f /dev/null
|
11
|
-
bundle install --no-color
|
12
|
-
release:
|
13
|
-
pre: false
|
14
|
-
script: |-
|
15
|
-
[[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
|
16
|
-
bundle exec rake
|
17
|
-
rm -rf *.gem
|
18
|
-
sed -i "s/0\.0\.0/${tag}/g" online.gemspec
|
19
|
-
git add online.gemspec
|
20
|
-
git commit -m "version set to ${tag}"
|
21
|
-
gem build online.gemspec
|
22
|
-
chmod 0600 ../rubygems.yml
|
23
|
-
gem push *.gem --config-file ../rubygems.yml
|
24
|
-
merge:
|
25
|
-
script: |-
|
26
|
-
bundle exec rake
|
data/renovate.json
DELETED
data/test/test__helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
$stdout.sync = true
|
7
|
-
|
8
|
-
require 'simplecov'
|
9
|
-
require 'simplecov-cobertura'
|
10
|
-
unless SimpleCov.running || ENV['PICKS']
|
11
|
-
SimpleCov.command_name('test')
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
13
|
-
[
|
14
|
-
SimpleCov::Formatter::HTMLFormatter,
|
15
|
-
SimpleCov::Formatter::CoberturaFormatter
|
16
|
-
]
|
17
|
-
)
|
18
|
-
SimpleCov.minimum_coverage 95
|
19
|
-
SimpleCov.minimum_coverage_by_file 95
|
20
|
-
SimpleCov.start do
|
21
|
-
add_filter 'test/'
|
22
|
-
add_filter 'vendor/'
|
23
|
-
add_filter 'target/'
|
24
|
-
track_files 'lib/**/*.rb'
|
25
|
-
track_files '*.rb'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
require 'minitest/autorun'
|
30
|
-
require 'minitest/reporters'
|
31
|
-
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
data/test/test_online.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'webmock/minitest'
|
7
|
-
require_relative 'test__helper'
|
8
|
-
require_relative '../lib/online'
|
9
|
-
|
10
|
-
# Test.
|
11
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
|
-
# License:: MIT
|
14
|
-
class TestOnline < Minitest::Test
|
15
|
-
def setup
|
16
|
-
Kernel::OnlineOrOffline.cache = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_when_online
|
20
|
-
WebMock.disable_net_connect!
|
21
|
-
stub_request(:get, 'http://www.google.com/').to_return(body: '')
|
22
|
-
assert_predicate(self, :online?)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_when_offline
|
26
|
-
WebMock.disable_net_connect!
|
27
|
-
stub_request(:get, 'http://www.google.com/').to_raise(Socket::ResolutionError, 'failure')
|
28
|
-
refute_predicate(self, :online?)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_cache_returns_same_result
|
32
|
-
WebMock.disable_net_connect!
|
33
|
-
stub_request(:get, 'http://www.google.com/').to_return(body: '')
|
34
|
-
assert_predicate(self, :online?)
|
35
|
-
WebMock.reset!
|
36
|
-
stub_request(:get, 'http://www.google.com/').to_raise(Socket::ResolutionError, 'failure')
|
37
|
-
assert_predicate(self, :online?)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_cache_expires_after_ttl
|
41
|
-
WebMock.disable_net_connect!
|
42
|
-
stub_request(:get, 'http://www.google.com/').to_return(body: '')
|
43
|
-
assert online?(ttl: 0)
|
44
|
-
WebMock.reset!
|
45
|
-
stub_request(:get, 'http://www.google.com/').to_raise(Socket::ResolutionError, 'failure')
|
46
|
-
refute online?(ttl: 0)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_different_uris_cached_separately
|
50
|
-
WebMock.disable_net_connect!
|
51
|
-
stub_request(:get, 'http://www.google.com/').to_return(body: '')
|
52
|
-
stub_request(:get, 'http://example.com/').to_raise(Socket::ResolutionError, 'failure')
|
53
|
-
assert online?(uri: 'http://www.google.com')
|
54
|
-
refute online?(uri: 'http://example.com')
|
55
|
-
end
|
56
|
-
end
|