tnt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/lib/tnt.rb +26 -0
- data/lib/tnt/version.rb +3 -0
- data/test/acceptance_test.rb +42 -0
- data/test/test_helper.rb +3 -0
- data/tnt.gemspec +23 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d7d07e1d384061a1b8aec031ab7b24339124f94
|
4
|
+
data.tar.gz: a9790bb418b1ddb14b9c40cca2db9d834fc4d1de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca1b28a36a3f1810ab47f9449ae8972aef69062a2b231df75e65c3d25b87a5ebb438e6da38ef00b337b9de7f54f5ac045095f1dabb97e8626264e186b2edea5f
|
7
|
+
data.tar.gz: 491031c33b431b7d67aff0bb01429ce2435247ae685d835917dcaa61dfe5414e3fcedf2dc6acc479841a824860e37c52531a2141c03c34f1141a847c979d89ab
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ahawkins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Tnt
|
2
|
+
|
3
|
+
[](https://travis-ci.org/ahawkins/tnt)
|
4
|
+
|
5
|
+
A libary for programmers who like things that go boom. I found myself
|
6
|
+
creating a lot of error classes. I usually wanted to customize the
|
7
|
+
message or simply the superclass. It was tiring. Enter Tnt. Tnt is
|
8
|
+
micro library for writing useable and informative error messages.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'tnt'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install tnt
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'tnt'
|
28
|
+
|
29
|
+
# Customize the message
|
30
|
+
ConstraintError = Tnt.boom "Domain constraints invalidated"
|
31
|
+
fail ConstraintError #=> ConstraintError: Domain constraints invalidated
|
32
|
+
|
33
|
+
# Pass arguments
|
34
|
+
ConstraintError = Tnt.boom do |subject, rule|
|
35
|
+
"#{subject} violated #{rule}!"
|
36
|
+
end
|
37
|
+
fail ConstraintError.new(:person, :age) #=> ConstraintError: :person violated age!
|
38
|
+
|
39
|
+
# Pass a superclass
|
40
|
+
PartialError = Tnt.boom NotImplementedError do |object, method|
|
41
|
+
"#{object} does not respond to #{method}"
|
42
|
+
end
|
43
|
+
|
44
|
+
# If you just need a new class
|
45
|
+
SampleError = Tnt.boom StandardError
|
46
|
+
|
47
|
+
# For the really lazy
|
48
|
+
SampleError = Tnt.boom
|
49
|
+
```
|
50
|
+
|
51
|
+
That's all there is too it. I use the first two forms most of the
|
52
|
+
time. The final form is handy for the lazy programmers. I prefer it.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/[my-github-username]/tnt/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/tnt.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "tnt/version"
|
2
|
+
|
3
|
+
module Tnt
|
4
|
+
class << self
|
5
|
+
def boom(super_class_or_message = StandardError)
|
6
|
+
if super_class_or_message.is_a? Class
|
7
|
+
Class.new super_class_or_message do
|
8
|
+
define_method :initialize do |*args|
|
9
|
+
if block_given?
|
10
|
+
message = yield *args
|
11
|
+
super message
|
12
|
+
else
|
13
|
+
super *args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
Class.new StandardError do
|
19
|
+
define_method :initialize do |*args|
|
20
|
+
super super_class_or_message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/tnt/version.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ErrorTest < MiniTest::Unit::TestCase
|
4
|
+
def test_error_builder_sets_the_message_from_the_args
|
5
|
+
klass = Tnt.boom do |foo|
|
6
|
+
"#{foo} bar"
|
7
|
+
end
|
8
|
+
|
9
|
+
error = klass.new "Adam"
|
10
|
+
assert_equal "Adam bar", error.message
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_argument_is_not_required
|
14
|
+
klass = Tnt.boom NotImplementedError do
|
15
|
+
"super duper!"
|
16
|
+
end
|
17
|
+
|
18
|
+
error = klass.new
|
19
|
+
assert_equal "super duper!", error.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_simple_failure_messages_can_be_given_as_the_argument
|
23
|
+
klass = Tnt.boom "test error"
|
24
|
+
|
25
|
+
error = klass.new
|
26
|
+
assert_equal "test error", error.message
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_errors_without_arguments_can_be_used_like_normal
|
30
|
+
klass = Tnt.boom
|
31
|
+
|
32
|
+
error = assert_raises klass do
|
33
|
+
fail klass, "test"
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_equal 'test', error.message
|
37
|
+
|
38
|
+
assert_raises klass do
|
39
|
+
fail klass
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/test_helper.rb
ADDED
data/tnt.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tnt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tnt"
|
8
|
+
spec.version = Tnt::VERSION
|
9
|
+
spec.authors = ["ahawkins"]
|
10
|
+
spec.email = ["adam@hawkins.io"]
|
11
|
+
spec.summary = %q{Make understanable Error classes easily}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/ahawkins/tnt"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tnt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ahawkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- adam@hawkins.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/tnt.rb
|
55
|
+
- lib/tnt/version.rb
|
56
|
+
- test/acceptance_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- tnt.gemspec
|
59
|
+
homepage: https://github.com/ahawkins/tnt
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Make understanable Error classes easily
|
83
|
+
test_files:
|
84
|
+
- test/acceptance_test.rb
|
85
|
+
- test/test_helper.rb
|