Project

online

0.0
No release in over 3 years
Provides a predicate that checks whether your machine is currently online or offline, which may be useful for unit and integration tests.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 0.4
 Project Readme

Ruby Function to Check If We Are Currently Online

DevOps By Rultor.com We recommend RubyMine

rake PDD status Gem Version Test Coverage Yard Docs Hits-of-Code License

First, install it:

gem install online

Then, you can use the online? global function:

require 'online'
if online?
  # do some LIVE testing
end

You can also check a particular URL:

if online?(uri: 'https://api.github.com')
  # GitHub API is accessible
end

The online?() function doesn't make an HTTP request on each call, but instead caches the previous result for five minutes. You can change this interval to three seconds, for example:

if online?(ttl: 3)
  # We are online, let's run integration tests!
end

That's it.

How to contribute

Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then:

bundle update
bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.