colored-not 1.2

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in colored-not.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Junegunn Choi
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,36 @@
1
+ # colored-not
2
+
3
+ ![Colored... NOT!](https://github.com/junegunn/colored-not/raw/master/colored-not.jpg)
4
+
5
+ Toggles methods from [colored gem](https://github.com/defunkt/colored).
6
+
7
+ ## Installation
8
+
9
+ gem install colored-not
10
+
11
+ ## Scenario
12
+
13
+ colored gem will add a bunch of coloring methods to String class.
14
+
15
+ ```ruby
16
+ require 'colored'
17
+ "Roses are red".red # Returns "\e[31mRoses are red\e[0m"
18
+ ```
19
+
20
+ OK, but what if we want to dynamically turn off colored output,
21
+ without removing calls to those methods scattered all over the code?
22
+ `Colored.not!` will replace the added methods with `String#dup`s.
23
+
24
+ ```ruby
25
+ require 'colored/not'
26
+ Colored.not!
27
+ "Roses are red... not!".red # Returns "Roses are red... not!"
28
+ ```
29
+
30
+ We can re-enable the colors.
31
+
32
+ ```ruby
33
+ Colored!
34
+ "Roses are red again".red # Returns "\e[31mRoses are red again\e[0m"
35
+ ```
36
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "colored-not"
7
+ gem.version = '1.2'
8
+ gem.authors = ["Junegunn Choi"]
9
+ gem.email = ["junegunn.c@gmail.com"]
10
+ gem.description = %q{Toggles methods from colored gem}
11
+ gem.summary = %q{Toggles methods from colored gem}
12
+ gem.homepage = "https://github.com/junegunn/colored-not"
13
+
14
+ gem.files = `git ls-files`.split($/).reject { |f| File.extname(f) == '.jpg' }
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_runtime_dependency "colored", '~> 1.2'
19
+ gem.add_development_dependency "minitest"
20
+ end
@@ -0,0 +1 @@
1
+ require 'colored/not'
@@ -0,0 +1,32 @@
1
+ require 'colored'
2
+
3
+ def Colored!
4
+ String.class_eval do
5
+ Colored.instance_methods.each do |m|
6
+ undef_method m
7
+ define_method(m) do |*args|
8
+ Colored.instance_method(m).bind(self).call(*args)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ module Colored
15
+ class << self
16
+ def not!
17
+ String.class_eval do
18
+ colors = COLORS.keys
19
+ (
20
+ EXTRAS.keys - %w[clear] +
21
+ colors +
22
+ colors.map { |c| "on_#{c}" } +
23
+ colors.product(colors).reject { |p| p.inject(:==) }.map { |p| p.join '_on_' }
24
+ ).map(&:to_sym).each do |m|
25
+ undef_method m
26
+ alias_method m, :dup
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,37 @@
1
+ $VERBOSE = true
2
+
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'colored/not'
6
+
7
+ class TestColoredNot < MiniTest::Unit::TestCase
8
+ def test_colored_not
9
+ 3.times do
10
+ assert_equal "\e[31mred\e[0m", 'red'.red
11
+ assert_equal "\e[41mred\e[0m", 'red'.on_red
12
+ assert_equal "\e[31m\e[44mred\e[0m", 'red'.red_on_blue
13
+ assert_equal "\e[1mred\e[0m", 'red'.bold
14
+ assert_equal "\e[4m\e[44m\e[31mred\e[0m\e[0m\e[0m", 'red'.red.on_blue.underline
15
+ assert_equal "", 'red'.clear if 'red'.respond_to?(:clear)
16
+
17
+ nots = Colored.not!
18
+
19
+ assert_equal "red", 'red'.red
20
+ assert_equal "red", 'red'.on_red
21
+ assert_equal "red", 'red'.red_on_blue
22
+ assert_equal "red", 'red'.bold
23
+ assert_equal "red", 'red'.red.on_blue.underline
24
+ assert_equal "", 'red'.clear if 'red'.respond_to?(:clear)
25
+
26
+ cols = Colored!
27
+
28
+ assert nots.include?(:bold)
29
+ assert nots.include?(:red)
30
+ assert nots.include?(:on_red)
31
+ assert nots.include?(:red_on_blue)
32
+ assert !nots.include?(:red_on_red)
33
+ assert (nots - cols).empty?
34
+ end
35
+ end
36
+ end
37
+
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colored-not
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Junegunn Choi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colored
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Toggles methods from colored gem
47
+ email:
48
+ - junegunn.c@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - colored-not.gemspec
59
+ - lib/colored-not.rb
60
+ - lib/colored/not.rb
61
+ - test/test_colored-not.rb
62
+ homepage: https://github.com/junegunn/colored-not
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Toggles methods from colored gem
86
+ test_files:
87
+ - test/test_colored-not.rb