motion-support 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +1 -1
  3. data/README.md +231 -2
  4. data/Rakefile +3 -3
  5. data/app/app_delegate.rb +0 -2
  6. data/examples/Inflector/.gitignore +16 -0
  7. data/examples/Inflector/Gemfile +5 -0
  8. data/examples/Inflector/Rakefile +13 -0
  9. data/examples/Inflector/app/app_delegate.rb +8 -0
  10. data/examples/Inflector/app/inflections.rb +5 -0
  11. data/examples/Inflector/app/inflector_view_controller.rb +120 -0
  12. data/examples/Inflector/app/words_view_controller.rb +101 -0
  13. data/examples/Inflector/resources/Default-568h@2x.png +0 -0
  14. data/examples/Inflector/spec/main_spec.rb +9 -0
  15. data/lib/motion-support/core_ext/array.rb +13 -0
  16. data/lib/motion-support/core_ext/class.rb +8 -0
  17. data/lib/motion-support/core_ext/hash.rb +16 -0
  18. data/lib/motion-support/core_ext/integer.rb +9 -0
  19. data/lib/motion-support/core_ext/module.rb +14 -0
  20. data/lib/motion-support/core_ext/numeric.rb +8 -0
  21. data/lib/motion-support/core_ext/object.rb +14 -0
  22. data/lib/motion-support/core_ext/range.rb +8 -0
  23. data/lib/motion-support/core_ext/string.rb +14 -0
  24. data/lib/motion-support/core_ext/time.rb +19 -0
  25. data/lib/motion-support/core_ext.rb +3 -0
  26. data/lib/motion-support/inflector.rb +12 -156
  27. data/lib/motion-support.rb +5 -5
  28. data/motion/_stdlib/cgi.rb +22 -0
  29. data/motion/_stdlib/date.rb +77 -0
  30. data/motion/_stdlib/time.rb +19 -0
  31. data/motion/core_ext/array/access.rb +28 -0
  32. data/motion/core_ext/array/conversions.rb +86 -0
  33. data/motion/core_ext/array/extract_options.rb +11 -0
  34. data/motion/core_ext/array/grouping.rb +99 -0
  35. data/motion/core_ext/array/prepend_and_append.rb +7 -0
  36. data/motion/core_ext/array/wrap.rb +45 -0
  37. data/{lib/motion-support → motion/core_ext}/array.rb +0 -4
  38. data/motion/core_ext/class/attribute.rb +119 -0
  39. data/motion/core_ext/class/attribute_accessors.rb +168 -0
  40. data/motion/core_ext/date/acts_like.rb +8 -0
  41. data/motion/core_ext/date/calculations.rb +117 -0
  42. data/motion/core_ext/date/conversions.rb +56 -0
  43. data/motion/core_ext/date_and_time/calculations.rb +232 -0
  44. data/motion/core_ext/enumerable.rb +90 -0
  45. data/motion/core_ext/hash/deep_merge.rb +27 -0
  46. data/motion/core_ext/hash/except.rb +15 -0
  47. data/motion/core_ext/hash/indifferent_access.rb +19 -0
  48. data/motion/core_ext/hash/keys.rb +138 -0
  49. data/motion/core_ext/hash/reverse_merge.rb +22 -0
  50. data/motion/core_ext/hash/slice.rb +40 -0
  51. data/motion/core_ext/integer/inflections.rb +27 -0
  52. data/motion/core_ext/integer/multiple.rb +10 -0
  53. data/motion/core_ext/integer/time.rb +41 -0
  54. data/{lib/motion-support → motion/core_ext}/metaclass.rb +0 -0
  55. data/motion/core_ext/module/aliasing.rb +69 -0
  56. data/motion/core_ext/module/anonymous.rb +19 -0
  57. data/motion/core_ext/module/attr_internal.rb +38 -0
  58. data/motion/core_ext/module/attribute_accessors.rb +64 -0
  59. data/motion/core_ext/module/delegation.rb +175 -0
  60. data/motion/core_ext/module/introspection.rb +60 -0
  61. data/motion/core_ext/module/reachable.rb +5 -0
  62. data/motion/core_ext/module/remove_method.rb +12 -0
  63. data/motion/core_ext/ns_dictionary.rb +11 -0
  64. data/motion/core_ext/numeric/bytes.rb +44 -0
  65. data/motion/core_ext/numeric/conversions.rb +7 -0
  66. data/motion/core_ext/numeric/time.rb +75 -0
  67. data/motion/core_ext/object/acts_like.rb +10 -0
  68. data/motion/core_ext/object/blank.rb +105 -0
  69. data/motion/core_ext/object/deep_dup.rb +44 -0
  70. data/motion/core_ext/object/duplicable.rb +83 -0
  71. data/motion/core_ext/object/instance_variables.rb +28 -0
  72. data/motion/core_ext/object/to_param.rb +58 -0
  73. data/motion/core_ext/object/to_query.rb +26 -0
  74. data/motion/core_ext/object/try.rb +78 -0
  75. data/motion/core_ext/range/include_range.rb +23 -0
  76. data/motion/core_ext/range/overlaps.rb +8 -0
  77. data/motion/core_ext/regexp.rb +5 -0
  78. data/motion/core_ext/string/access.rb +104 -0
  79. data/motion/core_ext/string/behavior.rb +6 -0
  80. data/motion/core_ext/string/exclude.rb +11 -0
  81. data/motion/core_ext/string/filters.rb +55 -0
  82. data/motion/core_ext/string/indent.rb +43 -0
  83. data/motion/core_ext/string/inflections.rb +195 -0
  84. data/motion/core_ext/string/starts_ends_with.rb +4 -0
  85. data/motion/core_ext/string/strip.rb +24 -0
  86. data/motion/core_ext/time/acts_like.rb +8 -0
  87. data/motion/core_ext/time/calculations.rb +215 -0
  88. data/motion/core_ext/time/conversions.rb +52 -0
  89. data/motion/duration.rb +104 -0
  90. data/motion/hash_with_indifferent_access.rb +251 -0
  91. data/motion/inflections.rb +67 -0
  92. data/motion/inflector/inflections.rb +203 -0
  93. data/motion/inflector/methods.rb +321 -0
  94. data/{lib/motion-support → motion}/logger.rb +0 -0
  95. data/{lib/motion-support → motion}/version.rb +1 -1
  96. data/motion-support.gemspec +2 -2
  97. data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
  98. data/spec/motion-support/_helpers/inflector_test_cases.rb +313 -0
  99. data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
  100. data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
  101. data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
  102. data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
  103. data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
  104. data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
  105. data/spec/motion-support/{array_spec.rb → core_ext/array_spec.rb} +0 -5
  106. data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
  107. data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
  108. data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
  109. data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
  110. data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
  111. data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
  112. data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
  113. data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
  114. data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
  115. data/spec/motion-support/core_ext/hash/key_spec.rb +230 -0
  116. data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
  117. data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
  118. data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
  119. data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
  120. data/spec/motion-support/{metaclass_spec.rb → core_ext/metaclass_spec.rb} +0 -0
  121. data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
  122. data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
  123. data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
  124. data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
  125. data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
  126. data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
  127. data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
  128. data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
  129. data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
  130. data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
  131. data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
  132. data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
  133. data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
  134. data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
  135. data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
  136. data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
  137. data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
  138. data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
  139. data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
  140. data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
  141. data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
  142. data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
  143. data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
  144. data/spec/motion-support/core_ext/string/filter_spec.rb +48 -0
  145. data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
  146. data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
  147. data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
  148. data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
  149. data/spec/motion-support/core_ext/string_spec.rb +88 -0
  150. data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
  151. data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
  152. data/spec/motion-support/core_ext/time/conversion_spec.rb +54 -0
  153. data/spec/motion-support/duration_spec.rb +107 -0
  154. data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
  155. data/spec/motion-support/inflector_spec.rb +474 -35
  156. data/spec/motion-support/ns_dictionary_spec.rb +29 -0
  157. metadata +212 -35
  158. data/lib/motion-support/cattr_accessor.rb +0 -19
  159. data/lib/motion-support/class_inheritable_accessor.rb +0 -23
  160. data/lib/motion-support/class_inheritable_array.rb +0 -29
  161. data/lib/motion-support/hash.rb +0 -31
  162. data/lib/motion-support/nilclass.rb +0 -5
  163. data/lib/motion-support/object.rb +0 -17
  164. data/lib/motion-support/string.rb +0 -71
  165. data/spec/motion-support/cattr_accessor_spec.rb +0 -49
  166. data/spec/motion-support/class_inheritable_accessor_spec.rb +0 -49
  167. data/spec/motion-support/class_inheritable_array_spec.rb +0 -61
  168. data/spec/motion-support/hash_spec.rb +0 -31
  169. data/spec/motion-support/nilclass_spec.rb +0 -5
  170. data/spec/motion-support/object_spec.rb +0 -43
  171. data/spec/motion-support/string_spec.rb +0 -145
@@ -1,31 +0,0 @@
1
- describe "hash" do
2
- describe "symbolize_keys" do
3
- it "should return copy with symbolized keys" do
4
- { 'foo' => 'bar', 'bla' => 'blub' }.symbolize_keys.should == { :foo => 'bar', :bla => 'blub' }
5
- end
6
-
7
- it "should not modify keys that can not be symbolized" do
8
- { :foo => 'bar', 1 => 'blub' }.symbolize_keys.should == { :foo => 'bar', 1 => 'blub' }
9
- end
10
-
11
- it "should symbolize keys in place" do
12
- hash = { 'foo' => 'bar', 'bla' => 'blub' }
13
- hash.symbolize_keys!
14
- hash.should == { :foo => 'bar', :bla => 'blub' }
15
- end
16
- end
17
-
18
- describe "empty?" do
19
- it "reports an empty hash using empty?" do
20
- {:key => 'value'}.empty?.should.not.be.true
21
- {}.empty?.should.be.true
22
- end
23
- end
24
-
25
- describe "except" do
26
- it "creates sub-hashes using except" do
27
- {:a => 'a', :b => 'b'}.except(:b)[:b].should.be.nil
28
- {:a => 'a', :b => 'b'}.except(:b).length.should == 1
29
- end
30
- end
31
- end
@@ -1,5 +0,0 @@
1
- describe 'nilclass' do
2
- it 'is blank if nil' do
3
- nil.should.be.blank
4
- end
5
- end
@@ -1,43 +0,0 @@
1
- describe "Object" do
2
- describe "blank?" do
3
- it "should be blank when responds to empty and is empty" do
4
- [].respond_to?(:empty?).should == true
5
- [].blank?.should == true
6
- end
7
-
8
- it "should not be blank when responds to empty and is not empty" do
9
- "Teststring".respond_to?(:empty?).should == true
10
- "Teststring".blank?.should == false
11
- end
12
- end
13
-
14
- describe "present?" do
15
- it "should be present if not blank" do
16
- "Hello".present?.should == true
17
- end
18
-
19
- it "should not be present if blank" do
20
- [].present?.should == false
21
- end
22
- end
23
-
24
- describe "common blank objects" do
25
- it "should be blank for empty array" do
26
- [].blank?.should == true
27
- end
28
-
29
- it "should be blank for empty string" do
30
- "".blank?.should == true
31
- end
32
-
33
- it "should be blank for empty hash" do
34
- {}.blank?.should == true
35
- end
36
- end
37
-
38
- describe "Nil" do
39
- it "should always be blank" do
40
- nil.blank?.should == true
41
- end
42
- end
43
- end
@@ -1,145 +0,0 @@
1
- describe "string" do
2
- describe "humanize" do
3
- it "handles dashes in text" do
4
- 'text-with-dashes'.humanize.should == 'text with dashes'
5
- end
6
-
7
- it "doesn't add junk at end if trailing character is a dash" do
8
- 'text-with-trailing-dash-'.humanize.should == 'text with trailing dash'
9
- end
10
-
11
- it "doesn't prepend junk if starting character is a dash" do
12
- '-text-with-leading-dash'.humanize.should == 'text with leading dash'
13
- end
14
-
15
- it "condenses multiple dashes to one space" do
16
- 'text--with-multiple--dashes'.humanize.should == 'text with multiple dashes'
17
- end
18
- end
19
-
20
- describe "titleize" do
21
- it "translates text to title case" do
22
- 'text-to-translate'.titleize.should == 'Text To Translate'
23
- end
24
- end
25
-
26
- describe "dasherize" do
27
- it 'handles strings with spaces' do
28
- 'a normal string'.dasherize.should == 'a-normal-string'
29
- end
30
-
31
- it 'handles CamelCase strings' do
32
- 'MyClass'.dasherize.should == 'my-class'
33
- end
34
-
35
- it 'handles snake_case strings' do
36
- 'my_class'.dasherize.should == 'my-class'
37
- end
38
- end
39
-
40
- describe "empty?" do
41
- it "an empty string is detected by empty?" do
42
- ''.empty?.should.be.true
43
- end
44
-
45
- it "a non-empty string is false according to empty?" do
46
- 'something'.empty?.should.not.be.true
47
- end
48
-
49
- it "a blank string is false according to empty?" do
50
- ' '.empty?.should.not.be.true
51
- end
52
- end
53
-
54
- describe "blank?" do
55
- it "an empty string should be blank" do
56
- ''.should.be.blank
57
- end
58
-
59
- it "a string containing only whitespace should be blank" do
60
- ' '.should.be.blank
61
- end
62
-
63
- it "a string with content is not blank" do
64
- 'abc'.should.not.be.blank
65
- end
66
- end
67
-
68
- describe "camelize" do
69
- it 'a dashed string should convert to CamelCase' do
70
- 'my-class'.camelize.should == 'MyClass'
71
- end
72
-
73
- it 'a snake_case string should convert to CamelCase' do
74
- 'my_class'.camelize.should == 'MyClass'
75
- end
76
-
77
- it 'a conversion can be specified with lowercase first letter' do
78
- 'my_cocoa_var'.camelize(false).should == 'myCocoaVar'
79
- end
80
- end
81
-
82
- describe "underscore" do
83
- it 'a camel-cased string can be converted to snake-case' do
84
- 'MyClass'.underscore.should == 'my_class'
85
- end
86
-
87
- it 'a module scoped class is properly underscored' do
88
- 'MyModule::MyClass'.underscore.should == 'my_module/my_class'
89
- end
90
-
91
- it 'properly underscores lowercase initial letter' do
92
- 'aCocoaVariable'.underscore.should == 'a_cocoa_variable'
93
- end
94
- end
95
-
96
- describe "pluralize" do
97
- it "should return self if string is already plural" do
98
- "houses".pluralize.should == "houses"
99
- "trains".pluralize.should == "trains"
100
- end
101
-
102
- it "should return plural version for singular string" do
103
- "house".pluralize.should == "houses"
104
- "train".pluralize.should == "trains"
105
- end
106
- end
107
-
108
- describe "singularize" do
109
- it "should return self if string is already singular" do
110
- "house".singularize.should == "house"
111
- "train".singularize.should == "train"
112
- end
113
-
114
- it "should return singular version for plural string" do
115
- "houses".singularize.should == "house"
116
- "trains".singularize.should == "train"
117
- end
118
- end
119
-
120
- describe "classify" do
121
- it "should return classified version of underscored singular string" do
122
- "search_controller".classify.should == "SearchController"
123
- end
124
-
125
- it "should return classified version of underscored plural string" do
126
- "search_controllers".classify.should == "SearchController"
127
- end
128
-
129
- it "should return classified version of camelized singular string" do
130
- "SearchController".classify.should == "SearchController"
131
- end
132
-
133
- it "should return classified version of camelized plural string" do
134
- "SearchControllers".classify.should == "SearchController"
135
- end
136
- end
137
-
138
- describe "constantize" do
139
- class SearchController; end
140
-
141
- it "makes a constant class name from a suitable string" do
142
- "SearchControllers".classify.constantize.should == SearchController
143
- end
144
- end
145
- end