braise 0.1.0 → 1.0.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 +8 -8
- data/.rspec +2 -0
- data/README.md +46 -10
- data/braise.gemspec +4 -2
- data/{example/braise_example.rb → examples/braise_usage.rb} +1 -2
- data/examples/craise_usage.rb +14 -0
- data/lib/braise.rb +25 -18
- data/lib/braise/version.rb +1 -1
- data/spec/braise_spec.rb +104 -0
- data/spec/spec_helper.rb +8 -0
- metadata +26 -7
- data/example/craise_example.rb +0 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGI0MzZlMDcwYTE5MzcyYTJiYTUwYWQ0MDU1M2Q1NzdkYWQ4M2U2OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzM5YTViMTEwNGY5NjdlOTE3MzdkYzhkMTllMjBjYzRlYWVmMjY0MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmFhYzVlZWQ5NTU0NDEwMGIxNWU2ZDkxOWE1N2Y4ZmVkMmM3M2YwYTFhZjAz
|
10
|
+
ZDAwOTBkYWM3MjdjYTFkZjM1Y2E4YzM3YmRmMzAzYzg0N2E4MDUxMTAzY2Qz
|
11
|
+
NDlmOTNlOWU2ZTExNjM1YzYxMzQwNjc4YmRkNzczMWE0MWQyZjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGM0NGM3Y2FmOWJmODJiYjM3MGQ2MTJhYzg3MGE5YjZlY2JhMjFlNjYxNTUy
|
14
|
+
ODcwMDQ5NDE4ZTMxZjEwMjc2YmExNDk2ZjIyMDBmMDU0YjcwOWYzOWFkZDk2
|
15
|
+
YThkMDBhZjk5NzVlMjIyNTA0MjU2OGQwZjQzNjU4MTM5ODIyOWQ=
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,27 +1,63 @@
|
|
1
1
|
# Braise
|
2
2
|
|
3
|
-
|
3
|
+
Braise is a tool to help debug ruby applications by providing shortcuts for the `raise` method.
|
4
4
|
|
5
|
-
|
5
|
+
Braise comes with 2 helper methods, `braise` and `craise`.
|
6
6
|
|
7
|
-
|
7
|
+
`braise` (short for *brief raise*) eliminates the need for calling inspect on an object
|
8
|
+
```
|
9
|
+
braise obj # is equivalent to "raise obj.inspect"
|
10
|
+
```
|
8
11
|
|
9
|
-
|
12
|
+
`craise` (short for *colorful raise*) allows you to specify options for coloring terminal output
|
13
|
+
```
|
14
|
+
# will raise an exception using white text on a red background for terminal output
|
15
|
+
# this is equivalent to "raise ANSI.white_on_red obj.inspect"
|
16
|
+
craise obj
|
17
|
+
```
|
10
18
|
|
11
|
-
|
19
|
+
Braise uses the [ansi](https://github.com/rubyworks/ansi) gem for specifying font color on the terminal. See ansi's [documentation](http://rubydoc.info/github/rubyworks/ansi/master/ANSI/Mixin) for a full list of available color schemes.
|
12
20
|
|
13
|
-
|
21
|
+
## Installation
|
22
|
+
### Ruby applications
|
23
|
+
On the command line, simply run:
|
24
|
+
```
|
25
|
+
$ gem install braise
|
26
|
+
```
|
14
27
|
|
15
|
-
|
28
|
+
Then in the ruby program, require braise:
|
29
|
+
```
|
30
|
+
require 'braise'
|
31
|
+
```
|
16
32
|
|
17
|
-
|
33
|
+
See the `examples` folder for specific examples of the `braise` and `craise` methods.
|
18
34
|
|
19
|
-
|
35
|
+
### Rails applications
|
36
|
+
It is recommended that you put the braise gem in the `:development` group of the Gemfile:
|
37
|
+
```
|
38
|
+
group :development do
|
39
|
+
# ...other development gems
|
40
|
+
gem 'braise'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
The gem will still work if you add it to top level of the Gemfile, but probably shouldn't be since Braise is intended to be used as a debugging tool.
|
45
|
+
|
46
|
+
Then bundle per usual:
|
47
|
+
|
48
|
+
$ bundle
|
20
49
|
|
21
|
-
|
50
|
+
If you'd like to override the default color scheme or set additional flags, you can use an initializer like `/config/initializers/braise.rb` :
|
51
|
+
```
|
52
|
+
if defined?(Braise) # check to make Braise is defined in the current environment
|
53
|
+
# override the default color scheme, use white_on_green
|
54
|
+
Braise::Settings.configure({:color => ANSI.white_on_green})
|
55
|
+
end
|
56
|
+
```
|
22
57
|
|
23
58
|
## Contributing
|
24
59
|
|
60
|
+
0. Check to see if the issue exists in the project's [tracker](https://github.com/MrAlexLau/braise/issues).
|
25
61
|
1. Fork it
|
26
62
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
63
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/braise.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "braise"
|
8
8
|
spec.version = Braise::VERSION
|
9
9
|
spec.authors = ["Alex Lau"]
|
10
|
-
spec.description = "
|
11
|
-
spec.summary = "
|
10
|
+
spec.description = "Syntatic sugar for the raise method"
|
11
|
+
spec.summary = "Shortcuts `raise obj.inspect` and makes it easy to add color terminal output"
|
12
12
|
spec.homepage = "https://github.com/MrAlexLau/braise"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -19,5 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
21
|
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
|
22
24
|
spec.add_dependency "ansi"
|
23
25
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'braise'
|
2
|
+
require 'ansi'
|
3
|
+
|
4
|
+
include Braise
|
5
|
+
|
6
|
+
arr = [1, 2, 3]
|
7
|
+
|
8
|
+
# Braise.configure({:color => ANSI.red}) # set default font color to red
|
9
|
+
# Braise.configure({:color => ANSI.on_green}) # set default background color to green
|
10
|
+
Braise.configure({:color => ANSI.white_on_yellow}) # set default font color to white and background color to yellow
|
11
|
+
|
12
|
+
# raise an exception that writes colorful output to the terminal
|
13
|
+
# equivalent to "raise ANSI.on_green arr.inspect"
|
14
|
+
craise arr
|
data/lib/braise.rb
CHANGED
@@ -1,32 +1,39 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'braise/version'
|
2
|
+
require 'ansi'
|
3
3
|
|
4
4
|
module Braise
|
5
|
-
|
6
|
-
|
5
|
+
class Settings
|
6
|
+
@@config = { :color => ANSI.white_on_red,
|
7
|
+
:additional_flags => '' }
|
7
8
|
|
8
|
-
|
9
|
+
@@valid_config_keys = @@config.keys
|
10
|
+
|
11
|
+
def self.get_options(opts={})
|
12
|
+
Settings.stringify_options(@@config.merge(opts))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure(opts={})
|
16
|
+
opts.each {|k,v| @@config[k.to_sym] = v if @@valid_config_keys.include? k.to_sym}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.stringify_options(opts)
|
22
|
+
return opts.values.join(' ').strip
|
23
|
+
end
|
24
|
+
end
|
9
25
|
|
10
26
|
# brief raise
|
11
27
|
def braise(obj)
|
12
28
|
raise obj.inspect
|
13
29
|
end
|
14
30
|
|
15
|
-
#
|
31
|
+
# colorful raise
|
16
32
|
def craise(obj, opts={})
|
17
|
-
opts_str =
|
33
|
+
opts_str = Settings.get_options(opts)
|
18
34
|
|
19
35
|
raise (opts_str + obj.inspect + ANSI.clear)
|
20
36
|
end
|
21
|
-
|
22
|
-
def configure(opts={})
|
23
|
-
opts.each {|k,v| @@config[k.to_sym] = v if @@valid_config_keys.include? k.to_sym}
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def stringify_options(opts_hash)
|
29
|
-
return opts_hash.inject(""){|result, pair| result.to_s + " " + pair[1].to_s}.strip
|
30
|
-
end
|
31
|
-
|
32
37
|
end
|
38
|
+
|
39
|
+
include Braise
|
data/lib/braise/version.rb
CHANGED
data/spec/braise_spec.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Braise
|
3
|
+
|
4
|
+
describe Braise do
|
5
|
+
before(:each) do
|
6
|
+
@@config = { :color => ANSI.white_on_red, :additional_flags => "" }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'braise' do
|
10
|
+
it 'should raise an exception on an inspected array' do
|
11
|
+
arr = [1, 2]
|
12
|
+
|
13
|
+
begin
|
14
|
+
braise arr
|
15
|
+
rescue Exception => e
|
16
|
+
e.message.should eq(arr.inspect)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end # end braise
|
20
|
+
|
21
|
+
describe 'craise' do
|
22
|
+
it 'should raise an exception with colorful font on an inspected array' do
|
23
|
+
arr = [1, 2]
|
24
|
+
|
25
|
+
begin
|
26
|
+
craise arr
|
27
|
+
rescue Exception => e
|
28
|
+
e.message.should eq(ANSI.white_on_red + arr.inspect + ANSI.clear)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise an exception with a green background' do
|
33
|
+
Braise::Settings.configure({:color => ANSI.green})
|
34
|
+
arr = [1, 2]
|
35
|
+
|
36
|
+
begin
|
37
|
+
craise arr
|
38
|
+
rescue Exception => e
|
39
|
+
e.message.should eq(ANSI.green + arr.inspect + ANSI.clear)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end # end craise
|
43
|
+
|
44
|
+
|
45
|
+
describe 'Settings' do
|
46
|
+
describe 'configure' do
|
47
|
+
it 'should set color option' do
|
48
|
+
# white_on_red is the default color scheme
|
49
|
+
Braise::Settings.get_options().should eq(ANSI.white_on_red)
|
50
|
+
|
51
|
+
# example background color
|
52
|
+
Braise::Settings.configure({:color => ANSI.on_green})
|
53
|
+
Braise::Settings.get_options().should eq(ANSI.on_green)
|
54
|
+
|
55
|
+
# example font color
|
56
|
+
Braise::Settings.configure({:color => ANSI.red})
|
57
|
+
Braise::Settings.get_options().should eq(ANSI.red)
|
58
|
+
|
59
|
+
# example mixed color
|
60
|
+
Braise::Settings.configure({:color => ANSI.black_on_yellow})
|
61
|
+
Braise::Settings.get_options().should eq(ANSI.black_on_yellow)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should set additional_flags option' do
|
65
|
+
opts_before = Braise::Settings.get_options()
|
66
|
+
additional_opts = 'any other option'
|
67
|
+
|
68
|
+
# example background additional_flags
|
69
|
+
Braise::Settings.configure({:additional_flags => additional_opts})
|
70
|
+
Braise::Settings.get_options().should eq("#{opts_before} #{additional_opts}")
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should set both options at once' do
|
74
|
+
additional_opts = 'any other option'
|
75
|
+
|
76
|
+
Braise::Settings.get_options().should_not eq("#{ANSI.blue} #{additional_opts}")
|
77
|
+
Braise::Settings.configure({:color => ANSI.blue, :additional_flags => additional_opts})
|
78
|
+
Braise::Settings.get_options().should eq("#{ANSI.blue} #{additional_opts}")
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should not set key with invalid name' do
|
82
|
+
invalid_string = 'a string'
|
83
|
+
opts_before = Braise::Settings.get_options()
|
84
|
+
|
85
|
+
Braise::Settings.configure({:invalid_key => invalid_string})
|
86
|
+
Braise::Settings.get_options().index(invalid_string).should be_nil
|
87
|
+
end
|
88
|
+
end # end configure
|
89
|
+
|
90
|
+
describe 'stringify_options' do
|
91
|
+
it 'should convert empty hash to empty string' do
|
92
|
+
Braise::Settings.stringify_options({}).should be_empty
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should convert options hash to string' do
|
96
|
+
# results should be separated by spaces
|
97
|
+
Braise::Settings.stringify_options({:key1 => 'value1', :key2 => 'value2'}).should eq('value1 value2')
|
98
|
+
Braise::Settings.stringify_options({:key1 => 'value1', :key2 => 'value2', :key3 => 'value3'}).should eq('value1 value2 value3')
|
99
|
+
end
|
100
|
+
end # end stringify_options
|
101
|
+
end # end Settings
|
102
|
+
|
103
|
+
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Lau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: ansi
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,22 +66,25 @@ dependencies:
|
|
52
66
|
- - ! '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
description:
|
69
|
+
description: Syntatic sugar for the raise method
|
56
70
|
email:
|
57
71
|
executables: []
|
58
72
|
extensions: []
|
59
73
|
extra_rdoc_files: []
|
60
74
|
files:
|
61
75
|
- .gitignore
|
76
|
+
- .rspec
|
62
77
|
- Gemfile
|
63
78
|
- LICENSE.txt
|
64
79
|
- README.md
|
65
80
|
- Rakefile
|
66
81
|
- braise.gemspec
|
67
|
-
-
|
68
|
-
-
|
82
|
+
- examples/braise_usage.rb
|
83
|
+
- examples/craise_usage.rb
|
69
84
|
- lib/braise.rb
|
70
85
|
- lib/braise/version.rb
|
86
|
+
- spec/braise_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
71
88
|
homepage: https://github.com/MrAlexLau/braise
|
72
89
|
licenses:
|
73
90
|
- MIT
|
@@ -91,5 +108,7 @@ rubyforge_project:
|
|
91
108
|
rubygems_version: 2.1.10
|
92
109
|
signing_key:
|
93
110
|
specification_version: 4
|
94
|
-
summary:
|
95
|
-
test_files:
|
111
|
+
summary: Shortcuts `raise obj.inspect` and makes it easy to add color terminal output
|
112
|
+
test_files:
|
113
|
+
- spec/braise_spec.rb
|
114
|
+
- spec/spec_helper.rb
|