An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

Tryout [![Build Status](https://secure.travis-ci.org/endel/tryout.png)](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.