facets 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +135 -294
- data/MANIFEST +40 -91
- data/NOTES +1 -1
- data/README.rdoc +10 -8
- data/Rakefile +11 -34
- data/demo/{hook.rd → hook.rdoc} +2 -0
- data/demo/{scenario_require.rd → scenario_require.rdoc} +3 -0
- data/lib/core/facets-live.rb +7 -5
- data/lib/core/facets.rb +379 -359
- data/lib/core/facets/array/conjoin.rb +2 -2
- data/lib/core/facets/array/pad.rb +1 -1
- data/lib/core/facets/array/recursively.rb +2 -2
- data/lib/core/facets/array/splice.rb +1 -1
- data/lib/core/facets/binding/caller.rb +2 -4
- data/lib/core/facets/comparable/comparable.rb +2 -2
- data/lib/core/facets/dir/ascend.rb +3 -0
- data/lib/core/facets/dir/recurse.rb +4 -0
- data/lib/core/facets/duplicable.rb +6 -8
- data/lib/core/facets/enumerable/count.rb +22 -13
- data/lib/core/facets/enumerable/map_detect.rb +28 -0
- data/lib/core/facets/enumerable/mash.rb +13 -5
- data/lib/core/facets/enumerable/per.rb +3 -1
- data/lib/core/facets/hash/count.rb +14 -0
- data/lib/core/facets/hash/data.rb +14 -0
- data/lib/core/facets/kernel/__method__.rb +1 -1
- data/lib/core/facets/kernel/d.rb +9 -8
- data/lib/core/facets/kernel/eigenclass.rb +20 -0
- data/lib/core/facets/kernel/extend.rb +10 -0
- data/lib/core/facets/kernel/instance_class.rb +1 -0
- data/lib/core/facets/kernel/instance_variables.rb +6 -6
- data/lib/core/facets/kernel/meta_alias.rb +18 -0
- data/lib/core/facets/kernel/meta_class.rb +17 -0
- data/lib/core/facets/kernel/meta_def.rb +18 -0
- data/lib/core/facets/kernel/meta_eval.rb +18 -0
- data/lib/core/facets/kernel/object_hexid.rb +21 -6
- data/lib/core/facets/kernel/object_state.rb +4 -2
- data/lib/core/facets/kernel/populate.rb +3 -1
- data/lib/core/facets/kernel/with.rb +1 -1
- data/lib/core/facets/metaid.rb +6 -93
- data/lib/core/facets/module/class_def.rb +2 -0
- data/lib/core/facets/module/extend.rb +10 -11
- data/lib/core/facets/module/is.rb +5 -5
- data/lib/core/facets/module/module_def.rb +31 -0
- data/lib/core/facets/string/camelcase.rb +14 -12
- data/lib/core/facets/string/cleanlines.rb +35 -0
- data/lib/core/facets/string/edit_distance.rb +62 -0
- data/lib/core/facets/string/indent.rb +86 -4
- data/lib/core/facets/string/index_all.rb +24 -0
- data/lib/core/facets/string/lines.rb +3 -6
- data/lib/core/facets/string/margin.rb +2 -1
- data/lib/core/facets/string/newlines.rb +35 -0
- data/lib/core/facets/string/op_div.rb +14 -0
- data/lib/core/facets/string/range.rb +2 -22
- data/lib/core/facets/string/range_all.rb +1 -0
- data/lib/core/facets/string/range_of_line.rb +1 -0
- data/lib/core/facets/string/similarity.rb +92 -0
- data/lib/core/facets/string/start_with.rb +6 -6
- data/lib/core/facets/string/titlecase.rb +1 -1
- data/lib/more/facets/basicobject.rb +16 -15
- data/lib/more/facets/blankslate.rb +8 -0
- data/lib/more/facets/class_extend.rb +126 -1
- data/lib/more/facets/continuation.rb +53 -54
- data/lib/more/facets/dictionary.rb +9 -63
- data/lib/more/facets/erb.rb +63 -0
- data/lib/more/facets/filelist.rb +5 -5
- data/lib/more/facets/hashbuilder.rb +101 -0
- data/lib/more/facets/inheritor.rb +36 -45
- data/lib/more/facets/ini.rb +267 -0
- data/lib/more/facets/instance_eval.rb +4 -4
- data/lib/more/facets/ioredirect.rb +7 -60
- data/lib/more/facets/linkedlist.rb +195 -0
- data/lib/more/facets/matcher.rb +140 -0
- data/lib/more/facets/memoizer.rb +64 -0
- data/lib/more/facets/methodspace.rb +9 -4
- data/lib/more/facets/module/class_extend.rb +2 -121
- data/lib/more/facets/ostruct.rb +9 -9
- data/lib/more/facets/pathlist.rb +1 -9
- data/lib/more/facets/pathname.rb +11 -4
- data/lib/more/facets/plugin_manager.rb +50 -0
- data/lib/more/facets/random.rb +25 -3
- data/lib/more/facets/roman.rb +174 -0
- data/lib/more/facets/semaphore.rb +92 -0
- data/lib/more/facets/shellwords.rb +21 -48
- data/lib/more/facets/succ.rb +1 -1
- data/meta/{modified → released} +0 -0
- data/meta/repository +1 -0
- data/meta/suite +1 -0
- data/meta/version +1 -1
- data/script/conflicts +63 -0
- data/script/methods +49 -0
- data/test/core/binding/test_caller.rb +11 -4
- data/test/core/enumerable/test_count.rb +19 -10
- data/test/core/enumerable/test_map_detect.rb +75 -0
- data/test/core/enumerable/test_take.rb +1 -1
- data/test/core/kernel/test_object_hexid.rb +2 -1
- data/test/core/proc/test_to_method.rb +1 -1
- data/test/core/string/test_cleanlines.rb +11 -0
- data/test/core/string/test_indent.rb +66 -4
- data/test/core/string/test_lines.rb +2 -1
- data/test/core/string/test_newlines.rb +13 -0
- data/test/core/time/test_change.rb +1 -1
- data/test/core/time/test_stamp.rb +4 -7
- data/test/core/unboundmethod/test_name.rb +1 -1
- data/test/more/test_basicobject.rb +1 -20
- data/test/more/test_class_extend.rb +7 -0
- data/test/more/test_continuation.rb +8 -6
- data/test/more/test_inheritor.rb +12 -6
- data/test/more/test_random.rb +19 -10
- data/test/more/test_shellwords.rb +33 -0
- metadata +60 -31
- data/TODO +0 -5
- data/doc/README.core +0 -102
- data/doc/README.more +0 -61
- data/doc/manual/about.rb +0 -47
- data/doc/manual/annotations.rdoc +0 -60
- data/doc/manual/associations.rdoc +0 -55
- data/doc/manual/blockups.rdoc +0 -101
- data/doc/manual/capsule.rdoc +0 -34
- data/doc/manual/command.rdoc +0 -177
- data/doc/manual/core.rdoc +0 -37
- data/doc/manual/faq.rdoc +0 -32
- data/doc/manual/typecast.html +0 -112
- data/lib/more/facets/capsule.rb +0 -258
- data/lib/more/facets/coroutine.rb +0 -159
- data/lib/more/facets/enumerablepass.rb +0 -3
- data/lib/more/facets/fileable.rb +0 -162
- data/lib/more/facets/progressbar.rb +0 -253
- data/lib/more/facets/recorder.rb +0 -108
- data/meta/releases +0 -14
- data/test/more/test_coroutine.rb +0 -46
data/lib/more/facets/succ.rb
CHANGED
data/meta/{modified → released}
RENAMED
File without changes
|
data/meta/repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
git@github.com:rubyworks/facets.git
|
data/meta/suite
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rubyworks
|
data/meta/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.8.0
|
data/script/conflicts
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'enumerator'
|
4
|
+
|
5
|
+
$: << 'lib'
|
6
|
+
#$: << 'lib'
|
7
|
+
|
8
|
+
libs = ARGV #(ENV['LIBS'] || "").split(/[;:]/)
|
9
|
+
|
10
|
+
# We add time b/c both that's built-in but not loaded by Ruby.
|
11
|
+
original = `script/methods time.rb yaml.rb`.split(/\s/)
|
12
|
+
facets = `script/methods lib/facets`.split(/\s/)
|
13
|
+
other = `script/methods #{libs.join(' ')}`.split(/\s/)
|
14
|
+
|
15
|
+
facets = facets - original
|
16
|
+
other = other - original
|
17
|
+
clash = facets & other
|
18
|
+
|
19
|
+
puts clash.sort.join("\n")
|
20
|
+
puts " #{clash.size} Clashes"
|
21
|
+
|
22
|
+
|
23
|
+
=begin
|
24
|
+
|
25
|
+
# Return a hash for each defined class containing a array class and method.
|
26
|
+
def methods_by_class
|
27
|
+
Module.
|
28
|
+
constants.
|
29
|
+
map{|klass| eval(klass)}.
|
30
|
+
select{|klass| klass.is_a? Class}.
|
31
|
+
inject({}){|h,klass|
|
32
|
+
h[klass] = [
|
33
|
+
klass.methods-klass.superclass.methods,
|
34
|
+
klass.instance_methods-(klass.superclass ? klass.superclass.instance_methods : [])
|
35
|
+
]
|
36
|
+
h
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
before = methods_by_class
|
41
|
+
|
42
|
+
ARGV.each{|a| require a }
|
43
|
+
|
44
|
+
after = methods_by_class
|
45
|
+
|
46
|
+
delta = after - before
|
47
|
+
|
48
|
+
puts delta.join("\n")
|
49
|
+
|
50
|
+
exit
|
51
|
+
|
52
|
+
# Print the difference between the before and after method lists:
|
53
|
+
before.keys.sort_by{|k| k.to_s}.each{|k|
|
54
|
+
class_diff = after[k][0]-before[k][0]
|
55
|
+
instance_diff = after[k][1]-before[k][1]
|
56
|
+
next if class_diff.empty? && instance_diff.empty?
|
57
|
+
puts((class_diff.sort.map{|c| "#{k}."+c} +
|
58
|
+
instance_diff.sort.map{|c| "#{k}#"+c}
|
59
|
+
)*"\n")
|
60
|
+
}
|
61
|
+
|
62
|
+
=end
|
63
|
+
|
data/script/methods
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'enumerator'
|
4
|
+
|
5
|
+
def method_list
|
6
|
+
list = []
|
7
|
+
|
8
|
+
ObjectSpace.each_object(Module) do |klass|
|
9
|
+
insta_methods = klass.public_instance_methods(true) +
|
10
|
+
klass.private_instance_methods(true) +
|
11
|
+
klass.protected_instance_methods(true)
|
12
|
+
|
13
|
+
class_methods = klass.public_methods(true) +
|
14
|
+
klass.private_methods(true) +
|
15
|
+
klass.protected_methods(true)
|
16
|
+
|
17
|
+
klass.ancestors[1..-1].each do |ancestor|
|
18
|
+
#next unless ancestor.is_a?(Module)
|
19
|
+
|
20
|
+
if ancestor.is_a?(Class)
|
21
|
+
insta_methods -= ancestor.public_instance_methods(true) +
|
22
|
+
ancestor.private_instance_methods(true) +
|
23
|
+
ancestor.protected_instance_methods(true)
|
24
|
+
|
25
|
+
class_methods -= ancestor.public_methods(true) +
|
26
|
+
ancestor.private_methods(true) +
|
27
|
+
ancestor.protected_methods(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class_methods -= Kernel.public_methods(true) +
|
32
|
+
Kernel.private_methods(true) +
|
33
|
+
Kernel.protected_methods(true)
|
34
|
+
|
35
|
+
class_methods.map!{|c| "#{klass}." + c}
|
36
|
+
insta_methods.map!{|c| "#{klass}#" + c}
|
37
|
+
|
38
|
+
list.concat(class_methods)
|
39
|
+
list.concat(insta_methods)
|
40
|
+
end
|
41
|
+
|
42
|
+
return list
|
43
|
+
end
|
44
|
+
|
45
|
+
ARGV.each{ |lib| require lib }
|
46
|
+
|
47
|
+
puts method_list.sort.join("\n")
|
48
|
+
|
49
|
+
|
@@ -33,12 +33,19 @@ class TestBindingCallStack < Test::Unit::TestCase
|
|
33
33
|
assert_nothing_raised{ @bind.caller }
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
# These only work for certain versions, which is okay.
|
37
|
+
|
38
|
+
unless RUBY_VERSION < "1.9"
|
39
|
+
def test_callee
|
40
|
+
assert_equal(:setup, @bind.__callee__)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
unless RUBY_VERSION < "1.8.7"
|
45
|
+
def test_method
|
46
|
+
assert_equal(:setup, @bind.__method__)
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
end
|
51
|
+
|
@@ -3,20 +3,29 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TC_Enumerable_Count < Test::Unit::TestCase
|
5
5
|
|
6
|
-
def
|
7
|
-
e = [
|
8
|
-
|
9
|
-
assert_equal(
|
6
|
+
def test_count_strings
|
7
|
+
e = ['a','1','a']
|
8
|
+
r = e.count('1')
|
9
|
+
assert_equal(1, r)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
e = [
|
14
|
-
|
12
|
+
def test_count_strings_again
|
13
|
+
e = ['a','1','a']
|
14
|
+
r = e.count('a')
|
15
|
+
assert_equal(2, r)
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
e =
|
19
|
-
|
18
|
+
def test_count_array_elements
|
19
|
+
e = [['a',2],['a',2],['a',2],['b',1]]
|
20
|
+
r = e.count(['a',2])
|
21
|
+
assert_equal(3, r)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_count_hash
|
25
|
+
e = { :a=>2, 'b'=>1, :c=>2 }
|
26
|
+
r = e.count(2)
|
27
|
+
assert_equal(2, r)
|
20
28
|
end
|
21
29
|
|
22
30
|
end
|
31
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'facets/enumerable/map_detect'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestEnumerable < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_map_detects_a_value
|
7
|
+
assert_equal true, [true].map_detect { |value| value }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_map_detect_detects_correct_value
|
11
|
+
assert_equal 1, [1].map_detect { |value| value }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_map_detect_returns_value_of_block
|
15
|
+
assert_equal 4, [1].map_detect { |v| v + 3 }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_map_detect_detects_first_truthy_value
|
19
|
+
assert_equal 1, [false, false, 1].map_detect { |value| value }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_map_detect_returns_value_when_block_is_true
|
23
|
+
assert_equal true, [false].map_detect { |value| true }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_map_detect_returns_early_when_block_is_true
|
27
|
+
val1 = lambda { :something }
|
28
|
+
val2 = lambda { raise "This shouldn't be called" }
|
29
|
+
|
30
|
+
assert_equal :something, [val1, val2].map_detect { |obj| obj.call }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_map_detect_returns_nil_when_block_returns_false_for_all_elements
|
34
|
+
assert_equal nil, [1,2,3,4].map_detect { |value| false }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_map_detect_returns_nil_when_no_elements_in_collection
|
38
|
+
assert_equal nil, [].map_detect { |v| }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_map_detect_can_have_return_value_specified_when_block_isnt_true
|
42
|
+
assert_equal :a_value, [1,2,3].map_detect(:a_value) { |value| false }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_map_detect_documentation_correct
|
46
|
+
obj1, obj2 = Object.new, Object.new
|
47
|
+
|
48
|
+
class << obj1
|
49
|
+
def foo?
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def foo
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class << obj2
|
59
|
+
def foo?
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def foo
|
64
|
+
"a value"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_equal false, obj1.foo?
|
69
|
+
assert_equal true, obj2.foo?
|
70
|
+
assert_equal "a value", obj2.foo
|
71
|
+
|
72
|
+
result = [obj1, obj2].map_detect { |obj| obj.foo if obj.foo? }
|
73
|
+
assert_equal result, "a value"
|
74
|
+
end
|
75
|
+
end
|
@@ -3,11 +3,73 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TC_String_Indent < Test::Unit::TestCase
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
assert_equal
|
9
|
-
# Need to expand on this
|
6
|
+
def test_positive_indent
|
7
|
+
assert_equal ' xyz', "xyz". indent(4)
|
8
|
+
assert_equal ' xyz', " xyz".indent(2)
|
10
9
|
end
|
11
10
|
|
11
|
+
def test_multi_line_positive_indent
|
12
|
+
assert_equal " abc\n" +
|
13
|
+
" xyz" ,
|
14
|
+
("abc\n" +
|
15
|
+
"xyz" ).indent(2)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_0_indent
|
19
|
+
assert_equal 'xyz', 'xyz'.indent(0)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_negative_indent
|
23
|
+
assert_equal ' xyz', ' xyz'.indent(-2)
|
24
|
+
assert_equal 'xyz', ' xyz'. indent(-2)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_multi_line_negative_indent
|
28
|
+
assert_equal " abc\n" +
|
29
|
+
" xyz" ,
|
30
|
+
(" abc\n" +
|
31
|
+
" xyz" ).indent(-2)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_outdent_is_alias_for_negative_indent
|
35
|
+
assert_equal 'xyz', ' xyz'.outdent(2)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_negative_indent_more_than_is_possible
|
39
|
+
assert_equal 'xyz', ' xyz'.indent(-3)
|
40
|
+
end
|
41
|
+
|
42
|
+
#-----------------------------------
|
43
|
+
# Using a character other than space
|
44
|
+
|
45
|
+
def test_nonspace_positive__indent
|
46
|
+
assert_equal '----xyz', "xyz".indent(4, '-')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_nonspace_0_indent
|
50
|
+
assert_equal 'xyz', 'xyz'.indent(0, '-')
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_nonspace_negative_indent_nonmatching_character
|
54
|
+
assert_equal ' xyz', ' xyz'.indent(-2, '-')
|
55
|
+
assert_equal ' xyz', ' xyz'. indent(-2, '-')
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_nonspace_negative_indent
|
59
|
+
assert_equal '--xyz', '----xyz'.indent(-2, '-')
|
60
|
+
assert_equal 'xyz', '--xyz'.indent(-2, '-')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_special_regexp_characters_are_escaped
|
64
|
+
# make sure . is treated as a literal '.' and not an "any character" wildcard
|
65
|
+
assert_equal ' xyz', ' xyz'.indent(-2, '.')
|
66
|
+
assert_equal 'xyz', '..xyz'.indent(-2, '.')
|
67
|
+
|
68
|
+
assert_equal ' xyz', ' xyz'.indent(-2, '^')
|
69
|
+
assert_equal 'xyz', '^^xyz'.indent(-2, '^')
|
70
|
+
|
71
|
+
assert_equal ' xyz', ' xyz'.indent(-2, '*')
|
72
|
+
assert_equal 'xyz', '**xyz'.indent(-2, '*')
|
73
|
+
end
|
12
74
|
end
|
13
75
|
|
@@ -3,8 +3,9 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TC_String_Lines < Test::Unit::TestCase
|
5
5
|
|
6
|
+
# Ruby 1.9 defined #lines to keep the newline character. Yuk!
|
6
7
|
def test_lines
|
7
|
-
assert_equal( ["a","b",
|
8
|
+
assert_equal( ["a\n","b\n","c"], "a\nb\nc".lines.to_a )
|
8
9
|
end
|
9
10
|
|
10
11
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'facets/string/newlines'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_String_NewLines < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# Since Ruby 1.9 defined #lines to keep the newline character,
|
7
|
+
# we have defined #newlines to leave them out.
|
8
|
+
def test_newlines
|
9
|
+
assert_equal( ["a","b","c"], "a\nb\nc".newlines.to_a )
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
@@ -4,11 +4,7 @@ require 'time'
|
|
4
4
|
|
5
5
|
class TC_Time_Stamp < Test::Unit::TestCase
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
# TODO Problem with TIMEZONE.
|
7
|
+
# TODO: Problem with TIMEZONE.
|
12
8
|
|
13
9
|
#def test_stamp_01
|
14
10
|
# t = Time.parse('4/20/2005 15:37')
|
@@ -16,13 +12,14 @@ class TC_Time_Stamp < Test::Unit::TestCase
|
|
16
12
|
#end
|
17
13
|
|
18
14
|
def test_stamp_02
|
19
|
-
t = Time.parse('
|
15
|
+
t = Time.parse('2005-04-20 15:37')
|
20
16
|
assert_equal( "April 20, 2005 15:37", t.stamp(:long) )
|
21
17
|
end
|
22
18
|
|
23
19
|
def test_stamp_03
|
24
|
-
t = Time.parse('
|
20
|
+
t = Time.parse('2005-04-20 15:37')
|
25
21
|
assert_equal( "20 Apr 15:37", t.stamp(:short) )
|
26
22
|
end
|
27
23
|
|
28
24
|
end
|
25
|
+
|