https://github.com/endel/tryout
Clean begin/rescue/retry utility.
https://github.com/endel/tryout
Last synced: 12 months ago
JSON representation
Clean begin/rescue/retry utility.
- Host: GitHub
- URL: https://github.com/endel/tryout
- Owner: endel
- License: mit
- Created: 2012-12-13T23:27:56.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-02-01T20:51:41.000Z (over 13 years ago)
- Last Synced: 2025-05-08T22:34:01.044Z (about 1 year ago)
- Language: Ruby
- Homepage: rubygems.org/gems/tryout
- Size: 109 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Tryout [](http://travis-ci.org/endel/tryout)
===
Allows you to do dirty stuff without messing up your code base.
Background
---
I've found myself using begin/rescue/retry through HTTP requests frequently, due
timeout, weird stuff caused by a messed up third-party service, or even due
internet connectivity lost.
How to use
---
value = Tryout.try { RestClient.get('http://www.google.com') }.retry(3)
**if/unless**: call any method on the result of the `try` block.
value = Tryout.try { RestClient.get('http://www.google.com') }.retry(3, :if => :empty?)
value = Tryout.try { RestClient.get('http://www.google.com') }.retry(3, :unless => :present?)
**block**: the result of the `try` block will be passed as argument for the second one.
Is up to you when the result is considered invalid.
value = Tryout.try { RestClient.get('http://www.google.com') }.retry(3) do |invalid|
# Invalidate when response have length lesser than 100
invalid.length < 100
end
License
---
Tryout is released under the MIT license. Please read the LICENSE file.