Project

tnt

0.01
No commit activity in last 3 years
No release in over 3 years
Make understanable Error classes easily
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
 Project Readme

Tnt

Build Status

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

  1. Fork it ( https://github.com/[my-github-username]/tnt/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request