qualitysmith_extensions 0.0.34 → 0.0.49
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/lib/qualitysmith_extensions/array/shell_escape.rb +2 -2
- data/lib/qualitysmith_extensions/kernel/remove_const.rb +178 -0
- data/lib/qualitysmith_extensions/kernel/remove_module.rb +127 -0
- data/lib/qualitysmith_extensions/module/ancestry_of_instance_method.rb +43 -0
- data/lib/qualitysmith_extensions/module/attribute_accessors.rb +3 -0
- data/lib/qualitysmith_extensions/module/basename.rb +76 -0
- data/lib/qualitysmith_extensions/module/class_methods.rb +87 -0
- data/lib/qualitysmith_extensions/module/create.rb +315 -0
- data/lib/qualitysmith_extensions/module/dirname.rb +4 -0
- data/lib/qualitysmith_extensions/module/guard_method.rb +0 -1
- data/lib/qualitysmith_extensions/module/join.rb +66 -0
- data/lib/qualitysmith_extensions/module/module_methods.rb +4 -0
- data/lib/qualitysmith_extensions/module/namespace.rb +111 -0
- data/lib/qualitysmith_extensions/module/parents.rb +61 -0
- data/lib/qualitysmith_extensions/module/remove_const.rb +117 -0
- data/lib/qualitysmith_extensions/module/split.rb +55 -0
- data/lib/qualitysmith_extensions/object/ancestry_of_method.rb +257 -0
- data/lib/qualitysmith_extensions/object/methods.rb +7 -2
- data/lib/qualitysmith_extensions/string/constantize.rb +4 -0
- data/lib/qualitysmith_extensions/string/shell_escape.rb +1 -1
- data/lib/qualitysmith_extensions/symbol/constantize.rb +69 -0
- data/lib/qualitysmith_extensions/template.rb +1 -0
- data/lib/qualitysmith_extensions/test/assert_anything.rb +93 -0
- metadata +19 -3
- data/lib/qualitysmith_extensions/class/class_methods.rb +0 -5
@@ -8,11 +8,16 @@
|
|
8
8
|
|
9
9
|
require 'rubygems'
|
10
10
|
require 'facets/core/module/alias_method_chain'
|
11
|
-
require '
|
11
|
+
require 'facets/core/symbol/to_proc'
|
12
12
|
|
13
13
|
class Object
|
14
14
|
|
15
|
-
#
|
15
|
+
# Ruby's built-in Object#methods says:
|
16
|
+
# Returns a list of the names of methods publicly accessible in obj. This will include all the methods accessible in obj's ancestors.
|
17
|
+
#
|
18
|
+
# But sometimes you don't _want_ all of obj's ancestors!
|
19
|
+
#
|
20
|
+
# This <tt>Object#methods</tt> adds the following features to the built-in <tt>Object#methods</tt>:
|
16
21
|
# * Provides the same +include_super+ option that Module#instance_methods has (Backwards compatible, because default is +true+)
|
17
22
|
# * Returns an array of symbols rather than strings (Not backwards compatible)
|
18
23
|
# * Sorts the array for you so you don't have to! (Not backwards compatible)
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
require 'rubygems'
|
9
9
|
require 'escape' # http://www.a-k-r.org/escape/
|
10
|
-
require '
|
10
|
+
require 'facets/core/symbol/to_proc' unless Symbol.method_defined?(:to_proc)
|
11
11
|
require 'facets/core/kernel/require_local'
|
12
12
|
|
13
13
|
class String
|
@@ -0,0 +1,69 @@
|
|
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
|
+
# Changes::
|
8
|
+
#++
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'facets/core/kernel/constant'
|
12
|
+
|
13
|
+
class Symbol
|
14
|
+
# Tries to find a declared constant with the name specified in self.
|
15
|
+
#
|
16
|
+
# :Foo.constantize => Foo
|
17
|
+
#
|
18
|
+
# Unlike ActiveSupport, we don't do this check (because Kernel.module "can handle module hierarchy"):
|
19
|
+
# vendor/rails/activesupport/lib/active_support/inflector.rb
|
20
|
+
# unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
|
21
|
+
# raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
|
22
|
+
# end
|
23
|
+
def constantize
|
24
|
+
Kernel.constant(self)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class String
|
28
|
+
# Tries to find a declared constant with the name specified in self.
|
29
|
+
#
|
30
|
+
# 'Foo'.constantize => Foo
|
31
|
+
#
|
32
|
+
# Unlike ActiveSupport, we don't do this check (because Kernel.module "can handle module hierarchy"):
|
33
|
+
# vendor/rails/activesupport/lib/active_support/inflector.rb
|
34
|
+
# unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
|
35
|
+
# raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
|
36
|
+
# end
|
37
|
+
def constantize
|
38
|
+
Kernel.constant(self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# _____ _
|
43
|
+
# |_ _|__ ___| |_
|
44
|
+
# | |/ _ \/ __| __|
|
45
|
+
# | | __/\__ \ |_
|
46
|
+
# |_|\___||___/\__|
|
47
|
+
#
|
48
|
+
=begin test
|
49
|
+
require 'test/unit'
|
50
|
+
|
51
|
+
module OuterModule; end
|
52
|
+
module OuterModule::InnerModule; end
|
53
|
+
|
54
|
+
class SymbolTest < Test::Unit::TestCase
|
55
|
+
module InnerModule; end
|
56
|
+
def test_1
|
57
|
+
assert_equal OuterModule, :OuterModule.constantize
|
58
|
+
assert_equal OuterModule::InnerModule, :'OuterModule::InnerModule'.constantize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
class StringTest < Test::Unit::TestCase
|
62
|
+
module InnerModule; end
|
63
|
+
def test_1
|
64
|
+
assert_equal OuterModule, 'OuterModule'.constantize
|
65
|
+
assert_equal OuterModule::InnerModule, 'OuterModule::InnerModule'.constantize
|
66
|
+
end
|
67
|
+
end
|
68
|
+
=end
|
69
|
+
|
@@ -0,0 +1,93 @@
|
|
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
|
+
# Changes::
|
8
|
+
#++
|
9
|
+
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
# Lets you make an assertion out of any method, without having to write a new assert_ method for it!
|
13
|
+
#
|
14
|
+
# So as long as the +whatever+ method's return value can be interpreted as a boolean value, you can simply call
|
15
|
+
# <tt>assert_whatever a, b</tt>, which will be equivalent to calling <tt>assert a.whatever(b)</tt>
|
16
|
+
#
|
17
|
+
# Follow this basic pattern:
|
18
|
+
# assert_{method} {receiver}, {args}
|
19
|
+
# assert_not_{method} {receiver}, {args}
|
20
|
+
# assert_{method}_is {receiver}, {args}, {expected_return_value}
|
21
|
+
# assert_{method}_returns {receiver}, {args}, {expected_return_value}
|
22
|
+
#
|
23
|
+
# Examples:
|
24
|
+
# assert_include? [1, 2, 3], 2
|
25
|
+
# assert_not_include? [1, 2, 3], 4
|
26
|
+
# assert_class_is 'foo', String
|
27
|
+
#
|
28
|
+
def method_missing(name, *args)
|
29
|
+
# to do:
|
30
|
+
# options = args.pop if args.last.is_a?(Hash)
|
31
|
+
# message = options[:message]
|
32
|
+
if name.to_s =~ /^assert_(.*)/
|
33
|
+
receiver = args.shift
|
34
|
+
negated = false
|
35
|
+
message_to_pass = $1
|
36
|
+
|
37
|
+
if name.to_s =~ /^assert_(.*)_is/
|
38
|
+
message_to_pass = $1
|
39
|
+
expected = args.pop
|
40
|
+
if name.to_s =~ /^assert_(.*)_is_not/
|
41
|
+
message_to_pass = $1
|
42
|
+
negated = true
|
43
|
+
end
|
44
|
+
|
45
|
+
result = receiver.send(message_to_pass, *args)
|
46
|
+
if negated
|
47
|
+
assert_not_equal expected, result
|
48
|
+
else
|
49
|
+
assert_equal expected, result
|
50
|
+
end
|
51
|
+
else
|
52
|
+
if name.to_s =~ /^assert_not_(.*)|assert_(.*)_is_not/
|
53
|
+
message_to_pass = $1
|
54
|
+
negated = true
|
55
|
+
end
|
56
|
+
|
57
|
+
result = receiver.send(message_to_pass, *args)
|
58
|
+
result = !result if negated
|
59
|
+
assert result
|
60
|
+
end
|
61
|
+
|
62
|
+
else
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# _____ _
|
72
|
+
# |_ _|__ ___| |_
|
73
|
+
# | |/ _ \/ __| __|
|
74
|
+
# | | __/\__ \ |_
|
75
|
+
# |_|\___||___/\__|
|
76
|
+
#
|
77
|
+
=begin test
|
78
|
+
require 'test/unit'
|
79
|
+
|
80
|
+
class TheTest < Test::Unit::TestCase
|
81
|
+
def test_1
|
82
|
+
assert_include? [1, 2, 3], 2
|
83
|
+
assert_not_include? [1, 2, 3], 4
|
84
|
+
end
|
85
|
+
def test_is
|
86
|
+
assert_class_is 'foo', String
|
87
|
+
assert_class_is_not ['foo'], String
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
=end
|
92
|
+
|
93
|
+
|
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-05-
|
6
|
+
version: 0.0.49
|
7
|
+
date: 2007-05-24 00:00:00 -07:00
|
8
8
|
summary: A collection of reusable Ruby methods developed by QualitySmith.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/qualitysmith_extensions/template.rb
|
35
35
|
- lib/qualitysmith_extensions/all.rb
|
36
36
|
- lib/qualitysmith_extensions/month.rb
|
37
|
+
- lib/qualitysmith_extensions/test/assert_anything.rb
|
37
38
|
- lib/qualitysmith_extensions/test/assert_exception.rb
|
38
39
|
- lib/qualitysmith_extensions/test/assert_user_error.rb
|
39
40
|
- lib/qualitysmith_extensions/test/assert_changed.rb
|
@@ -52,10 +53,13 @@ files:
|
|
52
53
|
- lib/qualitysmith_extensions/kernel/filter_output.rb
|
53
54
|
- lib/qualitysmith_extensions/kernel/backtrace.rb
|
54
55
|
- lib/qualitysmith_extensions/kernel/capture_output.rb
|
56
|
+
- lib/qualitysmith_extensions/kernel/remove_module.rb
|
57
|
+
- lib/qualitysmith_extensions/kernel/remove_const.rb
|
55
58
|
- lib/qualitysmith_extensions/kernel/trap_chain.rb
|
56
59
|
- lib/qualitysmith_extensions/dir/each_child.rb
|
57
60
|
- lib/qualitysmith_extensions/object/singleton_send.rb
|
58
61
|
- lib/qualitysmith_extensions/object/mcall.rb
|
62
|
+
- lib/qualitysmith_extensions/object/ancestry_of_method.rb
|
59
63
|
- lib/qualitysmith_extensions/object/send_if_not_nil.rb
|
60
64
|
- lib/qualitysmith_extensions/object/ignore_access.rb
|
61
65
|
- lib/qualitysmith_extensions/object/methods.rb
|
@@ -74,11 +78,23 @@ files:
|
|
74
78
|
- lib/qualitysmith_extensions/console/command.facets.1.8.54.rb
|
75
79
|
- lib/qualitysmith_extensions/console/command.facets.1.8.51.rb
|
76
80
|
- lib/qualitysmith_extensions/module/guard_method.rb
|
81
|
+
- lib/qualitysmith_extensions/module/ancestry_of_instance_method.rb
|
82
|
+
- lib/qualitysmith_extensions/module/split.rb
|
83
|
+
- lib/qualitysmith_extensions/module/module_methods.rb
|
77
84
|
- lib/qualitysmith_extensions/module/alias_method.rb
|
85
|
+
- lib/qualitysmith_extensions/module/namespace.rb
|
78
86
|
- lib/qualitysmith_extensions/module/includable_once.rb
|
87
|
+
- lib/qualitysmith_extensions/module/parents.rb
|
88
|
+
- lib/qualitysmith_extensions/module/dirname.rb
|
89
|
+
- lib/qualitysmith_extensions/module/basename.rb
|
79
90
|
- lib/qualitysmith_extensions/module/create_setter.rb
|
80
91
|
- lib/qualitysmith_extensions/module/attribute_accessors.rb
|
92
|
+
- lib/qualitysmith_extensions/module/create.rb
|
81
93
|
- lib/qualitysmith_extensions/module/bool_attr_accessor.rb
|
94
|
+
- lib/qualitysmith_extensions/module/remove_const.rb
|
95
|
+
- lib/qualitysmith_extensions/module/join.rb
|
96
|
+
- lib/qualitysmith_extensions/module/class_methods.rb
|
97
|
+
- lib/qualitysmith_extensions/symbol/constantize.rb
|
82
98
|
- lib/qualitysmith_extensions/symbol/match.rb
|
83
99
|
- lib/qualitysmith_extensions/enumerable/enum.rb
|
84
100
|
- lib/qualitysmith_extensions/hash/to_query_string.rb
|
@@ -98,9 +114,9 @@ files:
|
|
98
114
|
- lib/qualitysmith_extensions/string/with_knowledge_of_color.rb
|
99
115
|
- lib/qualitysmith_extensions/string/md5.rb
|
100
116
|
- lib/qualitysmith_extensions/string/to_underscored_label.rb
|
117
|
+
- lib/qualitysmith_extensions/string/constantize.rb
|
101
118
|
- lib/qualitysmith_extensions/string/all.rb
|
102
119
|
- lib/qualitysmith_extensions/string/each_char_with_index.rb
|
103
|
-
- lib/qualitysmith_extensions/class/class_methods.rb
|
104
120
|
- test/all.rb
|
105
121
|
- Readme
|
106
122
|
test_files:
|