cmessages 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +44 -0
- data/.travis.yml +69 -0
- data/CODEOWNERS +7 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.md +24 -0
- data/README.md +119 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cmessages.gemspec +28 -0
- data/examples/examples.rb +24 -0
- data/lib/cmessages.rb +81 -0
- data/lib/cmessages/overloads.rb +22 -0
- data/lib/cmessages/version.rb +3 -0
- data/spec/cmessages_spec.rb +202 -0
- data/spec/spec_helper.rb +26 -0
- data/stale.yml +17 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0119dff67dc1b586119287ea69e4e5535e630773ab4539269a9f15a441ca564b'
|
4
|
+
data.tar.gz: 92b3f3b789a463eecd807a36f6a300023fb43360a335faed90eb3f2f6a5a73ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf65cc481b2ff4bc7a817bc9403fb1a5da580b42ff7b9d7f0bab175b88aafb29626b65ade500e931f748571e0dbb10cbd73557011b1259036503d7b7c3e969fa
|
7
|
+
data.tar.gz: ca0d42d9dd2427c89e0a3824df433ddf41519c7822edb47eb01dac5738abf2806f9f05d296eff4f624b23a9e5a2c24905a01e301ce16b3158647d5d3dd74afff
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Layout/IndentationWidth:
|
2
|
+
Width: 4
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Layout/SpaceAroundOperators:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/PerceivedComplexity:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/FrozenStringLiteralComment:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/HashSyntax:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/RedundantParentheses:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/RedundantBegin:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/RedundantReturn:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/SpecialGlobalVars:
|
44
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
matrix:
|
2
|
+
include:
|
3
|
+
- language: ruby
|
4
|
+
name: Bundler (rvm 2.4 & bundler 1.17.3)
|
5
|
+
rvm: 2.4
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v 1.17.3
|
8
|
+
- language: ruby
|
9
|
+
name: Bundler (rvm 2.4 & bundler 2.0.1)
|
10
|
+
rvm: 2.4
|
11
|
+
before_install:
|
12
|
+
- gem install bundler -v 2.0.1
|
13
|
+
- language: ruby
|
14
|
+
name: Bundler (rvm 2.5 & bundler 2.0.1)
|
15
|
+
rvm: 2.5
|
16
|
+
before_install:
|
17
|
+
- gem install bundler -v 2.0.1
|
18
|
+
- language: ruby
|
19
|
+
name: Bundler (rvm 2.6 & bundler 2.0.1)
|
20
|
+
rvm: 2.6
|
21
|
+
before_install:
|
22
|
+
- gem install bundler -v 2.0.1
|
23
|
+
- language: ruby
|
24
|
+
name: Rubocop (rvm 2.4)
|
25
|
+
env: SKIP_INTERPRETER=true
|
26
|
+
rvm: 2.4
|
27
|
+
before_install:
|
28
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
29
|
+
install:
|
30
|
+
- "./rubocop-travis/install.sh"
|
31
|
+
script:
|
32
|
+
- "./rubocop-travis/scan.sh"
|
33
|
+
- language: ruby
|
34
|
+
name: Rubocop (rvm 2.5)
|
35
|
+
env: SKIP_INTERPRETER=true
|
36
|
+
rvm: 2.5
|
37
|
+
before_install:
|
38
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
39
|
+
install:
|
40
|
+
- "./rubocop-travis/install.sh"
|
41
|
+
script:
|
42
|
+
- "./rubocop-travis/scan.sh"
|
43
|
+
- language: ruby
|
44
|
+
name: Rubocop (rvm 2.6)
|
45
|
+
env: SKIP_INTERPRETER=true
|
46
|
+
rvm: 2.6
|
47
|
+
before_install:
|
48
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
49
|
+
install:
|
50
|
+
- "./rubocop-travis/install.sh"
|
51
|
+
script:
|
52
|
+
- "./rubocop-travis/scan.sh"
|
53
|
+
- language: ruby
|
54
|
+
name: Link Checking (rvm 2.6)
|
55
|
+
rvm: 2.6
|
56
|
+
env:
|
57
|
+
- WHITELIST="https://img.shields.io"
|
58
|
+
- EXCLUDE_FILES="CHANGELOG.md"
|
59
|
+
before_install:
|
60
|
+
- mkdir travis
|
61
|
+
- git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
|
62
|
+
install:
|
63
|
+
- "./travis/awesomebot/install.sh"
|
64
|
+
script:
|
65
|
+
- "./travis/awesomebot/scan.sh"
|
66
|
+
notifications:
|
67
|
+
email: false
|
68
|
+
slack:
|
69
|
+
secure: oW+QJywQdCoGoyIwystfLulGhUGP2ZzXtyNn3bq6SjbsxBE1i1LuOJEK+mJF6LB84vijQA8/pgWB8Tt0+kMwhN89ShjpVaTpXqXBbq75T7K7dVKyzftvgLa3VfKAH8yo0fmDXvyhcuIq7OTyou8b0QBuN1jevebi7tgixW6xKepP/ICTtYXKMaXHAvLuhn4E7mMx27mRyqHhiFMYqpgSBD1XwvA/m+jAFOP3O/JnzYaWaZEjDn0nxSqv2qQW2zU1ehh7/rIL75kkvaL2LsOVRKWEVjskCGtCrKm9uZ4gsFhZ6gjf7uQy7pWbYJo9DaCRT4m8Y7qZD+DxG489lp41OZRB6oqFxFITGcgUMDcvbqgska5z/tsJYOWcjxP8spiJAHIJB7ubnvq1Q5LoRTY2nZOuH/YMbaS4bcAldz8EDGlFp9rd8aRgKPtKMxqcnTc7bHZnfOEUVDeiV/oAPV7QC0N7ZXzbPWlCgurpS10/uw/Bb4pph7ds+eKG3zaKgSNvVVijvwCfQi5yyhZ8USWueQdL5a5iwbGeuEq7hphMh13MGayjVnlWOi/QicPQv/zEVPe7IwQw/I4iO7zHbdVuPXW2Lewi2nI/Hbq54FbGtNgiL2iwAOcjSoAn8iLXH+jkTw8v4GSUSFzIhR0dfjxopVvCz+VNY7GIMZEV5S6snBU=
|
data/CODEOWNERS
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright © `2016 - 2020` `Wolf Software Limited`
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
6
|
+
obtaining a copy of this software and associated documentation
|
7
|
+
files (the “Software”), to deal in the Software without
|
8
|
+
restriction, including without limitation the rights to use,
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the
|
11
|
+
Software is furnished to do so, subject to the following
|
12
|
+
conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/travis/WolfSoftware/cmessages/master?style=for-the-badge&logo=travis)](https://travis-ci.org/WolfSoftware/cmessages)
|
2
|
+
[![Software License](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](LICENSE.md)
|
3
|
+
[![Release](https://img.shields.io/github/release/WolfSoftware/cmessages?color=blue&style=for-the-badge&logo=github&label=Latest%20Release)](https://github.com/WolfSoftware/cmessages/releases/latest)
|
4
|
+
[![Last Release](https://img.shields.io/github/release-date/WolfSoftware/cmessages?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/cmessages/releases/latest)
|
5
|
+
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/WolfSoftware/cmessages/latest?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/cmessages/commits)
|
6
|
+
[![Last Commit](https://img.shields.io/github/last-commit/WolfSoftware/cmessages?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/cmessages/commits/master)
|
7
|
+
[![WolfSoftware](https://img.shields.io/badge/Released%20By-Wolf%20Software%20Ltd.-blue?style=for-the-badge)](https://github.com/WolfSoftware)
|
8
|
+
|
9
|
+
# Cmessages
|
10
|
+
|
11
|
+
A simple gem for outputting console errors/warnings/success/info messages. The module has 4 main functions.
|
12
|
+
|
13
|
+
* Error - Display an error message - Default light red text with an ```[ Error ]``` prefix.
|
14
|
+
* Warning - Display a warning message - Default light yellow text with an ```[ Warning ]``` prefix.
|
15
|
+
* Success - Display a success message - Default light green text with an ```[ Success ]``` prefix.
|
16
|
+
* Info - Display an info message - Default light cyan text with an ```[ Info ]``` prefix.
|
17
|
+
|
18
|
+
It is possible to disable colour, disable prefixed, define custom colours and custom prefixes.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'cmessages'
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
```
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
```
|
37
|
+
gem install cmessages
|
38
|
+
```
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
### Default Users
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
cm = Cmessages.new()
|
46
|
+
|
47
|
+
cm.error('This is an error message')
|
48
|
+
cm.warning('This is a warning warning')
|
49
|
+
cm.success('This is a success message')
|
50
|
+
cm.info('This is an info message')
|
51
|
+
```
|
52
|
+
|
53
|
+
It is also possible to chain the functions.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
message='This is an error message'
|
57
|
+
message.error
|
58
|
+
```
|
59
|
+
|
60
|
+
### Advanced Usage
|
61
|
+
|
62
|
+
It is possible to pass configuration when creating a new instance of cmessages.
|
63
|
+
|
64
|
+
```
|
65
|
+
cm = Cmessages.new( { use_prefixes => false } )
|
66
|
+
cm.error('This is an error with no prefix')
|
67
|
+
```
|
68
|
+
|
69
|
+
or
|
70
|
+
|
71
|
+
```
|
72
|
+
message='This is an error message'
|
73
|
+
message.error( { use_prefixes => false } )
|
74
|
+
```
|
75
|
+
|
76
|
+
### Configuration Options
|
77
|
+
|
78
|
+
| Name | Purpose | Default |
|
79
|
+
| ---- | ------- |:-------:|
|
80
|
+
| :error_colour | Set the colour for an error message | :light_red |
|
81
|
+
| :warning_colour | Set the colour for a warning message | :light_yellow |
|
82
|
+
| :success_colour | Set the colour for a warning message | :light_green |
|
83
|
+
| :info_colour | Set the colour for an info message | :light_cyan |
|
84
|
+
| :error_prefix | Set the colour for an error message | '[ Error ]' |
|
85
|
+
| :warning_prefix | Set the colour for a warning message | '[ Warning ]' |
|
86
|
+
| :success_prefix | Set the colour for a warning message | '[ Success ]' |
|
87
|
+
| :info_prefix | Set the colour for an info message | '[ Info ]' |
|
88
|
+
| :use_colours | Should we use colour in the output | true |
|
89
|
+
| :use_prefixes | Should we use prefies in the output | true |
|
90
|
+
|
91
|
+
### Valid Colours
|
92
|
+
|
93
|
+
| Default Colour | Highlighted Colour |
|
94
|
+
| -------------- | ------------------ |
|
95
|
+
| :black | :light_black |
|
96
|
+
| :red | :light_red |
|
97
|
+
| :green | :light_green |
|
98
|
+
| :yellow | :light_yellow |
|
99
|
+
| :blue | :light_blue |
|
100
|
+
| :magenta | :light_magenta |
|
101
|
+
| :cyan | ;light_cyan |
|
102
|
+
| :white | :light_white |
|
103
|
+
| :default | N/A |
|
104
|
+
|
105
|
+
> Note: If you use an invalid colour, it will not error, it will simply use the default colour instead.
|
106
|
+
|
107
|
+
## Development
|
108
|
+
|
109
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
112
|
+
|
113
|
+
### Testing
|
114
|
+
|
115
|
+
For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
|
116
|
+
|
117
|
+
For further information please refer to the [contributing](https://github.com/WolfSoftware/contributing) documentation.
|
118
|
+
|
119
|
+
<p align="right"><img src="https://img.shields.io/badge/Created%20By-Wolf-black?style=for-the-badge" /></p>
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'cmessages'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/cmessages.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'cmessages/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'cmessages'
|
7
|
+
spec.version = Cmessages::VERSION
|
8
|
+
spec.authors = ['Tim Gurney aka Wolf']
|
9
|
+
spec.email = ['wolf@tgwolf.com']
|
10
|
+
|
11
|
+
spec.summary = 'A simple gem for outputting console errors/warnings/success/info messages.'
|
12
|
+
spec.description = 'A simple gem for outputting console errors/warnings/success/info messages.'
|
13
|
+
spec.homepage = 'https://github.com/WolfSoftware/cmessages'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.0'
|
23
|
+
spec.add_development_dependency 'colorize', '~> 0.8.0'
|
24
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'colorize', '~> 0.8.0'
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift('./lib')
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'cmessages'
|
7
|
+
|
8
|
+
test = Cmessages.new
|
9
|
+
|
10
|
+
test.error('This is an error')
|
11
|
+
test.warning('This is a warning')
|
12
|
+
test.success('This is a success')
|
13
|
+
test.info('This is a message')
|
14
|
+
|
15
|
+
'This is an error'.error
|
16
|
+
'This is a warning'.warning
|
17
|
+
'This is a success'.success
|
18
|
+
'This is a message'.info
|
19
|
+
|
20
|
+
'This is a customised error'.error(:error_colour => :magenta, :error_prefix => '[ Custom Error ]')
|
21
|
+
'This is a customised error with no prefix'.error(:error_colour => :blue, :use_prefixes => false)
|
22
|
+
'This is a customised error with no prefix or colour'.error(:use_colours => false, :use_prefixes => false)
|
23
|
+
|
24
|
+
'This is a customised error with an invalid colour'.error(:error_colour => :invalid_colour, :error_prefix => '[ Custom Error ]')
|
data/lib/cmessages.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'cmessages/overloads.rb'
|
2
|
+
require 'cmessages/version'
|
3
|
+
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Docs to follow
|
8
|
+
#
|
9
|
+
class Cmessages
|
10
|
+
def initialize(options = {})
|
11
|
+
@valid_colours = %I[black light_black red light_red green light_green yellow light_yellow blue light_blue magenta light_magenta cyan light_cyan white light_white default]
|
12
|
+
|
13
|
+
@error_colour = :light_red
|
14
|
+
@warning_colour = :light_yellow
|
15
|
+
@success_colour = :light_green
|
16
|
+
@info_colour = :light_cyan
|
17
|
+
|
18
|
+
@error_prefix = '[ Error ]'
|
19
|
+
@warning_prefix = '[ Warning ]'
|
20
|
+
@success_prefix = '[ Success ]'
|
21
|
+
@info_prefix = '[ Info ]'
|
22
|
+
|
23
|
+
@use_colours = true unless options.key?(:use_colours) && options[:use_colours] == false
|
24
|
+
@use_prefixes = true unless options.key?(:use_prefixes) && options[:use_prefixes] == false
|
25
|
+
|
26
|
+
@error_colour = options[:error_colour] if options.key?(:error_colour) && valid_colour(options[:error_colour])
|
27
|
+
@warning_colour = options[:warning_colour] if options.key?(:warning_colour) && valid_colour(options[:warning_colour])
|
28
|
+
@success_colour = options[:success_colour] if options.key?(:success_colour) && valid_colour(options[:success_colour])
|
29
|
+
@info_colour = options[:info_colour] if options.key?(:info_colour) && valid_colour(options[:info_colour])
|
30
|
+
|
31
|
+
@error_prefix = options[:error_prefix] if options.key?(:error_prefix)
|
32
|
+
@warning_prefix = options[:warning_prefix] if options.key?(:warning_prefix)
|
33
|
+
@success_prefix = options[:success_prefix] if options.key?(:success_prefix)
|
34
|
+
@info_prefix = options[:info_prefix] if options.key?(:info_prefix)
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_colour(colour)
|
38
|
+
return @valid_colours.include?(colour)
|
39
|
+
end
|
40
|
+
|
41
|
+
def error(message = nil)
|
42
|
+
return if message.nil?
|
43
|
+
|
44
|
+
real_show_messge(@error_prefix, message, @error_colour)
|
45
|
+
end
|
46
|
+
|
47
|
+
def warning(message = nil)
|
48
|
+
return if message.nil?
|
49
|
+
|
50
|
+
real_show_messge(@warning_prefix, message, @warning_colour)
|
51
|
+
end
|
52
|
+
|
53
|
+
def success(message = nil)
|
54
|
+
return if message.nil?
|
55
|
+
|
56
|
+
real_show_messge(@success_prefix, message, @success_colour)
|
57
|
+
end
|
58
|
+
|
59
|
+
def info(message = nil)
|
60
|
+
return if message.nil?
|
61
|
+
|
62
|
+
real_show_messge(@info_prefix, message, @info_colour)
|
63
|
+
end
|
64
|
+
|
65
|
+
def real_show_messge(prefix, message, colour)
|
66
|
+
return if message.nil?
|
67
|
+
|
68
|
+
return if message.empty?
|
69
|
+
|
70
|
+
# String contains 0 or more white-space character and nothing else.
|
71
|
+
return if message =~ /^\s*$/
|
72
|
+
|
73
|
+
message = "#{prefix} #{message}" if @use_prefixes
|
74
|
+
|
75
|
+
if @use_colours
|
76
|
+
puts message.colorize(colour)
|
77
|
+
else
|
78
|
+
puts message
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Overloads
|
2
|
+
|
3
|
+
#
|
4
|
+
# Docs to follow
|
5
|
+
#
|
6
|
+
class String
|
7
|
+
def error(options = {})
|
8
|
+
Cmessages.new(options).error(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def warning(options = {})
|
12
|
+
Cmessages.new(options).warning(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def success(options = {})
|
16
|
+
Cmessages.new(options).success(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def info(options = {})
|
20
|
+
Cmessages.new(options).info(self)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'cmessages'
|
2
|
+
|
3
|
+
RSpec.describe Cmessages do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(Cmessages::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'Class Accessor Method' do
|
9
|
+
before(:each) do
|
10
|
+
@cm = Cmessages.new
|
11
|
+
@cmnc = Cmessages.new(:use_colours => false)
|
12
|
+
@cmnp = Cmessages.new(:use_prefixes => false)
|
13
|
+
@cmncnp = Cmessages.new(:use_colours => false, :use_prefixes => false)
|
14
|
+
@cmcustome = Cmessages.new(:error_prefix => '{ Error }')
|
15
|
+
@cmcustomw = Cmessages.new(:warning_prefix => '{ Warning }')
|
16
|
+
@cmcustoms = Cmessages.new(:success_prefix => '{ Success }')
|
17
|
+
@cmcustomi = Cmessages.new(:info_prefix => '{ Info }')
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'Error prefix validation' do
|
21
|
+
context 'default (colour and prefix)' do
|
22
|
+
specify { expect { @cm.error('foo') }.to output("\e[0;91;49m[ Error ] foo\e[0m\n").to_stdout }
|
23
|
+
end
|
24
|
+
context 'no colour' do
|
25
|
+
specify { expect { @cmnc.error('foo') }.to output("[ Error ] foo\n").to_stdout }
|
26
|
+
end
|
27
|
+
context 'no prefix' do
|
28
|
+
specify { expect { @cmnp.error('foo') }.to output("\e[0;91;49mfoo\e[0m\n").to_stdout }
|
29
|
+
end
|
30
|
+
context 'no prefix and no colour' do
|
31
|
+
specify { expect { @cmncnp.error('foo') }.to output("foo\n").to_stdout }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Warning Prefixes' do
|
36
|
+
context 'default (colour and prefix)' do
|
37
|
+
specify { expect { @cm.warning('foo') }.to output("\e[0;93;49m[ Warning ] foo\e[0m\n").to_stdout }
|
38
|
+
end
|
39
|
+
context 'no colour' do
|
40
|
+
specify { expect { @cmnc.warning('foo') }.to output("[ Warning ] foo\n").to_stdout }
|
41
|
+
end
|
42
|
+
context 'no prefix' do
|
43
|
+
specify { expect { @cmnp.warning('foo') }.to output("\e[0;93;49mfoo\e[0m\n").to_stdout }
|
44
|
+
end
|
45
|
+
context 'no prefix and no colour' do
|
46
|
+
specify { expect { @cmncnp.warning('foo') }.to output("foo\n").to_stdout }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'Success Prefixes' do
|
51
|
+
context 'default (colour and prefix)' do
|
52
|
+
specify { expect { @cm.success('foo') }.to output("\e[0;92;49m[ Success ] foo\e[0m\n").to_stdout }
|
53
|
+
end
|
54
|
+
context 'no colour' do
|
55
|
+
specify { expect { @cmnc.success('foo') }.to output("[ Success ] foo\n").to_stdout }
|
56
|
+
end
|
57
|
+
context 'no prefix' do
|
58
|
+
specify { expect { @cmnp.success('foo') }.to output("\e[0;92;49mfoo\e[0m\n").to_stdout }
|
59
|
+
end
|
60
|
+
context 'no prefix and no colour' do
|
61
|
+
specify { expect { @cmncnp.success('foo') }.to output("foo\n").to_stdout }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'Info Prefixes' do
|
66
|
+
context 'default (colour and prefix)' do
|
67
|
+
specify { expect { @cm.info('foo') }.to output("\e[0;96;49m[ Info ] foo\e[0m\n").to_stdout }
|
68
|
+
end
|
69
|
+
context 'no colour' do
|
70
|
+
specify { expect { @cmnc.info('foo') }.to output("[ Info ] foo\n").to_stdout }
|
71
|
+
end
|
72
|
+
context 'no prefix' do
|
73
|
+
specify { expect { @cmnp.info('foo') }.to output("\e[0;96;49mfoo\e[0m\n").to_stdout }
|
74
|
+
end
|
75
|
+
context 'no prefix and no colour' do
|
76
|
+
specify { expect { @cmncnp.info('foo') }.to output("foo\n").to_stdout }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'Custom Prefixes' do
|
81
|
+
context 'error prefix' do
|
82
|
+
specify { expect { Cmessages.new(:error_prefix => '{ Error }').error('foo') }.to output("\e[0;91;49m{ Error } foo\e[0m\n").to_stdout }
|
83
|
+
end
|
84
|
+
context 'warning prefix' do
|
85
|
+
specify { expect { Cmessages.new(:warning_prefix => '{ Warning }').warning('foo') }.to output("\e[0;93;49m{ Warning } foo\e[0m\n").to_stdout }
|
86
|
+
end
|
87
|
+
context 'success prefix' do
|
88
|
+
specify { expect { Cmessages.new(:success_prefix => '{ Success }').success('foo') }.to output("\e[0;92;49m{ Success } foo\e[0m\n").to_stdout }
|
89
|
+
end
|
90
|
+
context 'info prefix' do
|
91
|
+
specify { expect { Cmessages.new(:info_prefix => '{ Info }').info('foo') }.to output("\e[0;96;49m{ Info } foo\e[0m\n").to_stdout }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'Custom Colours' do
|
96
|
+
context 'error colour' do
|
97
|
+
specify { expect { Cmessages.new(:error_colour => :blue).error('foo') }.to output("\e[0;34;49m[ Error ] foo\e[0m\n").to_stdout }
|
98
|
+
end
|
99
|
+
context 'warning colour' do
|
100
|
+
specify { expect { Cmessages.new(:warning_colour => :white).warning('foo') }.to output("\e[0;37;49m[ Warning ] foo\e[0m\n").to_stdout }
|
101
|
+
end
|
102
|
+
context 'success colour' do
|
103
|
+
specify { expect { Cmessages.new(:success_colour => :black).success('foo') }.to output("\e[0;30;49m[ Success ] foo\e[0m\n").to_stdout }
|
104
|
+
end
|
105
|
+
context 'info colour' do
|
106
|
+
specify { expect { Cmessages.new(:info_colour => :magenta).info('foo') }.to output("\e[0;35;49m[ Info ] foo\e[0m\n").to_stdout }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'String Accessor Method' do
|
112
|
+
context 'Error prefix validation' do
|
113
|
+
context 'default (colour and prefix)' do
|
114
|
+
specify { expect { 'foo'.error }.to output("\e[0;91;49m[ Error ] foo\e[0m\n").to_stdout }
|
115
|
+
end
|
116
|
+
context 'no colour' do
|
117
|
+
specify { expect { 'foo'.error(:use_colours => false) }.to output("[ Error ] foo\n").to_stdout }
|
118
|
+
end
|
119
|
+
context 'no prefix' do
|
120
|
+
specify { expect { 'foo'.error(:use_prefixes => false) }.to output("\e[0;91;49mfoo\e[0m\n").to_stdout }
|
121
|
+
end
|
122
|
+
context 'no prefix and no colour' do
|
123
|
+
specify { expect { 'foo'.error(:use_colours => false, :use_prefixes => false) }.to output("foo\n").to_stdout }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'Warning Prefixes' do
|
128
|
+
context 'default (colour and prefix)' do
|
129
|
+
specify { expect { 'foo'.warning }.to output("\e[0;93;49m[ Warning ] foo\e[0m\n").to_stdout }
|
130
|
+
end
|
131
|
+
context 'no colour' do
|
132
|
+
specify { expect { 'foo'.warning(:use_colours => false) }.to output("[ Warning ] foo\n").to_stdout }
|
133
|
+
end
|
134
|
+
context 'no prefix' do
|
135
|
+
specify { expect { 'foo'.warning(:use_prefixes => false) }.to output("\e[0;93;49mfoo\e[0m\n").to_stdout }
|
136
|
+
end
|
137
|
+
context 'no prefix and no colour' do
|
138
|
+
specify { expect { 'foo'.warning(:use_colours => false, :use_prefixes => false) }.to output("foo\n").to_stdout }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'Success Prefixes' do
|
143
|
+
context 'default (colour and prefix)' do
|
144
|
+
specify { expect { 'foo'.success }.to output("\e[0;92;49m[ Success ] foo\e[0m\n").to_stdout }
|
145
|
+
end
|
146
|
+
context 'no colour' do
|
147
|
+
specify { expect { 'foo'.success(:use_colours => false) }.to output("[ Success ] foo\n").to_stdout }
|
148
|
+
end
|
149
|
+
context 'no prefix' do
|
150
|
+
specify { expect { 'foo'.success(:use_prefixes => false) }.to output("\e[0;92;49mfoo\e[0m\n").to_stdout }
|
151
|
+
end
|
152
|
+
context 'no prefix and no colour' do
|
153
|
+
specify { expect { 'foo'.success(:use_colours => false, :use_prefixes => false) }.to output("foo\n").to_stdout }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'Info Prefixes' do
|
158
|
+
context 'default (colour and prefix)' do
|
159
|
+
specify { expect { 'foo'.info }.to output("\e[0;96;49m[ Info ] foo\e[0m\n").to_stdout }
|
160
|
+
end
|
161
|
+
context 'no colour' do
|
162
|
+
specify { expect { 'foo'.info(:use_colours => false) }.to output("[ Info ] foo\n").to_stdout }
|
163
|
+
end
|
164
|
+
context 'no prefix' do
|
165
|
+
specify { expect { 'foo'.info(:use_prefixes => false) }.to output("\e[0;96;49mfoo\e[0m\n").to_stdout }
|
166
|
+
end
|
167
|
+
context 'no prefix and no colour' do
|
168
|
+
specify { expect { 'foo'.info(:use_colours => false, :use_prefixes => false) }.to output("foo\n").to_stdout }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'Custom Prefixes' do
|
173
|
+
context 'error prefix' do
|
174
|
+
specify { expect { 'foo'.error(:error_prefix => '{ Error }') }.to output("\e[0;91;49m{ Error } foo\e[0m\n").to_stdout }
|
175
|
+
end
|
176
|
+
context 'warning prefix' do
|
177
|
+
specify { expect { 'foo'.warning(:warning_prefix => '{ Warning }') }.to output("\e[0;93;49m{ Warning } foo\e[0m\n").to_stdout }
|
178
|
+
end
|
179
|
+
context 'success prefix' do
|
180
|
+
specify { expect { 'foo'.success(:success_prefix => '{ Success }') }.to output("\e[0;92;49m{ Success } foo\e[0m\n").to_stdout }
|
181
|
+
end
|
182
|
+
context 'info prefix' do
|
183
|
+
specify { expect { 'foo'.info(:info_prefix => '{ Info }') }.to output("\e[0;96;49m{ Info } foo\e[0m\n").to_stdout }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'Custom Colours' do
|
188
|
+
context 'error colour' do
|
189
|
+
specify { expect { 'foo'.error(:error_colour => :blue) }.to output("\e[0;34;49m[ Error ] foo\e[0m\n").to_stdout }
|
190
|
+
end
|
191
|
+
context 'warning colour' do
|
192
|
+
specify { expect { 'foo'.warning(:warning_colour => :white) }.to output("\e[0;37;49m[ Warning ] foo\e[0m\n").to_stdout }
|
193
|
+
end
|
194
|
+
context 'success colour' do
|
195
|
+
specify { expect { 'foo'.success(:success_colour => :black) }.to output("\e[0;30;49m[ Success ] foo\e[0m\n").to_stdout }
|
196
|
+
end
|
197
|
+
context 'info colour' do
|
198
|
+
specify { expect { 'foo'.info(:info_colour => :magenta) }.to output("\e[0;35;49m[ Info ] foo\e[0m\n").to_stdout }
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'cmessages'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
|
15
|
+
original_stderr = $stderr
|
16
|
+
original_stdout = $stdout
|
17
|
+
config.before(:all) do
|
18
|
+
# Redirect stderr and stdout
|
19
|
+
$stderr = File.open(File::NULL, 'w')
|
20
|
+
$stdout = File.open(File::NULL, 'w')
|
21
|
+
end
|
22
|
+
config.after(:all) do
|
23
|
+
$stderr = original_stderr
|
24
|
+
$stdout = original_stdout
|
25
|
+
end
|
26
|
+
end
|
data/stale.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
2
|
+
daysUntilStale: 60
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
4
|
+
daysUntilClose: 7
|
5
|
+
# Issues with these labels will never be considered stale
|
6
|
+
exemptLabels:
|
7
|
+
- pinned
|
8
|
+
- security
|
9
|
+
# Label to use when marking an issue as stale
|
10
|
+
staleLabel: wontfix
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
12
|
+
markComment: >
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
15
|
+
for your contributions.
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
17
|
+
closeComment: true
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cmessages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Gurney aka Wolf
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-03 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.17'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.17'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: colorize
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.8.0
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '13.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '13.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: colorize
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.8.0
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.8.0
|
89
|
+
description: A simple gem for outputting console errors/warnings/success/info messages.
|
90
|
+
email:
|
91
|
+
- wolf@tgwolf.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitattributes"
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".rubocop.yml"
|
100
|
+
- ".travis.yml"
|
101
|
+
- CODEOWNERS
|
102
|
+
- CONTRIBUTING.md
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.md
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/console
|
108
|
+
- bin/setup
|
109
|
+
- cmessages.gemspec
|
110
|
+
- examples/examples.rb
|
111
|
+
- lib/cmessages.rb
|
112
|
+
- lib/cmessages/overloads.rb
|
113
|
+
- lib/cmessages/version.rb
|
114
|
+
- spec/cmessages_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- stale.yml
|
117
|
+
homepage: https://github.com/WolfSoftware/cmessages
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.1.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A simple gem for outputting console errors/warnings/success/info messages.
|
140
|
+
test_files: []
|