qualitysmith_extensions 0.0.7 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qualitysmith_extensions/all.rb +3 -1
- data/lib/qualitysmith_extensions/dir/each_child.rb +58 -0
- data/lib/qualitysmith_extensions/kernel/require_all.rb +36 -20
- data/lib/qualitysmith_extensions/kernel/trap_chain.rb +61 -0
- data/lib/qualitysmith_extensions/mutex/if_available.rb +75 -0
- data/lib/qualitysmith_extensions/object/ignore_access.rb +79 -0
- data/lib/qualitysmith_extensions/object/methods.rb +1 -1
- data/lib/qualitysmith_extensions/object/send_if_not_nil.rb +35 -0
- data/lib/qualitysmith_extensions/object/singleton_send.rb +21 -3
- data/lib/qualitysmith_extensions/string/with_knowledge_of_color.rb +64 -0
- data/lib/qualitysmith_extensions/symbol/match.rb +36 -0
- metadata +9 -2
@@ -1,2 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/kernel/require_all"
|
2
|
-
require_all File.dirname(__FILE__),
|
2
|
+
require_all File.dirname(__FILE__),
|
3
|
+
:exclude => /(^|\/)test\//, # Don't include anything in test/ because those files will include test/unit, which causes tests to automatically be run (an unfortunate side-effect)!
|
4
|
+
:exclude_files => 'all.rb'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Nolan Cafferky
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
#++
|
7
|
+
|
8
|
+
|
9
|
+
class Dir
|
10
|
+
# Much like each(), except the "." and ".." special files
|
11
|
+
# are ignored.
|
12
|
+
def each_child
|
13
|
+
each do |file|
|
14
|
+
yield file if file != "." and file != ".."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# _____ _
|
21
|
+
# |_ _|__ ___| |_
|
22
|
+
# | |/ _ \/ __| __|
|
23
|
+
# | | __/\__ \ |_
|
24
|
+
# |_|\___||___/\__|
|
25
|
+
#
|
26
|
+
=begin test
|
27
|
+
|
28
|
+
require 'fileutils'
|
29
|
+
|
30
|
+
class TheTest < Test::Unit::TestCase
|
31
|
+
def setup
|
32
|
+
@base_path = "dir_extensions_test_test_each_child"
|
33
|
+
make_test_files @base_path
|
34
|
+
end
|
35
|
+
def teardown
|
36
|
+
FileUtils.remove_entry_secure @base_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_each_child
|
40
|
+
Dir.open(@base_path) do |d|
|
41
|
+
results = []
|
42
|
+
d.each_child { |file| results << file }
|
43
|
+
assert_equal 3, results.size
|
44
|
+
assert results.include?("foo")
|
45
|
+
assert results.include?("bar")
|
46
|
+
assert results.include?("foobar")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def make_test_files base_path
|
51
|
+
Dir.mkdir( base_path)
|
52
|
+
FileUtils.touch(base_path + "/foo")
|
53
|
+
FileUtils.touch(base_path + "/bar")
|
54
|
+
Dir.mkdir( base_path + "/foobar")
|
55
|
+
FileUtils.touch(base_path + "/foobar/baz")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
=end
|
@@ -46,14 +46,15 @@ end
|
|
46
46
|
=begin test
|
47
47
|
require 'tmpdir'
|
48
48
|
require 'fileutils'
|
49
|
+
require 'English'
|
49
50
|
|
50
51
|
class TheTest < Test::Unit::TestCase
|
51
52
|
def setup
|
52
|
-
@
|
53
|
-
@base_dir = "#{Dir.tmpdir}/#{@main_subdir}"
|
53
|
+
@base_dir = "#{Dir.tmpdir}/require_all_test"
|
54
54
|
FileUtils.mkdir @base_dir
|
55
|
-
|
56
|
-
$loaded =
|
55
|
+
@deep_dir = "really/really/deep/subdir"
|
56
|
+
$loaded = []
|
57
|
+
|
57
58
|
end
|
58
59
|
def teardown
|
59
60
|
FileUtils.rm_rf @base_dir
|
@@ -61,46 +62,54 @@ class TheTest < Test::Unit::TestCase
|
|
61
62
|
|
62
63
|
|
63
64
|
def test_repeat_requires
|
64
|
-
|
65
|
-
|
65
|
+
create_ruby_file 'moo.rb'
|
66
|
+
|
66
67
|
require_all File.dirname(@base_dir)
|
67
|
-
assert_equal [
|
68
|
+
assert_equal ['moo.rb'], $loaded
|
68
69
|
|
69
70
|
require "#{@base_dir}/moo.rb"
|
70
|
-
assert_equal [
|
71
|
+
assert_equal ['moo.rb'], $loaded
|
71
72
|
|
72
73
|
# Good! It refuses to load it again, even if we drop the ".rb" part!
|
73
74
|
require "#{@base_dir}/moo"
|
74
|
-
assert_equal [
|
75
|
+
assert_equal ['moo.rb'], $loaded
|
75
76
|
|
76
77
|
# But, we can still trick it!
|
77
78
|
$LOAD_PATH << @base_dir
|
78
79
|
require "moo"
|
79
|
-
assert_equal [
|
80
|
+
assert_equal ['moo.rb', 'moo.rb'], $loaded
|
80
81
|
|
81
82
|
load "moo.rb"
|
82
|
-
assert_equal [
|
83
|
+
assert_equal ['moo.rb', 'moo.rb', 'moo.rb'], $loaded
|
83
84
|
end
|
84
85
|
|
85
86
|
def test_deep_subdir
|
86
|
-
|
87
|
-
|
87
|
+
create_ruby_file 'flip.rb'
|
88
|
+
create_ruby_file @deep_dir + "/flop.rb"
|
88
89
|
|
89
90
|
require_all File.dirname(@base_dir)
|
90
|
-
assert_equal [
|
91
|
+
assert_equal ['flip.rb', @deep_dir + "/flop.rb"], $loaded
|
91
92
|
end
|
92
93
|
|
93
94
|
def test_exclude_pattern
|
94
|
-
|
95
|
-
|
95
|
+
create_ruby_file 'require_me.rb'
|
96
|
+
create_ruby_file 'please_ignore_me.rb'
|
96
97
|
|
97
98
|
require_all File.dirname(@base_dir), :exclude => [/ignore/]
|
98
|
-
assert_equal [
|
99
|
+
assert_equal ['require_me.rb'], $loaded
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_exclude_pattern_with_directory
|
103
|
+
create_ruby_file 'subdir/test/assert_even.rb'
|
104
|
+
create_ruby_file 'subdir/test/assert_odd.rb'
|
105
|
+
|
106
|
+
require_all File.dirname(@base_dir), :exclude => [/[^|\/]test/]
|
107
|
+
assert_equal [], $loaded
|
99
108
|
end
|
100
109
|
|
101
110
|
def test_exclude_filename
|
102
|
-
|
103
|
-
|
111
|
+
create_ruby_file 'yes.rb'
|
112
|
+
create_ruby_file 'all.rb'
|
104
113
|
|
105
114
|
# :todo: Interesting how none of these patterns work. I would have expected them to. Is there a bug in FileList? Find out...
|
106
115
|
# /usr/lib/ruby/gems/1.8/gems/facets-1.8.51/lib/facets/more/filelist.rb
|
@@ -113,7 +122,14 @@ class TheTest < Test::Unit::TestCase
|
|
113
122
|
# So...... I added an :exclude_files option so that people wouldn't have to!
|
114
123
|
require_all File.dirname(@base_dir), :exclude_files => ['all.rb']
|
115
124
|
|
116
|
-
assert_equal [
|
125
|
+
assert_equal ['yes.rb'], $loaded
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_ruby_file(file_name)
|
129
|
+
if file_name =~ /(.*)\//
|
130
|
+
FileUtils.mkdir_p @base_dir + '/' + $1
|
131
|
+
end
|
132
|
+
File.open(@base_dir + '/' + file_name, "w") {|f| f.puts "$loaded << '#{file_name}'"}
|
117
133
|
end
|
118
134
|
|
119
135
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes!
|
6
|
+
#++
|
7
|
+
|
8
|
+
module Kernel
|
9
|
+
# Calling <tt>Kernel#trap()</tt> by itself will _replace_ any previously registered handler code.
|
10
|
+
# <tt>Kernel#trap_chain()</tt>, on the other hand, will _add_ the block you supply to the existing "list" of registered handler blocks.
|
11
|
+
# Similar to the way <tt>Kernel#at_exit()</tt> works, <tt>Kernel#trap_chain()</tt> will _prepend_ the given +block+ to the call chain for the given +signal_name+.
|
12
|
+
# When the signal occurs, your block will be executed first and then the previously registered handler will be invoked. This can be called repeatedly to create a "chain" of handlers.
|
13
|
+
def trap_chain(signal_name, *args, &block)
|
14
|
+
previous_interrupt_handler = trap(signal_name, *args) {}
|
15
|
+
trap(signal_name, *args) do
|
16
|
+
block.call
|
17
|
+
previous_interrupt_handler.call unless previous_interrupt_handler == "DEFAULT"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# _____ _
|
23
|
+
# |_ _|__ ___| |_
|
24
|
+
# | |/ _ \/ __| __|
|
25
|
+
# | | __/\__ \ |_
|
26
|
+
# |_|\___||___/\__|
|
27
|
+
#
|
28
|
+
=begin test
|
29
|
+
require 'rubygems'
|
30
|
+
require 'qualitysmith_extensions/kernel/capture_output'
|
31
|
+
require 'fileutils'
|
32
|
+
|
33
|
+
class TheTest < Test::Unit::TestCase
|
34
|
+
def setup
|
35
|
+
FileUtils.touch('trap_chain_test_output')
|
36
|
+
end
|
37
|
+
def teardown
|
38
|
+
FileUtils.remove_entry_secure 'trap_chain_test_output'
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_1
|
42
|
+
output = capture_output do # For some reason, this wasn't capturing the output from the child process when I did plain puts, so I changed it to write to a file instead...
|
43
|
+
|
44
|
+
pid = fork do
|
45
|
+
trap_chain("INT") { File.open('trap_chain_test_output', 'a') {|file| file.puts "Handler 1" } }
|
46
|
+
trap_chain("INT") { File.open('trap_chain_test_output', 'a') {|file| file.puts "Handler 2"; file.puts "Exiting..."; }; exit }
|
47
|
+
trap_chain("INT") { File.open('trap_chain_test_output', 'a') {|file| file.puts "Handler 3" } }
|
48
|
+
puts 'Hello world'
|
49
|
+
sleep 5
|
50
|
+
end
|
51
|
+
Process.kill "INT", pid
|
52
|
+
Process.wait
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal "Handler 3\nHandler 2\nExiting...\n", File.read('trap_chain_test_output')
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
=end
|
61
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Nolan Cafferky
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
#++
|
7
|
+
|
8
|
+
require 'thread'
|
9
|
+
class Mutex
|
10
|
+
# Acts like synchronize, except that if the lock cannot be acquired immediately,
|
11
|
+
# the program continues without executing the given block.
|
12
|
+
#
|
13
|
+
# ==Example:
|
14
|
+
#
|
15
|
+
# mutex = Mutex.new
|
16
|
+
# # ...
|
17
|
+
# mutex.if_available do
|
18
|
+
# # Some process that we only want one thread to be running at a time,
|
19
|
+
# # and we don't mind skipping if some other thread is already doing it.
|
20
|
+
# loop do
|
21
|
+
# notify_mechanics if danger_to_teh_manifold!
|
22
|
+
# sleep 60
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
def if_available
|
26
|
+
if try_lock
|
27
|
+
begin
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
unlock
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
# _____ _
|
39
|
+
# |_ _|__ ___| |_
|
40
|
+
# | |/ _ \/ __| __|
|
41
|
+
# | | __/\__ \ |_
|
42
|
+
# |_|\___||___/\__|
|
43
|
+
#
|
44
|
+
=begin test
|
45
|
+
class TheTest < Test::Unit::TestCase
|
46
|
+
def setup
|
47
|
+
@semaphore = Mutex.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def teardown
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_executes_if_lock_is_available
|
54
|
+
i_ran = nil
|
55
|
+
|
56
|
+
@semaphore.if_available do
|
57
|
+
i_ran = true
|
58
|
+
end
|
59
|
+
|
60
|
+
assert i_ran
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_continues_if_lock_is_unavailable
|
64
|
+
i_ran = nil
|
65
|
+
|
66
|
+
@semaphore.lock
|
67
|
+
@semaphore.if_available do
|
68
|
+
i_ran = true
|
69
|
+
end
|
70
|
+
@semaphore.unlock
|
71
|
+
|
72
|
+
assert_nil i_ran
|
73
|
+
end
|
74
|
+
end
|
75
|
+
=end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes!
|
6
|
+
# Developer notes:
|
7
|
+
# * Come up with a shorter/better name than ignore_access?
|
8
|
+
# * Other name ideas:
|
9
|
+
# * ignore_private
|
10
|
+
# * access_everything
|
11
|
+
# * access
|
12
|
+
# * sneaky
|
13
|
+
# * rude
|
14
|
+
# * all_public
|
15
|
+
# * public!
|
16
|
+
# * all (like rdoc's --all -- it's too generic for a method name though)
|
17
|
+
# * promiscuous (like rdoc's --promiscuous -- different semantics though)
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'facets/more/functor'
|
22
|
+
|
23
|
+
class Object
|
24
|
+
|
25
|
+
# Sends all messages to receiver, bypassing access restrictions, allowing you to call private methods (like class_variable_get) without having to write ugly send() calls.
|
26
|
+
#
|
27
|
+
# o.class.ignore_access.class_variable_set(:@@v, 'old value')
|
28
|
+
# is equivalent to:
|
29
|
+
# o.class.send(:class_variable_set, :@@v, 'new value')
|
30
|
+
#
|
31
|
+
def ignore_access
|
32
|
+
@_ignore_access_functor ||= Functor.new do |op,*args|
|
33
|
+
self.send(op,*args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
alias_method :access, :ignore_access
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# _____ _
|
42
|
+
# |_ _|__ ___| |_
|
43
|
+
# | |/ _ \/ __| __|
|
44
|
+
# | | __/\__ \ |_
|
45
|
+
# |_|\___||___/\__|
|
46
|
+
#
|
47
|
+
=begin test
|
48
|
+
require 'test/unit'
|
49
|
+
|
50
|
+
class TheTest < Test::Unit::TestCase
|
51
|
+
|
52
|
+
# It's not identical to Kernel#meta, as this test proves! (Must run it singly, without other tests.)
|
53
|
+
# def test_meta
|
54
|
+
# require 'rubygems'; require 'facets/core/kernel/meta'
|
55
|
+
# o = Object.new
|
56
|
+
# o.class.meta.class_variable_set(:@@v, 'old value')
|
57
|
+
# assert_equal 'old value', o.class.meta.class_variable_get(:@@v)
|
58
|
+
#
|
59
|
+
# #assert_nothing_raised { o.class.send(:class_variable_get, :@@v) } # Fails!
|
60
|
+
#
|
61
|
+
# assert_equal Object, o.class
|
62
|
+
# o.class.send(:class_variable_set, :@@v, 'new value')
|
63
|
+
# assert_equal 'new value', o.class.send(:class_variable_get, :@@v)
|
64
|
+
# assert_equal 'new value', o.class.meta.class_variable_get(:@@v) # Fails! Still has 'old value'!
|
65
|
+
# end
|
66
|
+
|
67
|
+
def test_1
|
68
|
+
o = Object.new
|
69
|
+
o.class.ignore_access.class_variable_set(:@@v, 'old value')
|
70
|
+
assert_nothing_raised { o.class.send(:class_variable_get, :@@v) }
|
71
|
+
o.class.send(:class_variable_set, :@@v, 'new value')
|
72
|
+
assert_equal 'new value', o.class.ignore_access.class_variable_get(:@@v)
|
73
|
+
assert_equal 'new value', o.class.send(:class_variable_get, :@@v)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
=end
|
79
|
+
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Tyler Rick
|
3
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
4
|
# License:: Ruby License
|
5
|
-
# Submit to Facets?:: Yes
|
5
|
+
# Submit to Facets?:: Yes. Actually, Facets already has one, which takes a symbol (:inherited, :local, :public, etc.). Possibly merge with that one. Accept symbol *or* boolean as arg?
|
6
6
|
# Developer notes::
|
7
7
|
#++
|
8
8
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Maybe.
|
6
|
+
# Developer notes::
|
7
|
+
#++
|
8
|
+
|
9
|
+
class Object
|
10
|
+
def send_if_not_nil(message, *args)
|
11
|
+
if message
|
12
|
+
send(message, *args)
|
13
|
+
else
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# _____ _
|
21
|
+
# |_ _|__ ___| |_
|
22
|
+
# | |/ _ \/ __| __|
|
23
|
+
# | | __/\__ \ |_
|
24
|
+
# |_|\___||___/\__|
|
25
|
+
#
|
26
|
+
=begin test
|
27
|
+
require 'test/unit'
|
28
|
+
|
29
|
+
class TheTest < Test::Unit::TestCase
|
30
|
+
def test_1
|
31
|
+
assert_equal 'a', 'a'.send_if_not_nil(nil)
|
32
|
+
assert_equal 'A', 'a'.send_if_not_nil(:upcase)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
=end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Tyler Rick
|
3
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
4
|
# License:: Ruby License
|
5
|
-
# Submit to Facets?::
|
5
|
+
# Submit to Facets?:: Maybe.
|
6
6
|
# Developer notes::
|
7
7
|
# * Method name too long? Imagine if we wanted to string multiple calls together.
|
8
8
|
# * Ideas:
|
@@ -23,6 +23,9 @@ class Object
|
|
23
23
|
#
|
24
24
|
# More specificaly, it <tt>extend</tt>s +self+ with the methods from +moduule+ and then sends the supplied +message+ and +args+ (if any).
|
25
25
|
#
|
26
|
+
# Examples:
|
27
|
+
# "whatever".ss(MyColorizer, :colorize, :blue)
|
28
|
+
#
|
26
29
|
# Advantages:
|
27
30
|
# * Keeps things object-oriented. Better than having global/class methods.
|
28
31
|
# * (<tt>"whatever".ss(MyColorizer, :colorize).ss(SomeOtherClass, :another_class_method)</tt> instead of
|
@@ -37,8 +40,23 @@ class Object
|
|
37
40
|
# * Can't just call .sigleton_send(self, :some_method) if you want to use +some_method+ that's defined in +self+.
|
38
41
|
# * So what do we call the module containing the "singleton method"? String::MyColorizer? MyColorizer::String? MyStringColorizer?
|
39
42
|
#
|
40
|
-
#
|
41
|
-
#
|
43
|
+
# Adding methods to the base class using Facets' own *namespacing* facilities (Module#namespace and Module#include_as)
|
44
|
+
# might actually be a more sensible alternative a lot of the time than bothering to create singleton methods for single objects!
|
45
|
+
# That would look somethig like:
|
46
|
+
#
|
47
|
+
# class String
|
48
|
+
# namespace :my_colorizer do
|
49
|
+
# def colorize(...); ...; end
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# "whatever".my_colorizer.colorize(:blue)
|
53
|
+
#
|
54
|
+
# or
|
55
|
+
#
|
56
|
+
# class String
|
57
|
+
# include_as :my_colorizer => MyColorizer
|
58
|
+
# end
|
59
|
+
# "whatever".my_colorizer.colorize(:blue)
|
42
60
|
#
|
43
61
|
def singleton_send(moduule, message, *args)
|
44
62
|
self.extend(moduule)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Maybe
|
6
|
+
#++
|
7
|
+
|
8
|
+
module WithKnowledgeOfColor
|
9
|
+
Color_regexp = /\e\[[^m]+m/
|
10
|
+
|
11
|
+
def strip_color
|
12
|
+
gsub(Color_regexp, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
# This version of +length+ takes into account the fact that the ANSI color codes themselves don't take up any space to display on the screen.
|
16
|
+
# So this returns the number of characters wide the string is when it is actually printed to the screen.
|
17
|
+
def length_without_color
|
18
|
+
strip_color.length
|
19
|
+
end
|
20
|
+
|
21
|
+
def nonprinting_characters_used_for_color
|
22
|
+
self.scan(Color_regexp).join
|
23
|
+
end
|
24
|
+
|
25
|
+
def ljust_without_color(width)
|
26
|
+
ljust(width + nonprinting_characters_used_for_color.length)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class String
|
31
|
+
include WithKnowledgeOfColor
|
32
|
+
end
|
33
|
+
|
34
|
+
# _____ _
|
35
|
+
# |_ _|__ ___| |_
|
36
|
+
# | |/ _ \/ __| __|
|
37
|
+
# | | __/\__ \ |_
|
38
|
+
# |_|\___||___/\__|
|
39
|
+
#
|
40
|
+
=begin test
|
41
|
+
require 'rubygems'
|
42
|
+
gem 'colored'
|
43
|
+
require 'colored'
|
44
|
+
|
45
|
+
class TheTest < Test::Unit::TestCase
|
46
|
+
def test_strip_color
|
47
|
+
assert "abc" != "abc".blue
|
48
|
+
assert_equal "abc", "abc".blue.strip_color
|
49
|
+
end
|
50
|
+
def test_length_without_color
|
51
|
+
assert_equal 12, "abc".blue.length
|
52
|
+
assert_equal 3, "abc".blue.length_without_color
|
53
|
+
end
|
54
|
+
def test_nonprinting_characters_used_for_color
|
55
|
+
assert_equal "\e[34m\e[0m", 'abc'.blue.nonprinting_characters_used_for_color
|
56
|
+
end
|
57
|
+
def test_ljust_without_color
|
58
|
+
assert_equal "abc ", 'abc'. ljust( 5)
|
59
|
+
assert_equal "abc ", 'abc'.blue.ljust_without_color(5).strip_color
|
60
|
+
assert_equal "\e[34mabc\e[0m ", 'abc'.blue.ljust_without_color(5)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
=end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes! I can't believe Facets has Regexp#chomp, capitalize, downcase, etc., but not match/=~ !
|
6
|
+
# Developer notes::
|
7
|
+
#++
|
8
|
+
|
9
|
+
class Symbol
|
10
|
+
def match(regexp)
|
11
|
+
to_s.match(regexp)
|
12
|
+
end
|
13
|
+
def =~(regexp)
|
14
|
+
to_s =~ regexp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# _____ _
|
19
|
+
# |_ _|__ ___| |_
|
20
|
+
# | |/ _ \/ __| __|
|
21
|
+
# | | __/\__ \ |_
|
22
|
+
# |_|\___||___/\__|
|
23
|
+
#
|
24
|
+
=begin test
|
25
|
+
require 'test/unit'
|
26
|
+
|
27
|
+
class TheTest < Test::Unit::TestCase
|
28
|
+
def test_equal_tilde
|
29
|
+
assert_equal 1, :chopper =~ /hopper/
|
30
|
+
end
|
31
|
+
def test_match
|
32
|
+
assert :chopper.match(/hopper/).is_a?(MatchData)
|
33
|
+
assert_equal 'hopper', :chopper.match(/hopper/).to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
=end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: qualitysmith_extensions
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-04-
|
6
|
+
version: 0.0.13
|
7
|
+
date: 2007-04-11 00:00:00 -07:00
|
8
8
|
summary: A collection of reusable Ruby methods developed by QualitySmith.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -48,7 +48,11 @@ files:
|
|
48
48
|
- lib/qualitysmith_extensions/kernel/filter_output.rb
|
49
49
|
- lib/qualitysmith_extensions/kernel/backtrace.rb
|
50
50
|
- lib/qualitysmith_extensions/kernel/capture_output.rb
|
51
|
+
- lib/qualitysmith_extensions/kernel/trap_chain.rb
|
52
|
+
- lib/qualitysmith_extensions/dir/each_child.rb
|
51
53
|
- lib/qualitysmith_extensions/object/singleton_send.rb
|
54
|
+
- lib/qualitysmith_extensions/object/send_if_not_nil.rb
|
55
|
+
- lib/qualitysmith_extensions/object/ignore_access.rb
|
52
56
|
- lib/qualitysmith_extensions/object/methods.rb
|
53
57
|
- lib/qualitysmith_extensions/object/default.rb
|
54
58
|
- lib/qualitysmith_extensions/file/exact_match_regexp.rb
|
@@ -58,6 +62,7 @@ files:
|
|
58
62
|
- lib/qualitysmith_extensions/date/month_ranges.rb
|
59
63
|
- lib/qualitysmith_extensions/time/deprecated.rb
|
60
64
|
- lib/qualitysmith_extensions/time/all.rb
|
65
|
+
- lib/qualitysmith_extensions/mutex/if_available.rb
|
61
66
|
- lib/qualitysmith_extensions/console/command.rb
|
62
67
|
- lib/qualitysmith_extensions/console/command.facets.1.8.54.rb
|
63
68
|
- lib/qualitysmith_extensions/console/command.facets.1.8.51.rb
|
@@ -65,6 +70,7 @@ files:
|
|
65
70
|
- lib/qualitysmith_extensions/module/includable_once.rb
|
66
71
|
- lib/qualitysmith_extensions/module/create_setter.rb
|
67
72
|
- lib/qualitysmith_extensions/module/attribute_accessors.rb
|
73
|
+
- lib/qualitysmith_extensions/symbol/match.rb
|
68
74
|
- lib/qualitysmith_extensions/enumerable/enum.rb
|
69
75
|
- lib/qualitysmith_extensions/hash/to_query_string.rb
|
70
76
|
- lib/qualitysmith_extensions/hash/all.rb
|
@@ -79,6 +85,7 @@ files:
|
|
79
85
|
- lib/qualitysmith_extensions/array/group_by.rb
|
80
86
|
- lib/qualitysmith_extensions/string/digits_only.rb
|
81
87
|
- lib/qualitysmith_extensions/string/shell_escape.rb
|
88
|
+
- lib/qualitysmith_extensions/string/with_knowledge_of_color.rb
|
82
89
|
- lib/qualitysmith_extensions/string/md5.rb
|
83
90
|
- lib/qualitysmith_extensions/string/to_underscored_label.rb
|
84
91
|
- lib/qualitysmith_extensions/string/all.rb
|