quality_extensions 0.1.4 → 1.0.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 (68) hide show
  1. data/lib/quality_extensions/all.rb +1 -1
  2. data/lib/quality_extensions/array/average.rb +2 -1
  3. data/lib/quality_extensions/array/classify.rb +3 -1
  4. data/lib/quality_extensions/array/expand_ranges.rb +3 -1
  5. data/lib/quality_extensions/array/group_by.rb +3 -1
  6. data/lib/quality_extensions/array/sequence.rb +2 -0
  7. data/lib/quality_extensions/array/shell_escape.rb +11 -6
  8. data/lib/quality_extensions/array/to_a_recursive.rb +1 -0
  9. data/lib/quality_extensions/array/to_query_string.rb +2 -0
  10. data/lib/quality_extensions/colored/toggleability.rb +2 -2
  11. data/lib/quality_extensions/console/command.rb +4 -3
  12. data/lib/quality_extensions/date/deprecated.rb +2 -0
  13. data/lib/quality_extensions/date/iso8601.rb +4 -1
  14. data/lib/quality_extensions/date/month_ranges.rb +2 -0
  15. data/lib/quality_extensions/dir/each_child.rb +1 -0
  16. data/lib/quality_extensions/exception/inspect_with_backtrace.rb +4 -2
  17. data/lib/quality_extensions/file/exact_match_regexp.rb +1 -0
  18. data/lib/quality_extensions/hash/assert_has_only_keys.rb +48 -0
  19. data/lib/quality_extensions/hash/to_date.rb +2 -0
  20. data/lib/quality_extensions/hash/to_query_string.rb +8 -2
  21. data/lib/quality_extensions/kernel/backtrace.rb +4 -2
  22. data/lib/quality_extensions/kernel/capture_output.rb +3 -2
  23. data/lib/quality_extensions/kernel/die.rb +4 -1
  24. data/lib/quality_extensions/kernel/example_printer.rb +3 -3
  25. data/lib/quality_extensions/kernel/remove_const.rb +3 -2
  26. data/lib/quality_extensions/kernel/remove_module.rb +3 -2
  27. data/lib/quality_extensions/kernel/require_all.rb +5 -3
  28. data/lib/quality_extensions/kernel/require_once.rb +1 -0
  29. data/lib/quality_extensions/kernel/simulate_input.rb +1 -0
  30. data/lib/quality_extensions/kernel/trap_chain.rb +3 -0
  31. data/lib/quality_extensions/module/alias_method_chain.rb +3 -15
  32. data/lib/quality_extensions/module/ancestry_of_instance_method.rb +19 -0
  33. data/lib/quality_extensions/module/basename.rb +5 -8
  34. data/lib/quality_extensions/module/bool_attr_accessor.rb +3 -1
  35. data/lib/quality_extensions/module/by_name.rb +76 -0
  36. data/lib/quality_extensions/module/class_methods.rb +2 -0
  37. data/lib/quality_extensions/module/create.rb +6 -5
  38. data/lib/quality_extensions/module/guard_method.rb +4 -1
  39. data/lib/quality_extensions/module/join.rb +2 -2
  40. data/lib/quality_extensions/module/malias_method_chain.rb +3 -2
  41. data/lib/quality_extensions/module/namespace.rb +1 -1
  42. data/lib/quality_extensions/module/parents.rb +2 -2
  43. data/lib/quality_extensions/module/remove_const.rb +3 -2
  44. data/lib/quality_extensions/module/split.rb +2 -1
  45. data/lib/quality_extensions/month.rb +2 -0
  46. data/lib/quality_extensions/mutex/if_available.rb +2 -0
  47. data/lib/quality_extensions/nil_method_missing.rb +227 -0
  48. data/lib/quality_extensions/object/ancestry_of_method.rb +2 -0
  49. data/lib/quality_extensions/object/if_else.rb +1 -1
  50. data/lib/quality_extensions/object/ignore_access.rb +3 -2
  51. data/lib/quality_extensions/object/mcall.rb +3 -1
  52. data/lib/quality_extensions/object/methods.rb +3 -2
  53. data/lib/quality_extensions/object/send_if.rb +2 -1
  54. data/lib/quality_extensions/object/singleton_send.rb +2 -0
  55. data/lib/quality_extensions/safe_nil.rb +3 -5
  56. data/lib/quality_extensions/string/digits_only.rb +2 -0
  57. data/lib/quality_extensions/string/each_char_with_index.rb +1 -0
  58. data/lib/quality_extensions/string/md5.rb +2 -0
  59. data/lib/quality_extensions/string/shell_escape.rb +4 -2
  60. data/lib/quality_extensions/string/to_underscored_label.rb +2 -0
  61. data/lib/quality_extensions/string/with_knowledge_of_color.rb +3 -0
  62. data/lib/quality_extensions/symbol/constantize.rb +2 -1
  63. data/lib/quality_extensions/symbol/match.rb +2 -1
  64. data/lib/quality_extensions/test/assert_anything.rb +1 -0
  65. data/lib/quality_extensions/test/difference_highlighting.rb +2 -2
  66. data/lib/quality_extensions/time/deprecated.rb +2 -0
  67. data/test/all.rb +8 -2
  68. metadata +86 -83
@@ -1,4 +1,4 @@
1
1
  require File.dirname(__FILE__) + "/kernel/require_all"
2
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)!
3
+ :exclude => %r{(^|/)test/|nil_method_missing.rb}, # Exclude files with side-effects: Don't include anything in test/ because those files will include test/unit, which causes tests to automatically be run
4
4
  :exclude_files => 'all.rb'
@@ -3,7 +3,7 @@
3
3
  # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
4
4
  # License:: Ruby License
5
5
  # Submit to Facets?:: Yes.
6
- # Wait, so Facets has mode (http://facets.rubyforge.org/src/doc/rdoc/core/classes/Enumerable.html#M001253) but it doesn't have mean/average?
6
+ # Wait, so Facets has mode (http://facets.rubyforge.org/src/doc/rdoc/classes/Enumerable.html#M001253) but it doesn't have mean/average?
7
7
  # Whether or not this Array#average is included, Facets ought to have an Enumerable#mean/average similar to mode that uses each iterator rather than Array#size. (Still might want to keep this version if it's more efficient for Arrays?)
8
8
  #++
9
9
 
@@ -29,6 +29,7 @@ end
29
29
  #
30
30
  =begin test
31
31
  require 'test/unit'
32
+
32
33
  class TheTest < Test::Unit::TestCase
33
34
  def test_average
34
35
  assert_equal 2, [0, 4].average
@@ -10,9 +10,10 @@
10
10
  # column from the array, which can be nice, since the classification key in the hash makes it somewhat redundant.
11
11
  #++
12
12
 
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
13
14
  require 'rubygems'
14
15
  gem 'facets'
15
- require 'facet/array/to_hash'
16
+ require 'facets/to_hash'
16
17
  class Array
17
18
 
18
19
  =begin rdoc
@@ -51,6 +52,7 @@ end
51
52
  # |_|\___||___/\__|
52
53
  #
53
54
  =begin test
55
+ require 'test/unit'
54
56
  require 'set'
55
57
 
56
58
  class TheTest < Test::Unit::TestCase
@@ -5,8 +5,9 @@
5
5
  # Submit to Facets?:: Yes.
6
6
  #++
7
7
 
8
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
8
9
  require 'rubygems'
9
- require 'facets/core/kernel/silence_warnings'
10
+ require 'facets/kernel/silence'
10
11
 
11
12
  class Array
12
13
  # Expands (calls +to_a+ on) all Ranges contained in this array, replacing the range with the list of *elements* that the range represents.
@@ -39,6 +40,7 @@ end
39
40
  #
40
41
  =begin test
41
42
  require 'test/unit'
43
+
42
44
  class TheTest < Test::Unit::TestCase
43
45
  def test_1
44
46
  assert_equal [1, 2, 3], [1, 2, 3].expand_ranges
@@ -10,9 +10,10 @@
10
10
  # *not* in "table" form (whose elements are *not* all arrays of equal size and might not even be *arrays*).
11
11
  #++
12
12
 
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
13
14
  require 'rubygems'
14
15
  gem 'facets'
15
- require 'facet/array/delete_values_at'
16
+ require 'facets/array/delete'
16
17
  class Array
17
18
 
18
19
  =begin rdoc
@@ -71,6 +72,7 @@ end
71
72
  # |_|\___||___/\__|
72
73
  #
73
74
  =begin test
75
+ require 'test/unit'
74
76
  require 'set'
75
77
 
76
78
  class TheTest < Test::Unit::TestCase
@@ -44,6 +44,8 @@ end
44
44
  # |_|\___||___/\__|
45
45
  #
46
46
  =begin test
47
+ require 'test/unit'
48
+
47
49
  class TheTest < Test::Unit::TestCase
48
50
  def setup
49
51
  @sequence = ['a', 'b', 'c']
@@ -5,14 +5,16 @@
5
5
  # Submit to Facets?:: Yes.
6
6
  #++
7
7
 
8
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
8
9
  require 'rubygems'
9
- require 'facets/core/symbol/to_proc' unless Symbol.method_defined?(:to_proc)
10
- require 'facets/core/kernel/require_local'
10
+ require 'facets/ruby' # to_proc
11
+ require 'facets/kernel/load'
11
12
  require_local '../string/shell_escape.rb'
12
13
 
13
14
  class Array
14
15
  def shell_escape
15
- self.map(&:shell_escape)
16
+ #self.map(&:shell_escape)
17
+ Escape.shell_command(self)
16
18
  end
17
19
  end
18
20
 
@@ -24,13 +26,16 @@ end
24
26
  #
25
27
  =begin test
26
28
  require 'test/unit'
29
+
27
30
  class TheTest < Test::Unit::TestCase
28
31
  def test_1
29
- assert_equal ['a'], ['a'].shell_escape
32
+ assert_equal 'a', ['a'].shell_escape.to_s
30
33
  end
31
34
  def test_2
32
- assert_equal ["arg1", "'multiple words for single argument'"],
33
- ['arg1', 'multiple words for single argument'].shell_escape
35
+ #assert_equal ["arg1", "'multiple words for single argument'"],
36
+ # ['arg1', 'multiple words for single argument'].shell_escape.to_s
37
+ assert_equal "arg1 'multiple words for single argument'",
38
+ ['arg1', 'multiple words for single argument'].shell_escape.to_s
34
39
  end
35
40
  end
36
41
  =end
@@ -29,6 +29,7 @@ end
29
29
  #
30
30
  =begin test
31
31
  require 'test/unit'
32
+
32
33
  class TheTest < Test::Unit::TestCase
33
34
  def test_1
34
35
  assert_equal [[1, 2, 3], [5, 6, 7]], [1..3, 5..7].to_a_recursive
@@ -46,6 +46,8 @@ end
46
46
  # |_|\___||___/\__|
47
47
  #
48
48
  =begin test
49
+ require 'test/unit'
50
+
49
51
  class TheTest < Test::Unit::TestCase
50
52
  #-------------------------------------------------------------------------------------------------
51
53
  # Array:
@@ -6,12 +6,12 @@
6
6
  # Developer notes::
7
7
  #++
8
8
 
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
9
10
  require 'rubygems'
10
11
  gem 'colored'
11
12
  require 'colored'
12
13
  gem 'facets'
13
- require 'facets/core/module/alias_method_chain'
14
- gem 'quality_extensions'
14
+ require 'facets/module/alias'
15
15
  require 'quality_extensions/module/guard_method'
16
16
 
17
17
  class String
@@ -29,9 +29,10 @@
29
29
  # Copyright:: Copyright (c) 2005-2007
30
30
  # License:: Ruby License
31
31
 
32
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
32
33
  require 'shellwords'
33
34
  require 'rubygems'
34
- require 'facet/string/modulize'
35
+ require 'facets/style' #modulize
35
36
  require 'escape' # http://www.a-k-r.org/escape/
36
37
 
37
38
  # TODO Test
@@ -279,7 +280,7 @@ class Console::Command
279
280
  # Development notes:
280
281
  # * Currently requires you to pass the subcommand module's "self" to this method. I didn't know of a better way to cause it to create the instance methods in *that* module rather than here in Console::Command.
281
282
  # * Possible alternatives:
282
- # * Binding.of_caller() (http://facets.rubyforge.org/src/doc/rdoc/core/classes/Binding.html) -- wary of using it if it depends on Continuations, which I understand are deprecated
283
+ # * Binding.of_caller() (http://facets.rubyforge.org/src/doc/rdoc/classes/Binding.html) -- wary of using it if it depends on Continuations, which I understand are deprecated
283
284
  # * copy the pass_through class method to each subcommand module so that calls will be in the module's context...
284
285
  def pass_through(options, mod)
285
286
  options.each do |method_names, arity|
@@ -396,7 +397,7 @@ class Console::Command
396
397
 
397
398
  # Extend subcommand option module
398
399
  #subconst = subcommand.gsub(/\W/,'_').capitalize
399
- subconst = @subcommand.modulize
400
+ subconst = @subcommand.style(:modulize)
400
401
  #p self.class.constants if $debug
401
402
  if self.class.const_defined?(subconst)
402
403
  puts "Extending self (#{self.class}) with subcommand module #{subconst}" if $debug
@@ -27,6 +27,8 @@ end
27
27
  # |_|\___||___/\__|
28
28
  #
29
29
  =begin test
30
+ require 'test/unit'
31
+
30
32
  class TheTest < Test::Unit::TestCase
31
33
  def test_date_for_report
32
34
  assert_equal 'Jun 18, 2006', Date.new(2006, 6, 18).date_for_report()
@@ -5,9 +5,10 @@
5
5
  # Submit to Facets?:: Yes.
6
6
  #++
7
7
 
8
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
8
9
  require 'date'
9
10
  require 'rubygems'
10
- require 'facets/core/date/to_time'
11
+ require 'facets/date'
11
12
 
12
13
  class Date
13
14
  def iso8601
@@ -23,6 +24,8 @@ end
23
24
  # |_|\___||___/\__|
24
25
  #
25
26
  =begin test
27
+ require 'test/unit'
28
+
26
29
  class TheTest < Test::Unit::TestCase
27
30
  def test_iso8601
28
31
  assert_equal '2006-07-18', Date.civil(2006, 7, 18).iso8601()
@@ -48,6 +48,8 @@ end
48
48
  # |_|\___||___/\__|
49
49
  #
50
50
  =begin test
51
+ require 'test/unit'
52
+
51
53
  class TheTest < Test::Unit::TestCase
52
54
 
53
55
  #-------------------------------------------------------------------------------------------------
@@ -24,6 +24,7 @@ end
24
24
  # |_|\___||___/\__|
25
25
  #
26
26
  =begin test
27
+ require 'test/unit'
27
28
 
28
29
  require 'fileutils'
29
30
 
@@ -7,8 +7,9 @@
7
7
  # * Add depth argument to inspect()?
8
8
  #++
9
9
 
10
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
10
11
  require 'rubygems'
11
- require 'facets/core/module/alias_method_chain'
12
+ require 'facets/module/alias'
12
13
 
13
14
  class Exception
14
15
  # Use this if you want to output an exception with all the details that you'd *normally* see if the exception went unrescued
@@ -33,8 +34,9 @@ end
33
34
  # |_|\___||___/\__|
34
35
  #
35
36
  =begin test
37
+ require 'test/unit'
36
38
  require 'rubygems'
37
- require 'facets/core/string/lines'
39
+ require 'facets/ruby' # lines
38
40
 
39
41
  class TheTest < Test::Unit::TestCase
40
42
  def raise_an_error(arg = nil)
@@ -21,6 +21,7 @@ end
21
21
  # |_|\___||___/\__|
22
22
  #
23
23
  =begin test
24
+ require 'test/unit'
24
25
 
25
26
  class TheTest < Test::Unit::TestCase
26
27
  def test_1
@@ -0,0 +1,48 @@
1
+ #--
2
+ # Author:: Trans?
3
+ # Copyright:: Copyright (c) Trans?
4
+ # License:: Ruby License
5
+ # Submit to Facets?:: No. Copied from facets-1.8.54/lib/facets/core/hash/assert_has_only_keys.rb. No longer exists in 2.4.1.
6
+ # Developer notes::
7
+ #++
8
+
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
10
+ require 'rubygems'
11
+ require 'facets/hash/keys'
12
+
13
+ class Hash
14
+
15
+ # Returns true is hash has only then given keys,
16
+ # otherwise throws an ArgumentError.
17
+ #
18
+ # h = { :a => 1, :b => 2 }
19
+ # h.assert_has_only_keys( :a, :b ) #=> true
20
+ # h.assert_has_only_keys( :a ) #=> ArgumentError
21
+ #
22
+ def assert_has_only_keys(*check_keys)
23
+ raise(ArgumentError, "has unexpected key(s)") unless has_only_keys?(*check_keys)
24
+ end
25
+
26
+ end
27
+
28
+
29
+ # _____ _
30
+ # |_ _|__ ___| |_
31
+ # | |/ _ \/ __| __|
32
+ # | | __/\__ \ |_
33
+ # |_|\___||___/\__|
34
+ #
35
+ =begin test
36
+
37
+ require 'test/unit'
38
+
39
+ class TCHash < Test::Unit::TestCase
40
+
41
+ def test_assert_has_only_keys
42
+ assert_nothing_raised { { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b,:c) }
43
+ assert_raises( ArgumentError ) { { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b) }
44
+ end
45
+
46
+ end
47
+
48
+ =end
@@ -23,6 +23,8 @@ end
23
23
  # |_|\___||___/\__|
24
24
  #
25
25
  =begin test
26
+ require 'test/unit'
27
+
26
28
  class TheTest < Test::Unit::TestCase
27
29
  def test_Hash_to_date
28
30
  assert_equal Date.new(2007, 1, 22), {:year => "2007", :month => "01", :day => 22}.to_date
@@ -5,9 +5,10 @@
5
5
  # Submit to Facets?:: Yes.
6
6
  #++
7
7
 
8
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
8
9
  autoload :CGI, 'cgi'
9
10
  require 'rubygems'
10
- require 'facets/core/kernel/require_local'
11
+ require 'facets/kernel/load'
11
12
  require_local '../array/to_query_string.rb'
12
13
 
13
14
  class Hash
@@ -69,6 +70,10 @@ end
69
70
  # |_|\___||___/\__|
70
71
  #
71
72
  =begin test
73
+ require 'test/unit'
74
+ require 'rubygems'
75
+ require 'set'
76
+
72
77
  class TheTest < Test::Unit::TestCase
73
78
  def test_hash_to_query_string_nesting
74
79
  data = {
@@ -81,7 +86,8 @@ class TheTest < Test::Unit::TestCase
81
86
  }
82
87
  }
83
88
  }
84
- assert_equal 'foo=bar&names[common]=smith&names[uncommon][first]=lance&names[uncommon][last]=wilheiminkauf', data.to_query_string
89
+ assert_equal ['foo=bar', 'names[common]=smith', 'names[uncommon][first]=lance', 'names[uncommon][last]=wilheiminkauf'].to_set,
90
+ data.to_query_string.split(/&/).to_set
85
91
  end
86
92
  def test_hash_to_query_string_nesting_2
87
93
  data = {
@@ -5,8 +5,6 @@
5
5
  # Submit to Facets?:: Not sure. This might not be necessary if caller() actually works reliably.
6
6
  #++
7
7
 
8
- require "rubygems"
9
- require "facet/string/lines"
10
8
 
11
9
  module Kernel
12
10
  # Equivalent to calling caller(0)
@@ -40,6 +38,10 @@ end
40
38
  # |_|\___||___/\__|
41
39
  #
42
40
  =begin test
41
+ require 'test/unit'
42
+ require "rubygems"
43
+ require "facets/ruby" # lines
44
+
43
45
  class TheTest < Test::Unit::TestCase
44
46
  def test_1_level
45
47
  assert_match /^.*backtrace.rb:\d*:in `test_1_level'$/, backtrace[0]
@@ -7,7 +7,7 @@
7
7
 
8
8
  # :todo: Can we find a simpler way to do this based on facets' silence_stream?
9
9
  #
10
- # File lib/facets/core/kernel/silence_stream.rb, line 13
10
+ # File lib/facets/kernel/silence_stream.rb, line 13
11
11
  # def silence_stream(stream)
12
12
  # old_stream = stream.dup
13
13
  # stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
@@ -17,9 +17,10 @@
17
17
  # stream.reopen(old_stream)
18
18
  # end
19
19
 
20
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
20
21
  require 'stringio'
21
22
  require 'rubygems'
22
- require 'facets/more/dictionary'
23
+ require 'facets/dictionary'
23
24
 
24
25
  module Kernel
25
26
 
@@ -6,6 +6,7 @@
6
6
  # Deprecated. Because I discovered Kernel::abort !
7
7
  #++
8
8
 
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
9
10
  module Kernel
10
11
  def die(message, exit_code = 1)
11
12
  $stderr.puts message
@@ -20,9 +21,11 @@ end
20
21
  # |_|\___||___/\__|
21
22
  #
22
23
  =begin test
24
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
25
+ require 'test/unit'
23
26
  require 'rubygems'
24
27
  require 'quality_extensions/kernel/capture_output'
25
- #require 'facets/core/kernel/require_local'
28
+ #require 'facets/kernel/load'
26
29
  #require_local './capture_output'
27
30
 
28
31
  class TheTest < Test::Unit::TestCase
@@ -11,8 +11,9 @@
11
11
  # * Add class method for ExamplePrinter to set a template for use by xmp? So if you don't like the default ("=> #{result}"), you can specify your own...
12
12
  #++
13
13
 
14
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..')
14
15
  require 'rubygems'
15
- #require 'facets/core/binding/self/of_caller'
16
+ #require 'facets/binding/self/of_caller'
16
17
 
17
18
  # This was written because the irb/xmp that was already available seemed to be
18
19
  # needlessly complex and needlessly dependent upon "irb" stuff. This
@@ -57,9 +58,8 @@ include ExamplePrinter
57
58
  =begin test
58
59
  require 'test/unit'
59
60
  require 'rubygems'
60
- gem 'quality_extensions'
61
61
  require 'quality_extensions/kernel/capture_output'
62
- require 'facets/core/string/margin'
62
+ require 'facets/string/tab'
63
63
 
64
64
  class TheTest < Test::Unit::TestCase
65
65
  def test_puts_statement