Insouciant
Now I recognize that sound computer science practices dictate that all code should always strive to handle, on some level, all exceptions that may come up.
The reality is there are cases when you may not be aware, let alone in control of all the possible sources of errors. Sometimes, it would be nice to have your troublesome code run, and NOT bring the house down because some host is unreachable or some other error beyond your control.
The insouciant gem allows for just such a use case.
The single method in this gem, Object::insouciant allows code to be run in a simple and care free manner.
Now for some back story. In 2014, I had the wonderful experience of visiting Germany for a cruise on the Elbe river. One of the stops was the Sanssouci palace in Potsdam near Berlin. The palace was the refuge of Frederick the Great, King of Prussia. A safe place without the worries, stress or concerns of that troubled man.
In English this is translated as "insouciant" and is the inspiration for this gem.
Installation
Add this line to your application's Gemfile:
gem 'insouciant'
And then execute:
$ bundle
Or install it yourself as:
$ gem install insouciant
Usage
To use this gem simply:
require 'insouciant'
Then, wherever dodgy code may lurk, render it worry free. For example:
insouciant {latest_version_for("mysh").to_s}
If an error should occur, the error string of the exception will be returned. You may also choose to specify an alternate return value:
insouciant("<Error>") {latest_version_for("mysh").to_s}
And that is it. Compact, easy-to-use, easy-to-deal-with, and above all, trouble and worry free!
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
OR...
- Make a suggestion by raising an issue . All ideas and comments are welcome.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the pause_output project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.