Tnt
A libary for programmers who like things that go boom. I found myself creating a lot of error classes. I usually wanted to customize the message or simply the superclass. It was tiring. Enter Tnt. Tnt is micro library for writing useable and informative error messages.
Installation
Add this line to your application's Gemfile:
gem 'tnt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tnt
Usage
require 'tnt'
# Customize the message
ConstraintError = Tnt.boom "Domain constraints invalidated"
fail ConstraintError #=> ConstraintError: Domain constraints invalidated
# Pass arguments
ConstraintError = Tnt.boom do |subject, rule|
"#{subject} violated #{rule}!"
end
fail ConstraintError.new(:person, :age) #=> ConstraintError: :person violated age!
# Pass a superclass
PartialError = Tnt.boom NotImplementedError do |object, method|
"#{object} does not respond to #{method}"
end
# If you just need a new class
SampleError = Tnt.boom StandardError
# For the really lazy
SampleError = Tnt.boom
That's all there is too it. I use the first two forms most of the time. The final form is handy for the lazy programmers. I prefer it.
Contributing
- Fork it ( https://github.com/[my-github-username]/tnt/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