online 0.0.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5c935181fd3681e830413f863498954281f1f498b5456a5920cb89937d4780b
4
- data.tar.gz: f22371f34837a12d6efaf0b5491820606139ab68e7921b75720bea78d3150951
3
+ metadata.gz: e39ddd7a39de7638e54b088e1f350444bf0922860082e55d0705524b1df08dec
4
+ data.tar.gz: 88cdb650e021f7f195c7394c23b84166a54345d322c75ee603ab51e4033d88fd
5
5
  SHA512:
6
- metadata.gz: d75348162f7d9de1725c54bedff46f5b7ddaccfa2c91e3e9750a495857dc590a2eb61aecf65c4147536109663cd5c4430777b7321b842c990c27b7100794f8e4
7
- data.tar.gz: 34c271a32fe2bcad4048b5d2e0f8890bd24e5c3a968c7048c4b5ce0076f25554be1076929d25fd66e651d96c613857bf1a6a1142cd9c6f9f7e2b7ed2fe132586
6
+ metadata.gz: 7103a153d77be803ba028d2c5321cbb7a4ea76df9d77fe0a5d0922ef2bd8ab9f7ca27599a1466ed787f8f6e2e528589321c625aa8879a3c6b38cb8af418030fd
7
+ data.tar.gz: 0d52eed0528be475ae2346833af45d7df78fc54d2160467e80b614c45e5313ac1509042f47ae7eb9961006be26dc8d4a2e8bf04b1730a0ec2351fa88d34bd56a
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', '>0', require: false
14
- gem 'rubocop-performance', '>0', require: false
15
- gem 'rubocop-rake', '>0', require: false
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', '~>2.1', require: false
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
@@ -11,34 +11,34 @@ GEM
11
11
  public_suffix (>= 2.0.2, < 7.0)
12
12
  ansi (1.5.0)
13
13
  ast (2.4.3)
14
- bigdecimal (3.2.2)
14
+ bigdecimal (3.3.1)
15
15
  builder (3.3.0)
16
- crack (1.0.0)
16
+ crack (1.0.1)
17
17
  bigdecimal
18
18
  rexml
19
19
  docile (1.4.1)
20
- hashdiff (1.2.0)
21
- json (2.12.2)
20
+ hashdiff (1.2.1)
21
+ json (2.15.2)
22
22
  language_server-protocol (3.17.0.5)
23
23
  lint_roller (1.1.0)
24
- minitest (5.25.5)
24
+ minitest (5.26.2)
25
25
  minitest-reporters (1.7.1)
26
26
  ansi
27
27
  builder
28
28
  minitest (>= 5.0)
29
29
  ruby-progressbar
30
30
  parallel (1.27.0)
31
- parser (3.3.8.0)
31
+ parser (3.3.10.0)
32
32
  ast (~> 2.4.1)
33
33
  racc
34
- prism (1.4.0)
34
+ prism (1.5.2)
35
35
  public_suffix (6.0.2)
36
36
  racc (1.8.1)
37
37
  rainbow (3.1.1)
38
- rake (13.3.0)
39
- regexp_parser (2.10.0)
40
- rexml (3.4.1)
41
- rubocop (1.77.0)
38
+ rake (13.3.1)
39
+ regexp_parser (2.11.3)
40
+ rexml (3.4.4)
41
+ rubocop (1.81.7)
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.45.1, < 2.0)
49
+ rubocop-ast (>= 1.47.1, < 2.0)
50
50
  ruby-progressbar (~> 1.7)
51
51
  unicode-display_width (>= 2.4.0, < 4.0)
52
- rubocop-ast (1.45.1)
52
+ rubocop-ast (1.47.1)
53
53
  parser (>= 3.3.7.2)
54
54
  prism (~> 1.4)
55
- rubocop-minitest (0.38.1)
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.25.0)
59
+ rubocop-performance (1.26.1)
60
60
  lint_roller (~> 1.1)
61
61
  rubocop (>= 1.75.0, < 2.0)
62
- rubocop-ast (>= 1.38.0, < 2.0)
62
+ rubocop-ast (>= 1.47.1, < 2.0)
63
63
  rubocop-rake (0.7.1)
64
64
  lint_roller (~> 1.1)
65
65
  rubocop (>= 1.72.1)
@@ -68,20 +68,20 @@ GEM
68
68
  docile (~> 1.1)
69
69
  simplecov-html (~> 0.11)
70
70
  simplecov_json_formatter (~> 0.1)
71
- simplecov-cobertura (2.1.0)
71
+ simplecov-cobertura (3.1.0)
72
72
  rexml
73
73
  simplecov (~> 0.19)
74
- simplecov-html (0.13.1)
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.4)
78
- unicode-emoji (~> 4.0, >= 4.0.4)
79
- unicode-emoji (4.0.4)
80
- webmock (3.25.1)
77
+ unicode-display_width (3.2.0)
78
+ unicode-emoji (~> 4.1)
79
+ unicode-emoji (4.1.0)
80
+ webmock (3.26.1)
81
81
  addressable (>= 2.8.0)
82
82
  crack (>= 0.3.2)
83
83
  hashdiff (>= 0.4.0, < 2.0.0)
84
- yard (0.9.37)
84
+ yard (0.9.38)
85
85
 
86
86
  PLATFORMS
87
87
  aarch64-linux
@@ -99,11 +99,11 @@ DEPENDENCIES
99
99
  online!
100
100
  rake (~> 13.2)
101
101
  rubocop (~> 1.73)
102
- rubocop-minitest (> 0)
103
- rubocop-performance (> 0)
104
- rubocop-rake (> 0)
102
+ rubocop-minitest (~> 0.38)
103
+ rubocop-performance (~> 1.25)
104
+ rubocop-rake (~> 0.7)
105
105
  simplecov (~> 0.22)
106
- simplecov-cobertura (~> 2.1)
106
+ simplecov-cobertura (~> 3.0)
107
107
  webmock (~> 3.25)
108
108
  yard (~> 0.9)
109
109
 
data/README.md CHANGED
@@ -26,6 +26,35 @@ 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
+ You can specify HTTP timeout (in seconds) to prevent hanging on slow connections,
48
+ for example:
49
+
50
+ ```ruby
51
+ if online?(timeout: 2)
52
+ # We are online, if the timeout has not expired
53
+ end
54
+ ```
55
+
56
+ That's it.
57
+
29
58
  ## How to contribute
30
59
 
31
60
  Read
data/Rakefile CHANGED
@@ -33,6 +33,7 @@ require 'yard'
33
33
  desc 'Build Yard documentation'
34
34
  YARD::Rake::YardocTask.new do |t|
35
35
  t.files = ['lib/**/*.rb']
36
+ t.options = ['--fail-on-warning']
36
37
  end
37
38
 
38
39
  require 'rubocop/rake_task'
data/lib/online.rb CHANGED
@@ -30,8 +30,9 @@ module Kernel
30
30
  # for checking internet availability before performing network-dependent operations
31
31
  # or for implementing offline-mode functionality in applications.
32
32
  #
33
- # @param uri [String] the URI to check connectivity against (default: 'http://www.google.com')
33
+ # @param uri [String] the URI to check connectivity against (default: 'https://www.google.com/generate_204')
34
34
  # @param ttl [Integer] time-to-live for cached results in seconds (default: 300 seconds = 5 minutes)
35
+ # @param timeout [Integer] open, read and write HTTP timeout (default: 10 seconds)
35
36
  # @return [Boolean] true if the URI is reachable and returns HTTP success, false otherwise
36
37
  #
37
38
  # @example Basic usage - check internet connectivity
@@ -85,17 +86,29 @@ module Kernel
85
86
  # @note Returns false for any network-related errors including timeouts, DNS failures,
86
87
  # and unreachable hosts
87
88
  # @note Results are cached with a default TTL of 5 minutes to reduce network requests
88
- def online?(uri: 'http://www.google.com', ttl: 300)
89
+ def online?(uri: 'https://www.google.com/generate_204', ttl: 300, timeout: 10)
90
+ raise 'The URI is nil' if uri.nil?
91
+ raise 'The TTL is nil' if ttl.nil?
89
92
  key = uri.to_s
90
93
  OnlineOrOffline.mutex.synchronize do
91
94
  entry = OnlineOrOffline.cache[key]
92
95
  return entry[:status] if entry && (Time.now - entry[:time]) < ttl
96
+ uri = URI(uri) unless uri.is_a?(URI)
93
97
  status =
94
- Timeout.timeout(10) do
95
- Net::HTTP.get_response(URI(uri)).is_a?(Net::HTTPSuccess)
98
+ begin
99
+ Net::HTTP.start(
100
+ uri.hostname,
101
+ uri.port,
102
+ use_ssl: uri.scheme == 'https',
103
+ open_timeout: timeout,
104
+ read_timeout: timeout,
105
+ write_timeout: timeout
106
+ ) do |http|
107
+ http.request_get(uri, {}).is_a?(Net::HTTPSuccess)
108
+ end
96
109
  rescue \
97
- Timeout::Error, Timeout::ExitException, Socket::ResolutionError,
98
- Errno::EHOSTUNREACH, Errno::EINVAL, Errno::EADDRNOTAVAIL
110
+ Socket::ResolutionError, Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout,
111
+ Errno::EHOSTUNREACH, Errno::EINVAL, Errno::EADDRNOTAVAIL, Errno::EBADF
99
112
  false
100
113
  end
101
114
  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.1'
12
+ s.version = '0.2.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.1
4
+ version: 0.2.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.7
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
@@ -1,8 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
2
- # SPDX-License-Identifier: MIT
3
- ---
4
- errors:
5
- - yegor256@gmail.com
6
- # alerts:
7
- # github:
8
- # - yegor256
data/.gitattributes DELETED
@@ -1,7 +0,0 @@
1
- # Check out all text files in UNIX format, with LF as end of line
2
- # Don't change this file. If you have any ideas about it, please
3
- # submit a separate issue about it and we'll discuss.
4
-
5
- * text=auto eol=lf
6
- *.java ident
7
- *.xml ident
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,13 +0,0 @@
1
-
2
- .bundle/
3
- .DS_Store
4
- .idea/
5
- .yardoc/
6
- *.gem
7
- **/.claude/settings.local.json
8
- coverage/
9
- doc/
10
- node_modules/
11
- rdoc/
12
- temp/
13
- vendor/
data/.pdd DELETED
@@ -1,7 +0,0 @@
1
- --source=.
2
- --verbose
3
- --exclude target/**/*
4
- --exclude coverage/**/*
5
- --rule min-words:20
6
- --rule min-estimate:15
7
- --rule max-estimate:90
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
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": [
4
- "config:base"
5
- ]
6
- }
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