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.
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/README.md +231 -2
- data/Rakefile +3 -3
- data/app/app_delegate.rb +0 -2
- data/examples/Inflector/.gitignore +16 -0
- data/examples/Inflector/Gemfile +5 -0
- data/examples/Inflector/Rakefile +13 -0
- data/examples/Inflector/app/app_delegate.rb +8 -0
- data/examples/Inflector/app/inflections.rb +5 -0
- data/examples/Inflector/app/inflector_view_controller.rb +120 -0
- data/examples/Inflector/app/words_view_controller.rb +101 -0
- data/examples/Inflector/resources/Default-568h@2x.png +0 -0
- data/examples/Inflector/spec/main_spec.rb +9 -0
- data/lib/motion-support/core_ext/array.rb +13 -0
- data/lib/motion-support/core_ext/class.rb +8 -0
- data/lib/motion-support/core_ext/hash.rb +16 -0
- data/lib/motion-support/core_ext/integer.rb +9 -0
- data/lib/motion-support/core_ext/module.rb +14 -0
- data/lib/motion-support/core_ext/numeric.rb +8 -0
- data/lib/motion-support/core_ext/object.rb +14 -0
- data/lib/motion-support/core_ext/range.rb +8 -0
- data/lib/motion-support/core_ext/string.rb +14 -0
- data/lib/motion-support/core_ext/time.rb +19 -0
- data/lib/motion-support/core_ext.rb +3 -0
- data/lib/motion-support/inflector.rb +12 -156
- data/lib/motion-support.rb +5 -5
- data/motion/_stdlib/cgi.rb +22 -0
- data/motion/_stdlib/date.rb +77 -0
- data/motion/_stdlib/time.rb +19 -0
- data/motion/core_ext/array/access.rb +28 -0
- data/motion/core_ext/array/conversions.rb +86 -0
- data/motion/core_ext/array/extract_options.rb +11 -0
- data/motion/core_ext/array/grouping.rb +99 -0
- data/motion/core_ext/array/prepend_and_append.rb +7 -0
- data/motion/core_ext/array/wrap.rb +45 -0
- data/{lib/motion-support → motion/core_ext}/array.rb +0 -4
- data/motion/core_ext/class/attribute.rb +119 -0
- data/motion/core_ext/class/attribute_accessors.rb +168 -0
- data/motion/core_ext/date/acts_like.rb +8 -0
- data/motion/core_ext/date/calculations.rb +117 -0
- data/motion/core_ext/date/conversions.rb +56 -0
- data/motion/core_ext/date_and_time/calculations.rb +232 -0
- data/motion/core_ext/enumerable.rb +90 -0
- data/motion/core_ext/hash/deep_merge.rb +27 -0
- data/motion/core_ext/hash/except.rb +15 -0
- data/motion/core_ext/hash/indifferent_access.rb +19 -0
- data/motion/core_ext/hash/keys.rb +138 -0
- data/motion/core_ext/hash/reverse_merge.rb +22 -0
- data/motion/core_ext/hash/slice.rb +40 -0
- data/motion/core_ext/integer/inflections.rb +27 -0
- data/motion/core_ext/integer/multiple.rb +10 -0
- data/motion/core_ext/integer/time.rb +41 -0
- data/{lib/motion-support → motion/core_ext}/metaclass.rb +0 -0
- data/motion/core_ext/module/aliasing.rb +69 -0
- data/motion/core_ext/module/anonymous.rb +19 -0
- data/motion/core_ext/module/attr_internal.rb +38 -0
- data/motion/core_ext/module/attribute_accessors.rb +64 -0
- data/motion/core_ext/module/delegation.rb +175 -0
- data/motion/core_ext/module/introspection.rb +60 -0
- data/motion/core_ext/module/reachable.rb +5 -0
- data/motion/core_ext/module/remove_method.rb +12 -0
- data/motion/core_ext/ns_dictionary.rb +11 -0
- data/motion/core_ext/numeric/bytes.rb +44 -0
- data/motion/core_ext/numeric/conversions.rb +7 -0
- data/motion/core_ext/numeric/time.rb +75 -0
- data/motion/core_ext/object/acts_like.rb +10 -0
- data/motion/core_ext/object/blank.rb +105 -0
- data/motion/core_ext/object/deep_dup.rb +44 -0
- data/motion/core_ext/object/duplicable.rb +83 -0
- data/motion/core_ext/object/instance_variables.rb +28 -0
- data/motion/core_ext/object/to_param.rb +58 -0
- data/motion/core_ext/object/to_query.rb +26 -0
- data/motion/core_ext/object/try.rb +78 -0
- data/motion/core_ext/range/include_range.rb +23 -0
- data/motion/core_ext/range/overlaps.rb +8 -0
- data/motion/core_ext/regexp.rb +5 -0
- data/motion/core_ext/string/access.rb +104 -0
- data/motion/core_ext/string/behavior.rb +6 -0
- data/motion/core_ext/string/exclude.rb +11 -0
- data/motion/core_ext/string/filters.rb +55 -0
- data/motion/core_ext/string/indent.rb +43 -0
- data/motion/core_ext/string/inflections.rb +195 -0
- data/motion/core_ext/string/starts_ends_with.rb +4 -0
- data/motion/core_ext/string/strip.rb +24 -0
- data/motion/core_ext/time/acts_like.rb +8 -0
- data/motion/core_ext/time/calculations.rb +215 -0
- data/motion/core_ext/time/conversions.rb +52 -0
- data/motion/duration.rb +104 -0
- data/motion/hash_with_indifferent_access.rb +251 -0
- data/motion/inflections.rb +67 -0
- data/motion/inflector/inflections.rb +203 -0
- data/motion/inflector/methods.rb +321 -0
- data/{lib/motion-support → motion}/logger.rb +0 -0
- data/{lib/motion-support → motion}/version.rb +1 -1
- data/motion-support.gemspec +2 -2
- data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
- data/spec/motion-support/_helpers/inflector_test_cases.rb +313 -0
- data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
- data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
- data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
- data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
- data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
- data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
- data/spec/motion-support/{array_spec.rb → core_ext/array_spec.rb} +0 -5
- data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
- data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
- data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
- data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
- data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
- data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
- data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
- data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
- data/spec/motion-support/core_ext/hash/key_spec.rb +230 -0
- data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
- data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
- data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
- data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
- data/spec/motion-support/{metaclass_spec.rb → core_ext/metaclass_spec.rb} +0 -0
- data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
- data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
- data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
- data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
- data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
- data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
- data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
- data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
- data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
- data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
- data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
- data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
- data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
- data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
- data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
- data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
- data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
- data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
- data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
- data/spec/motion-support/core_ext/string/filter_spec.rb +48 -0
- data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
- data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
- data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
- data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
- data/spec/motion-support/core_ext/string_spec.rb +88 -0
- data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
- data/spec/motion-support/core_ext/time/conversion_spec.rb +54 -0
- data/spec/motion-support/duration_spec.rb +107 -0
- data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
- data/spec/motion-support/inflector_spec.rb +474 -35
- data/spec/motion-support/ns_dictionary_spec.rb +29 -0
- metadata +212 -35
- data/lib/motion-support/cattr_accessor.rb +0 -19
- data/lib/motion-support/class_inheritable_accessor.rb +0 -23
- data/lib/motion-support/class_inheritable_array.rb +0 -29
- data/lib/motion-support/hash.rb +0 -31
- data/lib/motion-support/nilclass.rb +0 -5
- data/lib/motion-support/object.rb +0 -17
- data/lib/motion-support/string.rb +0 -71
- data/spec/motion-support/cattr_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_array_spec.rb +0 -61
- data/spec/motion-support/hash_spec.rb +0 -31
- data/spec/motion-support/nilclass_spec.rb +0 -5
- data/spec/motion-support/object_spec.rb +0 -43
- 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,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
|