facets 2.7.0 → 2.8.0

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.
Files changed (130) hide show
  1. data/HISTORY.rdoc +135 -294
  2. data/MANIFEST +40 -91
  3. data/NOTES +1 -1
  4. data/README.rdoc +10 -8
  5. data/Rakefile +11 -34
  6. data/demo/{hook.rd → hook.rdoc} +2 -0
  7. data/demo/{scenario_require.rd → scenario_require.rdoc} +3 -0
  8. data/lib/core/facets-live.rb +7 -5
  9. data/lib/core/facets.rb +379 -359
  10. data/lib/core/facets/array/conjoin.rb +2 -2
  11. data/lib/core/facets/array/pad.rb +1 -1
  12. data/lib/core/facets/array/recursively.rb +2 -2
  13. data/lib/core/facets/array/splice.rb +1 -1
  14. data/lib/core/facets/binding/caller.rb +2 -4
  15. data/lib/core/facets/comparable/comparable.rb +2 -2
  16. data/lib/core/facets/dir/ascend.rb +3 -0
  17. data/lib/core/facets/dir/recurse.rb +4 -0
  18. data/lib/core/facets/duplicable.rb +6 -8
  19. data/lib/core/facets/enumerable/count.rb +22 -13
  20. data/lib/core/facets/enumerable/map_detect.rb +28 -0
  21. data/lib/core/facets/enumerable/mash.rb +13 -5
  22. data/lib/core/facets/enumerable/per.rb +3 -1
  23. data/lib/core/facets/hash/count.rb +14 -0
  24. data/lib/core/facets/hash/data.rb +14 -0
  25. data/lib/core/facets/kernel/__method__.rb +1 -1
  26. data/lib/core/facets/kernel/d.rb +9 -8
  27. data/lib/core/facets/kernel/eigenclass.rb +20 -0
  28. data/lib/core/facets/kernel/extend.rb +10 -0
  29. data/lib/core/facets/kernel/instance_class.rb +1 -0
  30. data/lib/core/facets/kernel/instance_variables.rb +6 -6
  31. data/lib/core/facets/kernel/meta_alias.rb +18 -0
  32. data/lib/core/facets/kernel/meta_class.rb +17 -0
  33. data/lib/core/facets/kernel/meta_def.rb +18 -0
  34. data/lib/core/facets/kernel/meta_eval.rb +18 -0
  35. data/lib/core/facets/kernel/object_hexid.rb +21 -6
  36. data/lib/core/facets/kernel/object_state.rb +4 -2
  37. data/lib/core/facets/kernel/populate.rb +3 -1
  38. data/lib/core/facets/kernel/with.rb +1 -1
  39. data/lib/core/facets/metaid.rb +6 -93
  40. data/lib/core/facets/module/class_def.rb +2 -0
  41. data/lib/core/facets/module/extend.rb +10 -11
  42. data/lib/core/facets/module/is.rb +5 -5
  43. data/lib/core/facets/module/module_def.rb +31 -0
  44. data/lib/core/facets/string/camelcase.rb +14 -12
  45. data/lib/core/facets/string/cleanlines.rb +35 -0
  46. data/lib/core/facets/string/edit_distance.rb +62 -0
  47. data/lib/core/facets/string/indent.rb +86 -4
  48. data/lib/core/facets/string/index_all.rb +24 -0
  49. data/lib/core/facets/string/lines.rb +3 -6
  50. data/lib/core/facets/string/margin.rb +2 -1
  51. data/lib/core/facets/string/newlines.rb +35 -0
  52. data/lib/core/facets/string/op_div.rb +14 -0
  53. data/lib/core/facets/string/range.rb +2 -22
  54. data/lib/core/facets/string/range_all.rb +1 -0
  55. data/lib/core/facets/string/range_of_line.rb +1 -0
  56. data/lib/core/facets/string/similarity.rb +92 -0
  57. data/lib/core/facets/string/start_with.rb +6 -6
  58. data/lib/core/facets/string/titlecase.rb +1 -1
  59. data/lib/more/facets/basicobject.rb +16 -15
  60. data/lib/more/facets/blankslate.rb +8 -0
  61. data/lib/more/facets/class_extend.rb +126 -1
  62. data/lib/more/facets/continuation.rb +53 -54
  63. data/lib/more/facets/dictionary.rb +9 -63
  64. data/lib/more/facets/erb.rb +63 -0
  65. data/lib/more/facets/filelist.rb +5 -5
  66. data/lib/more/facets/hashbuilder.rb +101 -0
  67. data/lib/more/facets/inheritor.rb +36 -45
  68. data/lib/more/facets/ini.rb +267 -0
  69. data/lib/more/facets/instance_eval.rb +4 -4
  70. data/lib/more/facets/ioredirect.rb +7 -60
  71. data/lib/more/facets/linkedlist.rb +195 -0
  72. data/lib/more/facets/matcher.rb +140 -0
  73. data/lib/more/facets/memoizer.rb +64 -0
  74. data/lib/more/facets/methodspace.rb +9 -4
  75. data/lib/more/facets/module/class_extend.rb +2 -121
  76. data/lib/more/facets/ostruct.rb +9 -9
  77. data/lib/more/facets/pathlist.rb +1 -9
  78. data/lib/more/facets/pathname.rb +11 -4
  79. data/lib/more/facets/plugin_manager.rb +50 -0
  80. data/lib/more/facets/random.rb +25 -3
  81. data/lib/more/facets/roman.rb +174 -0
  82. data/lib/more/facets/semaphore.rb +92 -0
  83. data/lib/more/facets/shellwords.rb +21 -48
  84. data/lib/more/facets/succ.rb +1 -1
  85. data/meta/{modified → released} +0 -0
  86. data/meta/repository +1 -0
  87. data/meta/suite +1 -0
  88. data/meta/version +1 -1
  89. data/script/conflicts +63 -0
  90. data/script/methods +49 -0
  91. data/test/core/binding/test_caller.rb +11 -4
  92. data/test/core/enumerable/test_count.rb +19 -10
  93. data/test/core/enumerable/test_map_detect.rb +75 -0
  94. data/test/core/enumerable/test_take.rb +1 -1
  95. data/test/core/kernel/test_object_hexid.rb +2 -1
  96. data/test/core/proc/test_to_method.rb +1 -1
  97. data/test/core/string/test_cleanlines.rb +11 -0
  98. data/test/core/string/test_indent.rb +66 -4
  99. data/test/core/string/test_lines.rb +2 -1
  100. data/test/core/string/test_newlines.rb +13 -0
  101. data/test/core/time/test_change.rb +1 -1
  102. data/test/core/time/test_stamp.rb +4 -7
  103. data/test/core/unboundmethod/test_name.rb +1 -1
  104. data/test/more/test_basicobject.rb +1 -20
  105. data/test/more/test_class_extend.rb +7 -0
  106. data/test/more/test_continuation.rb +8 -6
  107. data/test/more/test_inheritor.rb +12 -6
  108. data/test/more/test_random.rb +19 -10
  109. data/test/more/test_shellwords.rb +33 -0
  110. metadata +60 -31
  111. data/TODO +0 -5
  112. data/doc/README.core +0 -102
  113. data/doc/README.more +0 -61
  114. data/doc/manual/about.rb +0 -47
  115. data/doc/manual/annotations.rdoc +0 -60
  116. data/doc/manual/associations.rdoc +0 -55
  117. data/doc/manual/blockups.rdoc +0 -101
  118. data/doc/manual/capsule.rdoc +0 -34
  119. data/doc/manual/command.rdoc +0 -177
  120. data/doc/manual/core.rdoc +0 -37
  121. data/doc/manual/faq.rdoc +0 -32
  122. data/doc/manual/typecast.html +0 -112
  123. data/lib/more/facets/capsule.rb +0 -258
  124. data/lib/more/facets/coroutine.rb +0 -159
  125. data/lib/more/facets/enumerablepass.rb +0 -3
  126. data/lib/more/facets/fileable.rb +0 -162
  127. data/lib/more/facets/progressbar.rb +0 -253
  128. data/lib/more/facets/recorder.rb +0 -108
  129. data/meta/releases +0 -14
  130. data/test/more/test_coroutine.rb +0 -46
@@ -1,4 +1,4 @@
1
- class Integer
1
+ class Fixnum
2
2
 
3
3
  # Allows #succ to take _n_ increments.
4
4
  #
File without changes
@@ -0,0 +1 @@
1
+ git@github.com:rubyworks/facets.git
@@ -0,0 +1 @@
1
+ rubyworks
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.8.0
@@ -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
+
@@ -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
- def test_callee
37
- assert_equal( :setup, @bind.__callee__ )
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
- def test_method
41
- assert_equal( 'setup', @bind.__method__ )
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 test_count_01
7
- e = [ 'a', '1', 'a' ]
8
- assert_equal( 1, e.count('1') )
9
- assert_equal( 2, e.count('a') )
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 test_count_02
13
- e = [ ['a',2], ['a',2], ['a',2], ['b',1] ]
14
- assert_equal( 3, e.count(['a',2]) )
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 test_count_03
18
- e = { 'a' => 2, 'a' => 2, 'b' => 1 }
19
- assert_equal(1, e.count(['a',2]))
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
@@ -1,7 +1,7 @@
1
1
  require 'facets/enumerable/take'
2
2
  require 'test/unit'
3
3
 
4
- class TC_Enumerable_Defer < Test::Unit::TestCase
4
+ class TC_Enumerable_Take < Test::Unit::TestCase
5
5
 
6
6
  SOURCE = (1..1/0.0) # infinite Enumerable object
7
7
 
@@ -5,7 +5,8 @@ class TCKernel < Test::Unit::TestCase
5
5
 
6
6
  def test_object_hexid
7
7
  o = Object.new
8
- assert( o.inspect.index(o.object_hexid) )
8
+ assert_equal(o.inspect, "#<Object:#{o.object_hexid}>")
9
+ #assert(o.inspect.index(o.object_hexid))
9
10
  end
10
11
 
11
12
  end
@@ -19,7 +19,7 @@ class TestProc < Test::Unit::TestCase
19
19
 
20
20
  assert_equal(:foo, tmeth.call)
21
21
  assert_respond_to( :foo, :tryit )
22
- assert_equal( :foo, :foo.tryit(1) )
22
+ assert_equal( :foo, :foo.tryit )
23
23
  end
24
24
 
25
25
  end
@@ -0,0 +1,11 @@
1
+ require 'facets/string/cleanlines'
2
+ require 'test/unit'
3
+
4
+ class TC_String_CleanLines < Test::Unit::TestCase
5
+
6
+ def test_cleanlines
7
+ assert_equal( ["a","b","c"], "a \n b \nc".cleanlines.to_a )
8
+ end
9
+
10
+ end
11
+
@@ -3,11 +3,73 @@ require 'test/unit'
3
3
 
4
4
  class TC_String_Indent < Test::Unit::TestCase
5
5
 
6
- def test_indent
7
- a = "xyz".indent(4)
8
- assert_equal( ' ', a[0..3] )
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",'c'], "a\nb\nc".lines.to_a )
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
+
@@ -5,7 +5,7 @@ require 'time'
5
5
  class TC_Time_Change < Test::Unit::TestCase
6
6
 
7
7
  def test_change
8
- t = Time.parse('4/20/2006 15:37')
8
+ t = Time.parse('2006-04-20 15:37')
9
9
  n = Time.now
10
10
  n = n.change( :month=>4, :day=>20, :hour=>15, :min=>37, :year=>2006 )
11
11
  assert_equal( t, n )
@@ -4,11 +4,7 @@ require 'time'
4
4
 
5
5
  class TC_Time_Stamp < Test::Unit::TestCase
6
6
 
7
- def setup
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('4/20/2005 15:37')
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('4/20/2005 15:37')
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
+