PassAttempt
PassAttempt run a block depending on a condition.
Super simple Singleton with counter by name, that process a block. when condition is true.
I wrote this gem in order to avoid fill my exception_notification service.
Installation
Add this line to your application's Gemfile:
gem 'pass_attempt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pass_attempt
Usage
name = 'my_filtred_acction'
condition = ->(attempts) { attempts.odd? }
(1..4).each do |i|
PassAttempt.try(name, condition) do
puts "my_filtred_acction #{i}"
end
end
my_filtred_acction 1
my_filtred_acction 3
Condition can be a proc that receive counter for name and return boolean.
Also condition can be a symbol (:log2 or :log10), to be used as test of counter of name.
Contributing
- Fork it ( https://github.com/alejandrobabio/pass_attempt/fork )
- 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 a new Pull Request