Skip to content
/ tnt Public
forked from ahawkins/tnt

Make understandable and actionable error classes easily

License

Notifications You must be signed in to change notification settings

krisleech/tnt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Make understandable and actionable error classes easily

Resources

License

Stars

Watchers

Forks

Packages

No packages published