online 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5c935181fd3681e830413f863498954281f1f498b5456a5920cb89937d4780b
4
+ data.tar.gz: f22371f34837a12d6efaf0b5491820606139ab68e7921b75720bea78d3150951
5
+ SHA512:
6
+ metadata.gz: d75348162f7d9de1725c54bedff46f5b7ddaccfa2c91e3e9750a495857dc590a2eb61aecf65c4147536109663cd5c4430777b7321b842c990c27b7100794f8e4
7
+ data.tar.gz: 34c271a32fe2bcad4048b5d2e0f8890bd24e5c3a968c7048c4b5ce0076f25554be1076929d25fd66e651d96c613857bf1a6a1142cd9c6f9f7e2b7ed2fe132586
data/.0pdd.yml ADDED
@@ -0,0 +1,8 @@
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 ADDED
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,25 @@
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 }}
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,19 @@
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 ADDED
@@ -0,0 +1,13 @@
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 ADDED
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,53 @@
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 ADDED
@@ -0,0 +1,26 @@
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/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ source 'https://rubygems.org'
7
+ gemspec
8
+
9
+ gem 'minitest', '~>5.25', require: false
10
+ gem 'minitest-reporters', '~>1.7', require: false
11
+ gem 'rake', '~>13.2', require: false
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
16
+ gem 'simplecov', '~>0.22', require: false
17
+ gem 'simplecov-cobertura', '~>2.1', require: false
18
+ gem 'webmock', '~>3.25', require: false
19
+ gem 'yard', '~>0.9', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ online (0.0.0)
5
+ timeout (~> 0.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.7)
11
+ public_suffix (>= 2.0.2, < 7.0)
12
+ ansi (1.5.0)
13
+ ast (2.4.3)
14
+ bigdecimal (3.2.2)
15
+ builder (3.3.0)
16
+ crack (1.0.0)
17
+ bigdecimal
18
+ rexml
19
+ docile (1.4.1)
20
+ hashdiff (1.2.0)
21
+ json (2.12.2)
22
+ language_server-protocol (3.17.0.5)
23
+ lint_roller (1.1.0)
24
+ minitest (5.25.5)
25
+ minitest-reporters (1.7.1)
26
+ ansi
27
+ builder
28
+ minitest (>= 5.0)
29
+ ruby-progressbar
30
+ parallel (1.27.0)
31
+ parser (3.3.8.0)
32
+ ast (~> 2.4.1)
33
+ racc
34
+ prism (1.4.0)
35
+ public_suffix (6.0.2)
36
+ racc (1.8.1)
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)
42
+ json (~> 2.3)
43
+ language_server-protocol (~> 3.17.0.2)
44
+ lint_roller (~> 1.1.0)
45
+ parallel (~> 1.10)
46
+ parser (>= 3.3.0.2)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ regexp_parser (>= 2.9.3, < 3.0)
49
+ rubocop-ast (>= 1.45.1, < 2.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 2.4.0, < 4.0)
52
+ rubocop-ast (1.45.1)
53
+ parser (>= 3.3.7.2)
54
+ prism (~> 1.4)
55
+ rubocop-minitest (0.38.1)
56
+ lint_roller (~> 1.1)
57
+ rubocop (>= 1.75.0, < 2.0)
58
+ rubocop-ast (>= 1.38.0, < 2.0)
59
+ rubocop-performance (1.25.0)
60
+ lint_roller (~> 1.1)
61
+ rubocop (>= 1.75.0, < 2.0)
62
+ rubocop-ast (>= 1.38.0, < 2.0)
63
+ rubocop-rake (0.7.1)
64
+ lint_roller (~> 1.1)
65
+ rubocop (>= 1.72.1)
66
+ ruby-progressbar (1.13.0)
67
+ simplecov (0.22.0)
68
+ docile (~> 1.1)
69
+ simplecov-html (~> 0.11)
70
+ simplecov_json_formatter (~> 0.1)
71
+ simplecov-cobertura (2.1.0)
72
+ rexml
73
+ simplecov (~> 0.19)
74
+ simplecov-html (0.13.1)
75
+ simplecov_json_formatter (0.1.4)
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)
81
+ addressable (>= 2.8.0)
82
+ crack (>= 0.3.2)
83
+ hashdiff (>= 0.4.0, < 2.0.0)
84
+ yard (0.9.37)
85
+
86
+ PLATFORMS
87
+ aarch64-linux
88
+ arm-linux
89
+ arm64-darwin
90
+ arm64-darwin-23
91
+ x64-mingw-ucrt
92
+ x86-linux
93
+ x86_64-darwin
94
+ x86_64-linux
95
+
96
+ DEPENDENCIES
97
+ minitest (~> 5.25)
98
+ minitest-reporters (~> 1.7)
99
+ online!
100
+ rake (~> 13.2)
101
+ rubocop (~> 1.73)
102
+ rubocop-minitest (> 0)
103
+ rubocop-performance (> 0)
104
+ rubocop-rake (> 0)
105
+ simplecov (~> 0.22)
106
+ simplecov-cobertura (~> 2.1)
107
+ webmock (~> 3.25)
108
+ yard (~> 0.9)
109
+
110
+ BUNDLED WITH
111
+ 2.5.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Ruby Function to Check If We Are Currently Online
2
+
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/online)](https://www.rultor.com/p/yegor256/online)
4
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
+
6
+ [![rake](https://github.com/yegor256/online/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/online/actions/workflows/rake.yml)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/online)](https://www.0pdd.com/p?name=yegor256/online)
8
+ [![Gem Version](https://badge.fury.io/rb/online.svg)](https://badge.fury.io/rb/online)
9
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/online.svg)](https://codecov.io/github/yegor256/online?branch=master)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/online/master/frames)
11
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/online)](https://hitsofcode.com/view/github/yegor256/online)
12
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/online/blob/master/LICENSE.txt)
13
+
14
+ First, install it:
15
+
16
+ ```bash
17
+ gem install online
18
+ ```
19
+
20
+ Then, you can use the `online?` global function:
21
+
22
+ ```ruby
23
+ require 'online'
24
+ if online?
25
+ # do some LIVE testing
26
+ end
27
+ ```
28
+
29
+ ## How to contribute
30
+
31
+ Read
32
+ [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
33
+ Make sure your build is green before you contribute
34
+ your pull request. You will need to have
35
+ [Ruby](https://www.ruby-lang.org/en/) 3.0+ and
36
+ [Bundler](https://bundler.io/) installed. Then:
37
+
38
+ ```bash
39
+ bundle update
40
+ bundle exec rake
41
+ ```
42
+
43
+ If it's clean and you don't see any error messages, submit your pull request.
data/REUSE.toml ADDED
@@ -0,0 +1,35 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.png",
14
+ "**.txt",
15
+ "**/.DS_Store",
16
+ "**/.gitignore",
17
+ "**/.pdd",
18
+ "**/*.csv",
19
+ "**/*.jpg",
20
+ "**/*.json",
21
+ "**/*.md",
22
+ "**/*.pdf",
23
+ "**/*.png",
24
+ "**/*.svg",
25
+ "**/*.txt",
26
+ "**/*.vm",
27
+ "**/CNAME",
28
+ "**/Gemfile.lock",
29
+ "Gemfile.lock",
30
+ "README.md",
31
+ "renovate.json",
32
+ ]
33
+ precedence = "override"
34
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
35
+ SPDX-License-Identifier = "MIT"
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+
10
+ def name
11
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
12
+ end
13
+
14
+ def version
15
+ Gem::Specification.load(Dir['*.gemspec'].first).version
16
+ end
17
+
18
+ ENV['RACK_ENV'] = 'test'
19
+
20
+ task default: %i[clean test rubocop yard]
21
+
22
+ require 'rake/testtask'
23
+ desc 'Run all unit tests'
24
+ Rake::TestTask.new(:test) do |test|
25
+ Rake::Cleaner.cleanup_files(['coverage'])
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.warning = true
29
+ test.verbose = false
30
+ end
31
+
32
+ require 'yard'
33
+ desc 'Build Yard documentation'
34
+ YARD::Rake::YardocTask.new do |t|
35
+ t.files = ['lib/**/*.rb']
36
+ end
37
+
38
+ require 'rubocop/rake_task'
39
+ desc 'Run RuboCop on all directories'
40
+ RuboCop::RakeTask.new(:rubocop) do |task|
41
+ task.fail_on_error = true
42
+ end
data/lib/online.rb ADDED
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'net/http'
7
+ require 'socket'
8
+ require 'timeout'
9
+ require 'uri'
10
+
11
+ # Checks whether we are online now.
12
+ #
13
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
14
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
15
+ # License:: MIT
16
+ module Kernel
17
+ # Cache for online connectivity checks
18
+ module OnlineOrOffline
19
+ class << self
20
+ attr_accessor :cache, :mutex
21
+ end
22
+ @cache = {}
23
+ @mutex = Mutex.new
24
+ end
25
+
26
+ # Checks whether the system has an active internet connection by attempting
27
+ # to connect to a specified URI.
28
+ #
29
+ # This method performs an HTTP GET request to verify connectivity. It's useful
30
+ # for checking internet availability before performing network-dependent operations
31
+ # or for implementing offline-mode functionality in applications.
32
+ #
33
+ # @param uri [String] the URI to check connectivity against (default: 'http://www.google.com')
34
+ # @param ttl [Integer] time-to-live for cached results in seconds (default: 300 seconds = 5 minutes)
35
+ # @return [Boolean] true if the URI is reachable and returns HTTP success, false otherwise
36
+ #
37
+ # @example Basic usage - check internet connectivity
38
+ # if online?
39
+ # puts "Connected to the internet!"
40
+ # else
41
+ # puts "No internet connection available"
42
+ # end
43
+ #
44
+ # @example Check connectivity to a specific service
45
+ # if online?('https://api.github.com')
46
+ # # Proceed with GitHub API calls
47
+ # else
48
+ # # Use cached data or show offline message
49
+ # end
50
+ #
51
+ # @example Check with custom cache TTL (10 minutes)
52
+ # if online?(ttl: 600)
53
+ # # Will use cached result for 10 minutes
54
+ # end
55
+ #
56
+ # @example Use in Minitest tests
57
+ # require 'minitest/autorun'
58
+ # require 'online'
59
+ #
60
+ # class MyServiceTest < Minitest::Test
61
+ # def test_api_call_when_online
62
+ # skip("No internet connection") unless online?
63
+ # # Test code that requires internet
64
+ # end
65
+ #
66
+ # def test_offline_fallback
67
+ # unless online?
68
+ # assert_equal cached_data, service.fetch_data
69
+ # end
70
+ # end
71
+ # end
72
+ #
73
+ # @example Conditional feature loading
74
+ # class WeatherWidget
75
+ # def display
76
+ # if online?('https://api.weather.com')
77
+ # show_live_weather
78
+ # else
79
+ # show_cached_weather
80
+ # end
81
+ # end
82
+ # end
83
+ #
84
+ # @note The method has a 10-second timeout to prevent hanging on slow connections
85
+ # @note Returns false for any network-related errors including timeouts, DNS failures,
86
+ # and unreachable hosts
87
+ # @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
+ key = uri.to_s
90
+ OnlineOrOffline.mutex.synchronize do
91
+ entry = OnlineOrOffline.cache[key]
92
+ return entry[:status] if entry && (Time.now - entry[:time]) < ttl
93
+ status =
94
+ Timeout.timeout(10) do
95
+ Net::HTTP.get_response(URI(uri)).is_a?(Net::HTTPSuccess)
96
+ rescue \
97
+ Timeout::Error, Timeout::ExitException, Socket::ResolutionError,
98
+ Errno::EHOSTUNREACH, Errno::EINVAL, Errno::EADDRNOTAVAIL
99
+ false
100
+ end
101
+ OnlineOrOffline.cache[key] = { status: status, time: Time.now }
102
+ status
103
+ end
104
+ end
105
+ end
data/online.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'English'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
+ s.required_ruby_version = '>=3.2'
11
+ s.name = 'online'
12
+ s.version = '0.0.1'
13
+ s.license = 'MIT'
14
+ s.summary = 'Checks whether we are currently online or offline'
15
+ s.description =
16
+ 'Provides a predicate that checks whether your machine is currently
17
+ online or offline, which may be useful for unit and integration tests.'
18
+ s.authors = ['Yegor Bugayenko']
19
+ s.email = 'yegor256@gmail.com'
20
+ s.homepage = 'https://github.com/yegor256/online'
21
+ s.files = `git ls-files`.split($RS)
22
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ s.rdoc_options = ['--charset=UTF-8']
24
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
25
+ s.add_dependency 'timeout', '~>0.4'
26
+ s.metadata['rubygems_mfa_required'] = 'true'
27
+ end
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
@@ -0,0 +1,31 @@
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]
@@ -0,0 +1,56 @@
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
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: online
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: timeout
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.4'
26
+ description: |-
27
+ Provides a predicate that checks whether your machine is currently
28
+ online or offline, which may be useful for unit and integration tests.
29
+ email: yegor256@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE.txt
34
+ - README.md
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
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - LICENSES/MIT.txt
56
+ - README.md
57
+ - REUSE.toml
58
+ - Rakefile
59
+ - lib/online.rb
60
+ - online.gemspec
61
+ - renovate.json
62
+ - test/test__helper.rb
63
+ - test/test_online.rb
64
+ homepage: https://github.com/yegor256/online
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ rubygems_mfa_required: 'true'
69
+ rdoc_options:
70
+ - "--charset=UTF-8"
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '3.2'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.6.7
85
+ specification_version: 4
86
+ summary: Checks whether we are currently online or offline
87
+ test_files: []