gorillib 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/LICENSE.textile +81 -0
  4. data/README.textile +153 -0
  5. data/Rakefile +26 -0
  6. data/VERSION +1 -0
  7. data/fiddle/hubahuba.rb +62 -0
  8. data/gorillib.gemspec +142 -0
  9. data/lib/gorillib/array/compact_blank.rb +17 -0
  10. data/lib/gorillib/array/extract_options.rb +29 -0
  11. data/lib/gorillib/base.rb +7 -0
  12. data/lib/gorillib/datetime/flat.rb +29 -0
  13. data/lib/gorillib/datetime/parse.rb +21 -0
  14. data/lib/gorillib/enumerable/sum.rb +38 -0
  15. data/lib/gorillib/hash/compact.rb +31 -0
  16. data/lib/gorillib/hash/deep_merge.rb +16 -0
  17. data/lib/gorillib/hash/keys.rb +42 -0
  18. data/lib/gorillib/hash/reverse_merge.rb +26 -0
  19. data/lib/gorillib/hash/slice.rb +53 -0
  20. data/lib/gorillib/hash/zip.rb +10 -0
  21. data/lib/gorillib/logger/log.rb +14 -0
  22. data/lib/gorillib/metaprogramming/aliasing.rb +43 -0
  23. data/lib/gorillib/metaprogramming/cattr_accessor.rb +79 -0
  24. data/lib/gorillib/metaprogramming/class_attribute.rb +90 -0
  25. data/lib/gorillib/metaprogramming/delegation.rb +146 -0
  26. data/lib/gorillib/metaprogramming/mattr_accessor.rb +61 -0
  27. data/lib/gorillib/metaprogramming/remove_method.rb +11 -0
  28. data/lib/gorillib/metaprogramming/singleton_class.rb +8 -0
  29. data/lib/gorillib/object/blank.rb +89 -0
  30. data/lib/gorillib/some.rb +12 -0
  31. data/lib/gorillib/string/constantize.rb +21 -0
  32. data/lib/gorillib/string/human.rb +52 -0
  33. data/lib/gorillib/string/inflections.rb +78 -0
  34. data/lib/gorillib/string/truncate.rb +33 -0
  35. data/lib/gorillib.rb +1 -0
  36. data/spec/blank_spec.rb +86 -0
  37. data/spec/gorillib_spec.rb +7 -0
  38. data/spec/rcov.opts +6 -0
  39. data/spec/spec.opts +4 -0
  40. data/spec/spec_helper.rb +12 -0
  41. data/spec/spec_tasks.rake +15 -0
  42. data/test/abstract_unit.rb +25 -0
  43. data/test/array/compact_blank_test.rb +33 -0
  44. data/test/array/extract_options_test.rb +39 -0
  45. data/test/datetime/flat_test.rb +0 -0
  46. data/test/datetime/parse_test.rb +0 -0
  47. data/test/enumerable/sum_test.rb +50 -0
  48. data/test/hash/compact_test.rb +38 -0
  49. data/test/hash/deep_merge_test.rb +30 -0
  50. data/test/hash/keys_test.rb +110 -0
  51. data/test/hash/reverse_merge_test.rb +20 -0
  52. data/test/hash/slice_test.rb +47 -0
  53. data/test/hash/zip_test.rb +0 -0
  54. data/test/logger/log_test.rb +0 -0
  55. data/test/metaprogramming/aliasing_test.rb +188 -0
  56. data/test/metaprogramming/cattr_accessor_test.rb +38 -0
  57. data/test/metaprogramming/class_attribute_test.rb +73 -0
  58. data/test/metaprogramming/delegation_test.rb +166 -0
  59. data/test/metaprogramming/mattr_accessor_test.rb +40 -0
  60. data/test/metaprogramming/singleton_class_test.rb +9 -0
  61. data/test/object/blank_test.rb +22 -0
  62. data/test/string/constantize_test.rb +30 -0
  63. data/test/string/human_test.rb +65 -0
  64. data/test/string/inflections_test.rb +57 -0
  65. data/test/string/inflector_test_cases.rb +50 -0
  66. data/test/string/truncate_test.rb +37 -0
  67. metadata +199 -0
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__)+'/../abstract_unit'
2
+ require 'gorillib/object/blank'
3
+
4
+ class BlankTest < Test::Unit::TestCase
5
+ BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ]
6
+ NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ]
7
+
8
+ def test_blank
9
+ BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" }
10
+ NOT.each { |v| assert !v.blank?, "#{v.inspect} should not be blank" }
11
+ end
12
+
13
+ def test_present
14
+ BLANK.each { |v| assert !v.present?, "#{v.inspect} should not be present" }
15
+ NOT.each { |v| assert v.present?, "#{v.inspect} should be present" }
16
+ end
17
+
18
+ def test_presence
19
+ BLANK.each { |v| assert_equal nil, v.presence, "#{v.inspect}.presence should return nil" }
20
+ NOT.each { |v| assert_equal v, v.presence, "#{v.inspect}.presence should return self" }
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__)+'/../abstract_unit'
2
+ require File.dirname(__FILE__)+'/inflector_test_cases'
3
+ require 'gorillib/string/constantize'
4
+
5
+ module Ace
6
+ module Base
7
+ class Case
8
+ end
9
+ end
10
+ end
11
+
12
+
13
+ class InflectorTest < Test::Unit::TestCase
14
+ include InflectorTestCases
15
+
16
+ def test_constantize
17
+ assert_nothing_raised{ assert_equal Ace::Base::Case, "Ace::Base::Case".constantize }
18
+ assert_nothing_raised{ assert_equal Ace::Base::Case, "::Ace::Base::Case".constantize }
19
+ assert_nothing_raised{ assert_equal InflectorTest, "InflectorTest".constantize }
20
+ assert_nothing_raised{ assert_equal InflectorTest, "::InflectorTest".constantize }
21
+ assert_raise(NameError){ "UnknownClass" .constantize }
22
+ assert_raise(NameError){ "An invalid string".constantize }
23
+ assert_raise(NameError){ "InvalidClass\n" .constantize }
24
+ end
25
+
26
+ def test_constantize_does_lexical_lookup
27
+ assert_raise(NameError) { "Ace::Base::InflectorTest".constantize }
28
+ end
29
+
30
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__)+'/../abstract_unit'
2
+ require File.dirname(__FILE__)+'/inflector_test_cases'
3
+ require 'gorillib/string/human'
4
+
5
+ class InflectorTest < Test::Unit::TestCase
6
+ include InflectorTestCases
7
+
8
+ def test_titleize
9
+ MixtureToTitleCase.each do |before, titleized|
10
+ assert_equal(titleized, before.titleize)
11
+ end
12
+ end
13
+
14
+ MixtureToTitleCase.each do |before, titleized|
15
+ define_method "test_titleize_#{before}" do
16
+ assert_equal(titleized, before.titleize )
17
+ end
18
+ end
19
+
20
+ def test_humanize
21
+ UnderscoreToHuman.each do |underscored, human|
22
+ assert_equal(human, underscored.humanize )
23
+ end
24
+ end
25
+ end
26
+
27
+ class ArrayExtToSentenceTests < Test::Unit::TestCase
28
+ def test_plain_array_to_sentence
29
+ assert_equal "", [].to_sentence
30
+ assert_equal "one", ['one'].to_sentence
31
+ assert_equal "one and two", ['one', 'two'].to_sentence
32
+ assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence
33
+ end
34
+
35
+ def test_to_sentence_with_words_connector
36
+ assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' ')
37
+ assert_equal "one & two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' & ')
38
+ assert_equal "onetwo, and three", ['one', 'two', 'three'].to_sentence(:words_connector => nil)
39
+ end
40
+
41
+ def test_to_sentence_with_last_word_connector
42
+ assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ', and also ')
43
+ assert_equal "one, twothree", ['one', 'two', 'three'].to_sentence(:last_word_connector => nil)
44
+ assert_equal "one, two three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' ')
45
+ assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' and ')
46
+ end
47
+
48
+ def test_two_elements
49
+ assert_equal "one and two", ['one', 'two'].to_sentence
50
+ assert_equal "one two", ['one', 'two'].to_sentence(:two_words_connector => ' ')
51
+ end
52
+
53
+ def test_one_element
54
+ assert_equal "one", ['one'].to_sentence
55
+ end
56
+
57
+ def test_one_element_not_same_object
58
+ elements = ["one"]
59
+ assert_not_equal elements[0].object_id, elements.to_sentence.object_id
60
+ end
61
+
62
+ def test_one_non_string_element
63
+ assert_equal '1', [1].to_sentence
64
+ end
65
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__)+'/../abstract_unit'
2
+ require 'gorillib/string/inflections'
3
+ require File.dirname(__FILE__)+'/inflector_test_cases'
4
+
5
+ class InflectorTest < Test::Unit::TestCase
6
+ include InflectorTestCases
7
+
8
+ def test_camelize
9
+ CamelToUnderscore.each do |cameled, underscored|
10
+ assert_equal(cameled, underscored.camelize)
11
+ end
12
+ end
13
+
14
+ def test_camelize_with_lower_downcases_the_first_letter
15
+ assert_equal('capital', 'Capital'.camelize(:lower))
16
+ end
17
+
18
+ def test_snakeize
19
+ UnderscoreToLowerCamel.each do |underscored, snaked|
20
+ assert_equal(snaked, underscored.snakeize)
21
+ end
22
+ end
23
+
24
+ def test_underscore_to_lower_camel
25
+ UnderscoreToLowerCamel.each do |underscored, lower_cameled|
26
+ assert_equal(lower_cameled, underscored.camelize(:lower))
27
+ end
28
+ end
29
+
30
+ def test_underscore
31
+ CamelToUnderscore.each do |cameled, underscored|
32
+ assert_equal(underscored, cameled.underscore)
33
+ end
34
+ CamelToUnderscoreWithoutReverse.each do |cameled, underscored|
35
+ assert_equal(underscored, cameled.underscore)
36
+ end
37
+ assert_equal "html_tidy", "HTMLTidy".underscore
38
+ assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore
39
+ end
40
+
41
+ def test_camelize_with_module
42
+ CamelWithModuleToUnderscoreWithSlash.each do |cameled, underscored|
43
+ assert_equal(cameled, underscored.camelize)
44
+ end
45
+ end
46
+
47
+ def test_underscore_with_slashes
48
+ CamelWithModuleToUnderscoreWithSlash.each do |cameled, underscored|
49
+ assert_equal(underscored, cameled.underscore)
50
+ end
51
+ end
52
+
53
+ def test_demodulize
54
+ assert_equal "Account", "MyApplication::Billing::Account".demodulize
55
+ end
56
+
57
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ module InflectorTestCases
4
+
5
+ CamelToUnderscore = {
6
+ "Product" => "product",
7
+ "SpecialGuest" => "special_guest",
8
+ "ApplicationController" => "application_controller",
9
+ "Area51Controller" => "area51_controller"
10
+ }
11
+
12
+ UnderscoreToLowerCamel = {
13
+ "product" => "product",
14
+ "special_guest" => "specialGuest",
15
+ "application_controller" => "applicationController",
16
+ "area51_controller" => "area51Controller"
17
+ }
18
+
19
+ CamelToUnderscoreWithoutReverse = {
20
+ "HTMLTidy" => "html_tidy",
21
+ "HTMLTidyGenerator" => "html_tidy_generator",
22
+ "FreeBSD" => "free_bsd",
23
+ "HTML" => "html",
24
+ }
25
+
26
+ CamelWithModuleToUnderscoreWithSlash = {
27
+ "Admin::Product" => "admin/product",
28
+ "Users::Commission::Department" => "users/commission/department",
29
+ "UsersSection::CommissionDepartment" => "users_section/commission_department",
30
+ }
31
+
32
+ UnderscoreToHuman = {
33
+ "employee_salary" => "Employee salary",
34
+ "employee_id" => "Employee",
35
+ "underground" => "Underground"
36
+ }
37
+
38
+ MixtureToTitleCase = {
39
+ 'active_record' => 'Active Record',
40
+ 'ActiveRecord' => 'Active Record',
41
+ 'action web service' => 'Action Web Service',
42
+ 'Action Web Service' => 'Action Web Service',
43
+ 'Action web service' => 'Action Web Service',
44
+ 'actionwebservice' => 'Actionwebservice',
45
+ 'Actionwebservice' => 'Actionwebservice',
46
+ "david's code" => "David's Code",
47
+ "David's code" => "David's Code",
48
+ "david's Code" => "David's Code"
49
+ }
50
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__)+'/../abstract_unit'
3
+ require File.dirname(__FILE__)+'/inflector_test_cases'
4
+ require 'gorillib/string/truncate'
5
+
6
+ class StringInflectionsTest < Test::Unit::TestCase
7
+ include InflectorTestCases
8
+
9
+ def test_truncate
10
+ assert_equal "Hello World!", "Hello World!".truncate(12)
11
+ assert_equal "Hello Wor...", "Hello World!!".truncate(12)
12
+ end
13
+
14
+ def test_truncate_with_omission_and_seperator
15
+ assert_equal "Hello[...]", "Hello World!".truncate(10, :omission => "[...]")
16
+ assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => ' ')
17
+ assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => ' ')
18
+ assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ')
19
+ end
20
+
21
+ if RUBY_VERSION < '1.9.0'
22
+ def test_truncate_multibyte
23
+ with_kcode 'none' do
24
+ assert_equal "\354\225\210\353\205\225\355...", "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224".truncate(10)
25
+ end
26
+ with_kcode 'u' do
27
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
28
+ "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".truncate(10)
29
+ end
30
+ end
31
+ else
32
+ def test_truncate_multibyte
33
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
34
+ "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8').truncate(10)
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gorillib
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Infochimps
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-02 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: yard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 6
31
+ - 0
32
+ version: 0.6.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 5
46
+ - 2
47
+ version: 1.5.2
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rcov
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: "Gorillib: infochimps lightweight subset of ruby convenience methods"
64
+ email: coders@infochimps.org
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - LICENSE.textile
71
+ - README.textile
72
+ files:
73
+ - .document
74
+ - .rspec
75
+ - LICENSE.textile
76
+ - README.textile
77
+ - Rakefile
78
+ - VERSION
79
+ - fiddle/hubahuba.rb
80
+ - gorillib.gemspec
81
+ - lib/gorillib.rb
82
+ - lib/gorillib/array/compact_blank.rb
83
+ - lib/gorillib/array/extract_options.rb
84
+ - lib/gorillib/base.rb
85
+ - lib/gorillib/datetime/flat.rb
86
+ - lib/gorillib/datetime/parse.rb
87
+ - lib/gorillib/enumerable/sum.rb
88
+ - lib/gorillib/hash/compact.rb
89
+ - lib/gorillib/hash/deep_merge.rb
90
+ - lib/gorillib/hash/keys.rb
91
+ - lib/gorillib/hash/reverse_merge.rb
92
+ - lib/gorillib/hash/slice.rb
93
+ - lib/gorillib/hash/zip.rb
94
+ - lib/gorillib/logger/log.rb
95
+ - lib/gorillib/metaprogramming/aliasing.rb
96
+ - lib/gorillib/metaprogramming/cattr_accessor.rb
97
+ - lib/gorillib/metaprogramming/class_attribute.rb
98
+ - lib/gorillib/metaprogramming/delegation.rb
99
+ - lib/gorillib/metaprogramming/mattr_accessor.rb
100
+ - lib/gorillib/metaprogramming/remove_method.rb
101
+ - lib/gorillib/metaprogramming/singleton_class.rb
102
+ - lib/gorillib/object/blank.rb
103
+ - lib/gorillib/some.rb
104
+ - lib/gorillib/string/constantize.rb
105
+ - lib/gorillib/string/human.rb
106
+ - lib/gorillib/string/inflections.rb
107
+ - lib/gorillib/string/truncate.rb
108
+ - spec/blank_spec.rb
109
+ - spec/gorillib_spec.rb
110
+ - spec/rcov.opts
111
+ - spec/spec.opts
112
+ - spec/spec_helper.rb
113
+ - spec/spec_tasks.rake
114
+ - test/abstract_unit.rb
115
+ - test/array/compact_blank_test.rb
116
+ - test/array/extract_options_test.rb
117
+ - test/datetime/flat_test.rb
118
+ - test/datetime/parse_test.rb
119
+ - test/enumerable/sum_test.rb
120
+ - test/hash/compact_test.rb
121
+ - test/hash/deep_merge_test.rb
122
+ - test/hash/keys_test.rb
123
+ - test/hash/reverse_merge_test.rb
124
+ - test/hash/slice_test.rb
125
+ - test/hash/zip_test.rb
126
+ - test/logger/log_test.rb
127
+ - test/metaprogramming/aliasing_test.rb
128
+ - test/metaprogramming/cattr_accessor_test.rb
129
+ - test/metaprogramming/class_attribute_test.rb
130
+ - test/metaprogramming/delegation_test.rb
131
+ - test/metaprogramming/mattr_accessor_test.rb
132
+ - test/metaprogramming/singleton_class_test.rb
133
+ - test/object/blank_test.rb
134
+ - test/string/constantize_test.rb
135
+ - test/string/human_test.rb
136
+ - test/string/inflections_test.rb
137
+ - test/string/inflector_test_cases.rb
138
+ - test/string/truncate_test.rb
139
+ has_rdoc: true
140
+ homepage: http://infochimps.com/labs
141
+ licenses:
142
+ - MIT
143
+ post_install_message:
144
+ rdoc_options: []
145
+
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project:
167
+ rubygems_version: 1.3.7
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: include only what you need. No dependencies, no creep
171
+ test_files:
172
+ - spec/blank_spec.rb
173
+ - spec/gorillib_spec.rb
174
+ - spec/spec_helper.rb
175
+ - test/abstract_unit.rb
176
+ - test/array/compact_blank_test.rb
177
+ - test/array/extract_options_test.rb
178
+ - test/datetime/flat_test.rb
179
+ - test/datetime/parse_test.rb
180
+ - test/enumerable/sum_test.rb
181
+ - test/hash/compact_test.rb
182
+ - test/hash/deep_merge_test.rb
183
+ - test/hash/keys_test.rb
184
+ - test/hash/reverse_merge_test.rb
185
+ - test/hash/slice_test.rb
186
+ - test/hash/zip_test.rb
187
+ - test/logger/log_test.rb
188
+ - test/metaprogramming/aliasing_test.rb
189
+ - test/metaprogramming/cattr_accessor_test.rb
190
+ - test/metaprogramming/class_attribute_test.rb
191
+ - test/metaprogramming/delegation_test.rb
192
+ - test/metaprogramming/mattr_accessor_test.rb
193
+ - test/metaprogramming/singleton_class_test.rb
194
+ - test/object/blank_test.rb
195
+ - test/string/constantize_test.rb
196
+ - test/string/human_test.rb
197
+ - test/string/inflections_test.rb
198
+ - test/string/inflector_test_cases.rb
199
+ - test/string/truncate_test.rb