qualitysmith_extensions 0.0.3

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 (47) hide show
  1. data/Readme +72 -0
  2. data/lib/qualitysmith_extensions/all.rb +2 -0
  3. data/lib/qualitysmith_extensions/array/all.rb +2 -0
  4. data/lib/qualitysmith_extensions/array/average.rb +42 -0
  5. data/lib/qualitysmith_extensions/array/expand_ranges.rb +48 -0
  6. data/lib/qualitysmith_extensions/array/group_by.rb +112 -0
  7. data/lib/qualitysmith_extensions/array/sequence.rb +64 -0
  8. data/lib/qualitysmith_extensions/array/shell_escape.rb +34 -0
  9. data/lib/qualitysmith_extensions/array/to_a_recursive.rb +39 -0
  10. data/lib/qualitysmith_extensions/array/to_query_string.rb +94 -0
  11. data/lib/qualitysmith_extensions/collection_extensions_for_cgi.rb +2 -0
  12. data/lib/qualitysmith_extensions/console/command.facets.1.8.51.rb +749 -0
  13. data/lib/qualitysmith_extensions/console/command.rb +940 -0
  14. data/lib/qualitysmith_extensions/date/all.rb +2 -0
  15. data/lib/qualitysmith_extensions/date/deprecated.rb +38 -0
  16. data/lib/qualitysmith_extensions/date/iso8601.rb +29 -0
  17. data/lib/qualitysmith_extensions/date/month_ranges.rb +120 -0
  18. data/lib/qualitysmith_extensions/enumerable/enum.rb +72 -0
  19. data/lib/qualitysmith_extensions/file/exact_match_regexp.rb +32 -0
  20. data/lib/qualitysmith_extensions/file_test/binary_file.rb +108 -0
  21. data/lib/qualitysmith_extensions/filter_output.rb +107 -0
  22. data/lib/qualitysmith_extensions/global_variable_set.rb +151 -0
  23. data/lib/qualitysmith_extensions/hash/all.rb +2 -0
  24. data/lib/qualitysmith_extensions/hash/to_date.rb +32 -0
  25. data/lib/qualitysmith_extensions/hash/to_query_string.rb +119 -0
  26. data/lib/qualitysmith_extensions/kernel/all.rb +2 -0
  27. data/lib/qualitysmith_extensions/kernel/backtrace.rb +69 -0
  28. data/lib/qualitysmith_extensions/kernel/capture_output.rb +113 -0
  29. data/lib/qualitysmith_extensions/kernel/die.rb +34 -0
  30. data/lib/qualitysmith_extensions/kernel/require_all.rb +118 -0
  31. data/lib/qualitysmith_extensions/kernel/require_once.rb +16 -0
  32. data/lib/qualitysmith_extensions/month.rb +62 -0
  33. data/lib/qualitysmith_extensions/object/singleton.rb +95 -0
  34. data/lib/qualitysmith_extensions/simulate_input.rb +51 -0
  35. data/lib/qualitysmith_extensions/string/all.rb +2 -0
  36. data/lib/qualitysmith_extensions/string/digits_only.rb +25 -0
  37. data/lib/qualitysmith_extensions/string/md5.rb +27 -0
  38. data/lib/qualitysmith_extensions/string/shell_escape.rb +41 -0
  39. data/lib/qualitysmith_extensions/string/to_underscored_label.rb +35 -0
  40. data/lib/qualitysmith_extensions/test/assert_changed.rb +64 -0
  41. data/lib/qualitysmith_extensions/test/assert_exception.rb +63 -0
  42. data/lib/qualitysmith_extensions/test/assert_includes.rb +34 -0
  43. data/lib/qualitysmith_extensions/test/assert_user_error.rb +34 -0
  44. data/lib/qualitysmith_extensions/time/all.rb +2 -0
  45. data/lib/qualitysmith_extensions/time/deprecated.rb +29 -0
  46. data/test/all.rb +16 -0
  47. metadata +94 -0
@@ -0,0 +1,25 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ class String
7
+ # Strips out everything except digits.
8
+ def digits_only
9
+ self.gsub(/[^0-9]/, "")
10
+ end
11
+ end
12
+
13
+ # _____ _
14
+ # |_ _|__ ___| |_
15
+ # | |/ _ \/ __| __|
16
+ # | | __/\__ \ |_
17
+ # |_|\___||___/\__|
18
+ #
19
+ =begin test
20
+ class TheTest < Test::Unit::TestCase
21
+ def test_digits_only
22
+ assert_equal "123", "$!@)(*&abc123[]{}".digits_only
23
+ end
24
+ end
25
+ =end
@@ -0,0 +1,27 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ require "digest/md5"
7
+
8
+ class String
9
+ # Because it's so much more natural to have this as a method of the string rather than having to call <tt>Digest::MD5.hexdigest(string)</tt>.
10
+ def md5
11
+ return Digest::MD5.hexdigest(self)
12
+ end
13
+ end
14
+
15
+ # _____ _
16
+ # |_ _|__ ___| |_
17
+ # | |/ _ \/ __| __|
18
+ # | | __/\__ \ |_
19
+ # |_|\___||___/\__|
20
+ #
21
+ =begin test
22
+ class TheTest < Test::Unit::TestCase
23
+ def test_md5
24
+ assert_equal "abc".md5, Digest::MD5.hexdigest("abc")
25
+ end
26
+ end
27
+ =end
@@ -0,0 +1,41 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ require 'rubygems'
7
+ require 'escape' # http://www.a-k-r.org/escape/
8
+ require 'extensions/symbol' unless Symbol.method_defined?(:to_proc)
9
+ require 'facets/core/kernel/require_local'
10
+
11
+ class String
12
+ def shell_escape
13
+ Escape.shell_command([self])
14
+ end
15
+ end
16
+
17
+ # _____ _
18
+ # |_ _|__ ___| |_
19
+ # | |/ _ \/ __| __|
20
+ # | | __/\__ \ |_
21
+ # |_|\___||___/\__|
22
+ #
23
+ =begin test
24
+ require 'test/unit'
25
+ class TheTest < Test::Unit::TestCase
26
+ def assert_that_echo_gives_back_what_we_put_in(input)
27
+ input = %q{!&'"`$0 |()<>}
28
+ output = `echo -n #{input.shell_escape}`
29
+ assert_equal input, output
30
+ end
31
+ def test_1
32
+ assert_that_echo_gives_back_what_we_put_in(
33
+ %q{!&'"`$0 |()<>} )
34
+ end
35
+ def test_2
36
+ assert_that_echo_gives_back_what_we_put_in(
37
+ %q{'an arg that's got "quotes"} )
38
+ end
39
+ end
40
+ =end
41
+
@@ -0,0 +1,35 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Probably not.
5
+ # Developer notes:
6
+ # * Can we use a more general method instead (like humanize or methodize)? Does this really have a use distinct from all the other inflection methods out there?
7
+
8
+ class String
9
+ # Strips out most non-alphanumeric characters and leaves you with a lowercased, underscored string that can safely be used as a class_name
10
+ def to_underscored_label
11
+ self.
12
+ downcase.
13
+ gsub(/-+/, "_").gsub(/ +/, "_"). # spaces and -'s-> underscores
14
+ gsub(/[^a-z0-9_]/, ""). # keep only alphanumeric and _ characters
15
+ gsub(/_+$/, ""). # We don't want any _ characters at the end
16
+ gsub(/^_+/, "") # ... or the beginning
17
+ end
18
+ end
19
+
20
+ # _____ _
21
+ # |_ _|__ ___| |_
22
+ # | |/ _ \/ __| __|
23
+ # | | __/\__ \ |_
24
+ # |_|\___||___/\__|
25
+ #
26
+ =begin test
27
+ class TheTest < Test::Unit::TestCase
28
+ def test_to_underscored_label
29
+ assert_equal "discount_amount", "Discount Amount".to_underscored_label
30
+ assert_equal "more_spaces", "More SPACES".to_underscored_label
31
+ assert_equal "other_123_types_of_characters", "Other-123 Types? Of!!! Characters".to_underscored_label
32
+ assert_equal "weird_characters_on_the_end", "weird characters on the end *#*#**".to_underscored_label
33
+ end
34
+ end
35
+ =end
@@ -0,0 +1,64 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ require 'test/unit'
7
+ class Test::Unit::TestCase
8
+
9
+ # Asserts that the block that is passed in causes the value of the specified variable (+variable+) to change.
10
+ # +variable+ should be a Proc that, when evaluated, returns the current value of the variable.
11
+ #
12
+ # Options:
13
+ # * If the optional +:from+ option is supplied, it also asserts that it had that initial value.
14
+ # * If the optional +:to+ option is supplied, it also asserts that it changed _to_ that value.
15
+ #
16
+ # So instead of doing this:
17
+ # assert_equal 1, Model.count
18
+ # do_something_that_should_cause_count_to_increase
19
+ # assert_equal 2, Model.count
20
+ # we can do this:
21
+ # assert_changed(lambda {ErrorType.count}, :from => 1, :to => 2) do
22
+ # do_something_that_should_cause_count_to_increase
23
+ # end
24
+ # Or, if we don't care what it's changing _from_ as long as it increases in value _by_ 1, we can write this:
25
+ # assert_changed(c = lambda {ErrorType.count}, :to => c.call+1) do
26
+ # do_something_that_should_cause_count_to_increase
27
+ # end
28
+ # instead of this:
29
+ # before = Model.count
30
+ # do_something_that_should_cause_count_to_increase
31
+ # assert_equal before + 1, Model.count
32
+ #
33
+ def assert_changed(variable, options = {}, &block)
34
+ expected_from = options.delete(:from) || variable.call
35
+
36
+ assert_equal expected_from, variable.call
37
+
38
+ failure_message = build_message(failure_message, "The variable was expected to change from <?> to <?> but it didn't", variable.call, options.delete(:to) || "something else")
39
+ assert_block(failure_message) do
40
+ before = variable.call
41
+ yield
42
+ expected_to = options.delete(:to) || variable.call
43
+ before != variable.call and variable.call == expected_to
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ # _____ _
50
+ # |_ _|__ ___| |_
51
+ # | |/ _ \/ __| __|
52
+ # | | __/\__ \ |_
53
+ # |_|\___||___/\__|
54
+ #
55
+ =begin test
56
+ require 'test/unit'
57
+
58
+ class TheTest < Test::Unit::TestCase
59
+ def test_1
60
+ end
61
+ end
62
+ =end
63
+
64
+
@@ -0,0 +1,63 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ require 'test/unit'
7
+ class Test::Unit::TestCase
8
+
9
+ # Used when you want to make assertions *about* an assertion that you expect to be raised. (With the built-in assert_raise()
10
+ # you can only assert *that* a particular class of exception is raised, not any specifics about it.
11
+ #
12
+ # Before:
13
+ #
14
+ # assert_raises(ArgumentError) { SomeCommand.execute("foo '''") }
15
+ # begin
16
+ # SomeCommand.execute("foo -m '''")
17
+ # rescue Exception => _exception
18
+ # exception = _exception
19
+ # end
20
+ # assert_equal "Unmatched single quote: '", exception.message
21
+ #
22
+ # After:
23
+ #
24
+ # assert_exception(ArgumentError, lambda { |exception|
25
+ # assert_match /Unmatched single quote/, exception.message
26
+ # }) do
27
+ # SomeCommand.execute("foo -m 'stuff''")
28
+ # end
29
+ #
30
+ def assert_exception(expected_class, additional_expectations = nil, &block)
31
+ exception = nil
32
+ assert_raise(expected_class) do
33
+ begin
34
+ yield
35
+ rescue Exception => _exception
36
+ exception = _exception
37
+ raise
38
+ end
39
+ end
40
+ additional_expectations.call(exception) if additional_expectations
41
+ end
42
+ end
43
+
44
+ # _____ _
45
+ # |_ _|__ ___| |_
46
+ # | |/ _ \/ __| __|
47
+ # | | __/\__ \ |_
48
+ # |_|\___||___/\__|
49
+ #
50
+ =begin test
51
+ require 'test/unit'
52
+
53
+ class TheTest < Test::Unit::TestCase
54
+ def test_1
55
+ assert_exception(RuntimeError, lambda { |exception|
56
+ assert_match /est/, exception.message
57
+ }) do
58
+ raise "Test"
59
+ end
60
+ end
61
+ end
62
+ =end
63
+
@@ -0,0 +1,34 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: Yes
5
+
6
+ require 'test/unit'
7
+ class Test::Unit::TestCase
8
+ def assert_includes(container, expected_contents, failure_message = nil)
9
+ failure_message = build_message(failure_message, "Container <?> was expected to contain <?> but it didn't", container, expected_contents)
10
+ assert_block(failure_message) do
11
+ container.include?(expected_contents)
12
+ end
13
+ end
14
+ alias_method :assert_contains, :assert_includes
15
+
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_1
29
+ end
30
+ end
31
+ =end
32
+
33
+
34
+
@@ -0,0 +1,34 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: No
5
+
6
+ require 'test/unit'
7
+ class Test::Unit::TestCase
8
+ def assert_user_error(error_message)
9
+ assert_tag({
10
+ :attributes => { :id => "errorExplanation" },
11
+ :descendant => {
12
+ :content => error_message
13
+ }
14
+ })
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_1
29
+ end
30
+ end
31
+ =end
32
+
33
+
34
+
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + "/../kernel/require_all"
2
+ require_all File.dirname(__FILE__), :exclude_files => 'all.rb'
@@ -0,0 +1,29 @@
1
+ # Author:: Tyler Rick
2
+ # Copyright:: Copyright (c) 2007 QualitySmith, Inc.
3
+ # License:: Ruby License
4
+ # Submit to Facets?:: No!
5
+
6
+ class Time
7
+ # This should be moved elsewhere because it is subjective and depends on the context where it's used.
8
+ def datetime_for_report(line_break = false)
9
+ optional_line_break = (line_break ? "<br/>\n" : "")
10
+ strftime("%I:%M %p #{optional_line_break} %B %d, %Y") # Example: "June 18, 2006"
11
+ end
12
+ end
13
+
14
+ # _____ _
15
+ # |_ _|__ ___| |_
16
+ # | |/ _ \/ __| __|
17
+ # | | __/\__ \ |_
18
+ # |_|\___||___/\__|
19
+ #
20
+ =begin test
21
+ class TheTest < Test::Unit::TestCase
22
+
23
+ def test_date_for_report
24
+ assert_equal "01:49 PM June 18, 2006", Time.mktime(2006, 6, 18, 13, 49, 4).datetime_for_report()
25
+ assert_equal "01:49 PM <br/>\n June 18, 2006", Time.mktime(2006, 6, 18, 13, 49, 4).datetime_for_report(line_break = true)
26
+ end
27
+
28
+ end
29
+ =end
data/test/all.rb ADDED
@@ -0,0 +1,16 @@
1
+ #require File.dirname(__FILE__) + "/../lib/kernel/require_all.rb"
2
+
3
+ require "rubygems"
4
+ require "rake" # FileList
5
+ require 'exacto' # Test extractor
6
+
7
+ FileList[File.dirname(__FILE__) + "/../lib/" + "**/**/*.rb"].exclude(/all/).each do |filename|
8
+ puts "Running #{filename}"
9
+ begin
10
+ Exacto::RubyCommand.new([filename]).run
11
+ rescue SystemExit => exception # "Code block not found" -- we don't care -- keep going already!
12
+ end
13
+ #sh "exrb #{filename}"
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: qualitysmith_extensions
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.3
7
+ date: 2007-03-20 00:00:00 -07:00
8
+ summary: A collection of reusable Ruby methods developed by QualitySmith.
9
+ require_paths:
10
+ - lib
11
+ email: rubyforge.org@tylerrick.com
12
+ homepage: http://qualitysmithext.rubyforge.org/
13
+ rubyforge_project: qualitysmith_extensions
14
+ description: A collection of reusable Ruby methods developed by QualitySmith.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Tyler Rick and others
30
+ files:
31
+ - lib/qualitysmith_extensions/global_variable_set.rb
32
+ - lib/qualitysmith_extensions/simulate_input.rb
33
+ - lib/qualitysmith_extensions/collection_extensions_for_cgi.rb
34
+ - lib/qualitysmith_extensions/all.rb
35
+ - lib/qualitysmith_extensions/filter_output.rb
36
+ - lib/qualitysmith_extensions/month.rb
37
+ - lib/qualitysmith_extensions/test/assert_exception.rb
38
+ - lib/qualitysmith_extensions/test/assert_user_error.rb
39
+ - lib/qualitysmith_extensions/test/assert_changed.rb
40
+ - lib/qualitysmith_extensions/test/assert_includes.rb
41
+ - lib/qualitysmith_extensions/file_test/binary_file.rb
42
+ - lib/qualitysmith_extensions/kernel/require_all.rb
43
+ - lib/qualitysmith_extensions/kernel/die.rb
44
+ - lib/qualitysmith_extensions/kernel/require_once.rb
45
+ - lib/qualitysmith_extensions/kernel/all.rb
46
+ - lib/qualitysmith_extensions/kernel/backtrace.rb
47
+ - lib/qualitysmith_extensions/kernel/capture_output.rb
48
+ - lib/qualitysmith_extensions/object/singleton.rb
49
+ - lib/qualitysmith_extensions/file/exact_match_regexp.rb
50
+ - lib/qualitysmith_extensions/date/iso8601.rb
51
+ - lib/qualitysmith_extensions/date/deprecated.rb
52
+ - lib/qualitysmith_extensions/date/all.rb
53
+ - lib/qualitysmith_extensions/date/month_ranges.rb
54
+ - lib/qualitysmith_extensions/time/deprecated.rb
55
+ - lib/qualitysmith_extensions/time/all.rb
56
+ - lib/qualitysmith_extensions/console/command.rb
57
+ - lib/qualitysmith_extensions/console/command.facets.1.8.51.rb
58
+ - lib/qualitysmith_extensions/enumerable/enum.rb
59
+ - lib/qualitysmith_extensions/hash/to_query_string.rb
60
+ - lib/qualitysmith_extensions/hash/all.rb
61
+ - lib/qualitysmith_extensions/hash/to_date.rb
62
+ - lib/qualitysmith_extensions/array/expand_ranges.rb
63
+ - lib/qualitysmith_extensions/array/shell_escape.rb
64
+ - lib/qualitysmith_extensions/array/to_query_string.rb
65
+ - lib/qualitysmith_extensions/array/sequence.rb
66
+ - lib/qualitysmith_extensions/array/to_a_recursive.rb
67
+ - lib/qualitysmith_extensions/array/all.rb
68
+ - lib/qualitysmith_extensions/array/average.rb
69
+ - lib/qualitysmith_extensions/array/group_by.rb
70
+ - lib/qualitysmith_extensions/string/digits_only.rb
71
+ - lib/qualitysmith_extensions/string/shell_escape.rb
72
+ - lib/qualitysmith_extensions/string/md5.rb
73
+ - lib/qualitysmith_extensions/string/to_underscored_label.rb
74
+ - lib/qualitysmith_extensions/string/all.rb
75
+ - test/all.rb
76
+ - Readme
77
+ test_files:
78
+ - test/all.rb
79
+ rdoc_options:
80
+ - --title
81
+ - qualitysmith_extensions
82
+ - --main
83
+ - Readme
84
+ - --line-numbers
85
+ extra_rdoc_files:
86
+ - Readme
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ requirements: []
92
+
93
+ dependencies: []
94
+