gorillib 0.1.11 → 0.4.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -2
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.textile → CHANGELOG.md} +35 -9
  5. data/Gemfile +21 -14
  6. data/Guardfile +19 -0
  7. data/{LICENSE.textile → LICENSE.md} +43 -29
  8. data/README.md +47 -52
  9. data/Rakefile +31 -30
  10. data/TODO.md +32 -0
  11. data/VERSION +1 -1
  12. data/examples/builder/ironfan.rb +133 -0
  13. data/examples/model/simple.rb +17 -0
  14. data/gorillib.gemspec +106 -86
  15. data/lib/alt/kernel/call_stack.rb +56 -0
  16. data/lib/gorillib/array/wrap.rb +53 -0
  17. data/lib/gorillib/base.rb +3 -3
  18. data/lib/gorillib/builder/field.rb +5 -0
  19. data/lib/gorillib/builder.rb +260 -0
  20. data/lib/gorillib/collection/has_collection.rb +31 -0
  21. data/lib/gorillib/collection.rb +129 -0
  22. data/lib/gorillib/configurable.rb +28 -0
  23. data/lib/gorillib/datetime/{flat.rb → to_flat.rb} +0 -0
  24. data/lib/gorillib/exception/confidence.rb +17 -0
  25. data/lib/gorillib/exception/raisers.rb +78 -0
  26. data/lib/gorillib/hash/mash.rb +202 -0
  27. data/lib/gorillib/hashlike/slice.rb +53 -19
  28. data/lib/gorillib/hashlike.rb +5 -3
  29. data/lib/gorillib/io/system_helpers.rb +30 -0
  30. data/lib/gorillib/logger/log.rb +18 -0
  31. data/lib/gorillib/metaprogramming/concern.rb +124 -0
  32. data/lib/gorillib/model/active_model_conversion.rb +68 -0
  33. data/lib/gorillib/model/active_model_naming.rb +87 -0
  34. data/lib/gorillib/model/active_model_shim.rb +33 -0
  35. data/lib/gorillib/model/base.rb +341 -0
  36. data/lib/gorillib/model/defaults.rb +71 -0
  37. data/lib/gorillib/model/errors.rb +14 -0
  38. data/lib/gorillib/model/factories.rb +372 -0
  39. data/lib/gorillib/model/field.rb +146 -0
  40. data/lib/gorillib/model/named_schema.rb +53 -0
  41. data/lib/gorillib/{struct/hashlike_iteration.rb → model/overlay.rb} +0 -0
  42. data/lib/gorillib/model/record_schema.rb +9 -0
  43. data/lib/gorillib/model/serialization.rb +23 -0
  44. data/lib/gorillib/model/validate.rb +22 -0
  45. data/lib/gorillib/model.rb +23 -0
  46. data/lib/gorillib/pathname.rb +78 -0
  47. data/lib/gorillib/{serialization.rb → serialization/to_wire.rb} +0 -0
  48. data/lib/gorillib/some.rb +11 -9
  49. data/lib/gorillib/string/constantize.rb +21 -14
  50. data/lib/gorillib/string/inflections.rb +6 -76
  51. data/lib/gorillib/string/inflector.rb +192 -0
  52. data/lib/gorillib/string/simple_inflector.rb +267 -0
  53. data/lib/gorillib/type/extended.rb +52 -0
  54. data/lib/gorillib/utils/capture_output.rb +28 -0
  55. data/lib/gorillib/utils/console.rb +131 -0
  56. data/lib/gorillib/utils/nuke_constants.rb +9 -0
  57. data/lib/gorillib/utils/stub_module.rb +33 -0
  58. data/spec/examples/builder/ironfan_spec.rb +37 -0
  59. data/spec/extlib/hash_spec.rb +64 -0
  60. data/spec/extlib/mash_spec.rb +312 -0
  61. data/spec/{array → gorillib/array}/compact_blank_spec.rb +2 -2
  62. data/spec/{array → gorillib/array}/extract_options_spec.rb +2 -2
  63. data/spec/gorillib/builder_spec.rb +187 -0
  64. data/spec/gorillib/collection_spec.rb +20 -0
  65. data/spec/gorillib/configurable_spec.rb +62 -0
  66. data/spec/{datetime → gorillib/datetime}/parse_spec.rb +3 -3
  67. data/spec/{datetime/flat_spec.rb → gorillib/datetime/to_flat_spec.rb} +4 -4
  68. data/spec/{enumerable → gorillib/enumerable}/sum_spec.rb +5 -5
  69. data/spec/gorillib/exception/raisers_spec.rb +60 -0
  70. data/spec/{hash → gorillib/hash}/compact_spec.rb +2 -2
  71. data/spec/{hash → gorillib/hash}/deep_compact_spec.rb +3 -3
  72. data/spec/{hash → gorillib/hash}/deep_merge_spec.rb +2 -2
  73. data/spec/{hash → gorillib/hash}/keys_spec.rb +2 -2
  74. data/spec/{hash → gorillib/hash}/reverse_merge_spec.rb +2 -2
  75. data/spec/{hash → gorillib/hash}/slice_spec.rb +2 -2
  76. data/spec/{hash → gorillib/hash}/zip_spec.rb +2 -2
  77. data/spec/{hashlike → gorillib/hashlike}/behave_same_as_hash_spec.rb +6 -3
  78. data/spec/{hashlike → gorillib/hashlike}/deep_hash_spec.rb +2 -2
  79. data/spec/{hashlike → gorillib/hashlike}/hashlike_behavior_spec.rb +32 -30
  80. data/spec/{hashlike → gorillib/hashlike}/hashlike_via_accessors_spec.rb +3 -3
  81. data/spec/{hashlike_spec.rb → gorillib/hashlike_spec.rb} +3 -3
  82. data/spec/{logger → gorillib/logger}/log_spec.rb +2 -2
  83. data/spec/{metaprogramming → gorillib/metaprogramming}/aliasing_spec.rb +3 -3
  84. data/spec/{metaprogramming → gorillib/metaprogramming}/class_attribute_spec.rb +3 -3
  85. data/spec/{metaprogramming → gorillib/metaprogramming}/delegation_spec.rb +3 -3
  86. data/spec/{metaprogramming → gorillib/metaprogramming}/singleton_class_spec.rb +3 -3
  87. data/spec/gorillib/model/record/defaults_spec.rb +108 -0
  88. data/spec/gorillib/model/record/factories_spec.rb +321 -0
  89. data/spec/gorillib/model/record/overlay_spec.rb +46 -0
  90. data/spec/gorillib/model/serialization_spec.rb +48 -0
  91. data/spec/gorillib/model_spec.rb +281 -0
  92. data/spec/{numeric → gorillib/numeric}/clamp_spec.rb +2 -2
  93. data/spec/{object → gorillib/object}/blank_spec.rb +2 -2
  94. data/spec/{object → gorillib/object}/try_dup_spec.rb +2 -2
  95. data/spec/{object → gorillib/object}/try_spec.rb +3 -2
  96. data/spec/gorillib/pathname_spec.rb +114 -0
  97. data/spec/{string → gorillib/string}/constantize_spec.rb +2 -2
  98. data/spec/{string → gorillib/string}/human_spec.rb +2 -2
  99. data/spec/{string → gorillib/string}/inflections_spec.rb +4 -3
  100. data/spec/{string → gorillib/string}/inflector_test_cases.rb +0 -0
  101. data/spec/{string → gorillib/string}/truncate_spec.rb +4 -10
  102. data/spec/gorillib/type/extended_spec.rb +120 -0
  103. data/spec/gorillib/utils/capture_output_spec.rb +71 -0
  104. data/spec/spec_helper.rb +8 -11
  105. data/spec/support/gorillib_test_helpers.rb +66 -0
  106. data/spec/support/hashlike_fuzzing_helper.rb +31 -33
  107. data/spec/support/hashlike_helper.rb +3 -3
  108. data/spec/support/model_test_helpers.rb +81 -0
  109. data/spec/support/shared_examples/included_module.rb +20 -0
  110. metadata +177 -158
  111. data/lib/gorillib/array/average.rb +0 -13
  112. data/lib/gorillib/array/sorted_median.rb +0 -11
  113. data/lib/gorillib/array/sorted_percentile.rb +0 -11
  114. data/lib/gorillib/array/sorted_sample.rb +0 -12
  115. data/lib/gorillib/dsl_object.rb +0 -64
  116. data/lib/gorillib/hash/indifferent_access.rb +0 -207
  117. data/lib/gorillib/hash/tree_merge.rb +0 -4
  118. data/lib/gorillib/hashlike/tree_merge.rb +0 -49
  119. data/lib/gorillib/metaprogramming/cattr_accessor.rb +0 -79
  120. data/lib/gorillib/metaprogramming/mattr_accessor.rb +0 -61
  121. data/lib/gorillib/receiver/active_model_shim.rb +0 -32
  122. data/lib/gorillib/receiver/acts_as_hash.rb +0 -195
  123. data/lib/gorillib/receiver/acts_as_loadable.rb +0 -42
  124. data/lib/gorillib/receiver/locale/en.yml +0 -27
  125. data/lib/gorillib/receiver/tree_diff.rb +0 -74
  126. data/lib/gorillib/receiver/validations.rb +0 -30
  127. data/lib/gorillib/receiver.rb +0 -402
  128. data/lib/gorillib/receiver_model.rb +0 -21
  129. data/lib/gorillib/struct/acts_as_hash.rb +0 -108
  130. data/notes/fancy_hashes_and_receivers.textile +0 -120
  131. data/notes/hash_rdocs.textile +0 -97
  132. data/spec/array/average_spec.rb +0 -24
  133. data/spec/array/sorted_median_spec.rb +0 -18
  134. data/spec/array/sorted_percentile_spec.rb +0 -24
  135. data/spec/array/sorted_sample_spec.rb +0 -28
  136. data/spec/dsl_object_spec.rb +0 -99
  137. data/spec/hash/indifferent_access_spec.rb +0 -391
  138. data/spec/metaprogramming/cattr_accessor_spec.rb +0 -43
  139. data/spec/metaprogramming/mattr_accessor_spec.rb +0 -45
  140. data/spec/receiver/acts_as_hash_spec.rb +0 -295
  141. data/spec/receiver_spec.rb +0 -551
  142. data/spec/struct/acts_as_hash_fuzz_spec.rb +0 -71
  143. data/spec/struct/acts_as_hash_spec.rb +0 -422
@@ -1,295 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require 'gorillib/receiver'
3
- require 'gorillib/metaprogramming/class_attribute'
4
- require 'gorillib/hashlike'
5
- require 'gorillib/receiver/acts_as_hash'
6
- require GORILLIB_ROOT_DIR('spec/support/hashlike_helper')
7
- require GORILLIB_ROOT_DIR('spec/support/hashlike_via_delegation')
8
- require GORILLIB_ROOT_DIR('spec/hashlike/hashlike_behavior_spec')
9
-
10
- class SimpleReceiver
11
- include Receiver
12
- include Receiver::ActsAsHash
13
- #
14
- rcvr_accessor :a, Integer
15
- rcvr_accessor :b, Integer
16
- rcvr_accessor :c, Integer
17
- rcvr_accessor :nil_val, NilClass
18
- rcvr_accessor :false_val, Boolean
19
- rcvr_accessor :new_key, String
20
- end
21
-
22
- describe Receiver do
23
-
24
- before do
25
- @hshlike = SimpleReceiver.new.merge(HashlikeHelper::HASH_TO_TEST_HL_V_A.dup)
26
- @empty_hshlike = SimpleReceiver.new
27
- @hshlike_with_array_vals = SimpleReceiver.new.merge(HashlikeHelper::BASE_HSH_WITH_ARRAY_VALS.dup)
28
- #
29
- @hshlike_subklass = Class.new(SimpleReceiver)
30
- @hshlike_subklass_inst = @hshlike_subklass.new.merge(HashlikeHelper::BASE_HSH.dup)
31
- end
32
-
33
-
34
- # ===========================================================================
35
- #
36
- # Fundamental behavior
37
-
38
- describe '#[] and #[]= and #store' do
39
- it_should_behave_like :hashlike_store_and_retrieve
40
- it_should_behave_like :references_string_and_symbol_keys_equivalently
41
-
42
- it 'reject unknown keys' do
43
- lambda{ @hshlike[:fnord] = 69 }.should raise_error NoMethodError, /undefined method `fnord=' for/
44
- lambda{ @hshlike[:fnord] }.should raise_error NoMethodError, /undefined method `fnord' for/
45
- @hshlike.delete(:fnord).should be_nil
46
- end
47
-
48
- it 'accepts defined but unset keys' do
49
- @hshlike[:new_key].should be_nil
50
- @hshlike[:new_key] = 69
51
- @hshlike[:new_key].should == 69
52
- end
53
-
54
- it 'does not allow nil, Object, or other non-stringy keys' do
55
- lambda{ @hshlike[300] = :i_haz_num }.should raise_error(ArgumentError, "Keys for SimpleReceiver must be symbols, strings or respond to #to_sym")
56
- lambda{ @hshlike[nil] = :i_haz_nil }.should raise_error(ArgumentError, "Keys for SimpleReceiver must be symbols, strings or respond to #to_sym")
57
- obj = Object.new
58
- lambda{ @hshlike[obj] = :i_haz_obj }.should raise_error(ArgumentError, "Keys for SimpleReceiver must be symbols, strings or respond to #to_sym")
59
- def obj.to_sym() :c ; end
60
- @hshlike[obj] = :i_haz_obj
61
- @hshlike[obj].should == :i_haz_obj
62
- end
63
-
64
- it 'defines the right accessor methods' do
65
- @hshlike_subklass.rcvr_writer :write_only_attr, String
66
- @hshlike_subklass.rcvr_reader :read_only_attr, String
67
- @hshlike_subklass.rcvr :internal_attr, String
68
- @hshlike_subklass.class_eval{ attr_accessor :not_a_receiver }
69
- [ :receive_write_only_attr, :write_only_attr=,
70
- :receive_read_only_attr, :read_only_attr,
71
- :receive_internal_attr,
72
- :not_a_receiver, :not_a_receiver= ].each{ |attr| @hshlike_subklass.should be_method_defined(attr) }
73
- [ :write_only_attr, :read_only_attr=,
74
- :internal_attr, :internal_attr=,
75
- :receive_not_a_receiver ].each{ |attr| @hshlike_subklass.should_not be_method_defined(attr) }
76
- @hshlike_subklass.receiver_attr_names.should == [:a, :b, :c, :nil_val, :false_val, :new_key, :write_only_attr, :read_only_attr, :internal_attr]
77
- end
78
- end
79
-
80
- describe '#delete' do
81
- it_should_behave_like :hashlike_delete
82
- end
83
-
84
- describe '#keys' do
85
- it_should_behave_like :hashlike_keys
86
- end
87
-
88
- # ===========================================================================
89
- #
90
- # Iteration
91
-
92
- describe '#each_pair' do
93
- describe 'with block' do
94
- it_should_behave_like :each_pair_on_stringlike_keys, :each_pair
95
- end
96
- it_should_behave_like :with_no_block_returns_enumerator, :each_pair
97
- end
98
-
99
- describe '#each' do
100
- describe 'with block' do
101
- it_should_behave_like :each_pair_on_stringlike_keys, :each
102
- end
103
- it_should_behave_like :with_no_block_returns_enumerator, :each
104
- end
105
-
106
- describe '#each_key' do
107
- describe 'with block' do
108
- it_should_behave_like :each_key_on_stringlike_keys
109
- end
110
- it_should_behave_like :with_no_block_returns_enumerator, :each_key
111
- end
112
-
113
- describe '#each_value' do
114
- describe 'with block' do
115
- it_should_behave_like :each_value_on_stringlike_keys
116
- end
117
- it_should_behave_like :with_no_block_returns_enumerator, :each_value
118
- end
119
-
120
- # ===========================================================================
121
- #
122
- # Retrieval and Membership
123
-
124
- describe '#values' do
125
- it_should_behave_like :hashlike_values
126
- end
127
-
128
- describe '#values_at' do
129
- it_should_behave_like :hashlike_values_at_or_of, :values_at
130
- end
131
-
132
- describe '#values_of' do
133
- it_should_behave_like :hashlike_values_at_or_of, :values_of
134
- end
135
-
136
- describe '#length' do
137
- it_should_behave_like :hashlike_length, :length
138
- end
139
-
140
- describe '#size' do
141
- it_should_behave_like :hashlike_length, :size
142
- end
143
-
144
- describe '#has_key?' do
145
- it_should_behave_like :hashlike_has_key?, :has_key?
146
- it_should_behave_like :hashlike_has_key_string_and_symbol_equivalent, :has_key?
147
- end
148
-
149
- describe '#include?' do
150
- it_should_behave_like :hashlike_has_key?, :include?
151
- it_should_behave_like :hashlike_has_key_string_and_symbol_equivalent, :include?
152
- end
153
-
154
- describe '#key?' do
155
- it_should_behave_like :hashlike_has_key?, :key?
156
- it_should_behave_like :hashlike_has_key_string_and_symbol_equivalent, :key?
157
- end
158
-
159
- describe '#member?' do
160
- it_should_behave_like :hashlike_has_key?, :member?
161
- it_should_behave_like :hashlike_has_key_string_and_symbol_equivalent, :member?
162
- end
163
-
164
- describe '#has_value?' do
165
- it_should_behave_like :hashlike_has_value?, :has_value?
166
- end
167
-
168
- describe '#value?' do
169
- it_should_behave_like :hashlike_has_value?, :value?
170
- end
171
-
172
- describe '#fetch' do
173
- it_should_behave_like :hashlike_fetch
174
- end
175
-
176
- describe '#key' do
177
- it_should_behave_like :hashlike_key
178
- end
179
-
180
- describe '#assoc' do
181
- it_should_behave_like :hashlike_assoc
182
- end
183
-
184
- describe '#rassoc' do
185
- it_should_behave_like :hashlike_rassoc
186
- end
187
-
188
- describe '#empty?' do
189
- it_should_behave_like :hashlike_empty?
190
- end
191
-
192
- # ===========================================================================
193
- #
194
- # Update, merge!, merge
195
-
196
- describe 'update' do
197
- it_should_behave_like :merging_method, :update
198
- it_should_behave_like :merging_method_with_normal_keys, :update
199
- it_should_behave_like :merging_method_inplace, :update
200
- end
201
-
202
- describe '#merge!' do
203
- it_should_behave_like :merging_method, :merge!
204
- it_should_behave_like :merging_method_with_normal_keys, :merge!
205
- it_should_behave_like :merging_method_inplace, :merge!
206
- end
207
-
208
- describe '#merge' do
209
- it_should_behave_like :merging_method, :merge
210
- it_should_behave_like :merging_method_with_normal_keys, :merge
211
- it_should_behave_like :merging_method_returning_new, :merge
212
- end
213
-
214
- # ===========================================================================
215
- #
216
- # Filters
217
-
218
- describe '#reject!' do
219
- it_should_behave_like :hashlike_filter, :reject!
220
- it_should_behave_like :rejection_filter, :reject!
221
- it_should_behave_like :filter_modifies_self_returns_nil_if_unchanged, :reject!, false
222
- end
223
-
224
- describe '#select!' do
225
- it_should_behave_like :hashlike_filter, :select!
226
- it_should_behave_like :selection_filter, :select!
227
- it_should_behave_like :filter_modifies_self_returns_nil_if_unchanged, :select!, true
228
- end
229
-
230
- describe '#delete_if' do
231
- it_should_behave_like :hashlike_filter, :delete_if
232
- it_should_behave_like :rejection_filter, :delete_if
233
- it_should_behave_like :filter_modifies_self_returns_self, :delete_if, false
234
- end
235
-
236
- describe '#keep_if' do
237
- it_should_behave_like :hashlike_filter, :keep_if
238
- it_should_behave_like :selection_filter, :keep_if
239
- it_should_behave_like :filter_modifies_self_returns_self, :keep_if, true
240
- end
241
-
242
- describe '#reject' do
243
- it_should_behave_like :hashlike_filter, :select
244
- it_should_behave_like :selection_filter, :select
245
- it_should_behave_like :filter_does_not_modify_self_returns_same_class, :reject, false
246
- end
247
-
248
- describe '#select' do
249
- it_should_behave_like :hashlike_filter, :select
250
- it_should_behave_like :selection_filter, :select
251
- it_should_behave_like :filter_does_not_modify_self_returns_same_class, :select, true
252
- end
253
-
254
- describe '#clear' do
255
- it_should_behave_like :hashlike_clear
256
- end
257
-
258
- # ===========================================================================
259
- #
260
- # Conversion
261
-
262
- describe '#to_hash' do
263
- it_should_behave_like :hashlike_to_hash
264
-
265
- it 'should recurse' do
266
- @hshlike_subklass.rcvr_accessor :k2, SimpleReceiver
267
- hsh = HashlikeHelper::HASH_TO_TEST_HL_V_A.merge(:k2 => {:a => 3, :new_key => 'hi' })
268
- obj = @hshlike_subklass.receive(hsh)
269
- obj.to_hash.should == {:a=>100, :b=>200, :c=>300, :nil_val=>nil, :false_val=>false, :k2=>{:a=>3, :new_key=>"hi"} }
270
- end
271
- end
272
-
273
- describe '#invert' do
274
- it_should_behave_like :hashlike_invert
275
- end
276
-
277
- describe '#flatten' do
278
- it_should_behave_like :hashlike_flatten
279
- end
280
-
281
- # ===========================================================================
282
- #
283
- # Sanity check
284
-
285
- it 'built test objects correctly' do
286
- @hshlike_subklass .should < @hshlike.class
287
- @hshlike_subklass .should_not == @hshlike.class
288
- @hshlike_subklass_inst .should be_a(SimpleReceiver)
289
- @hshlike_subklass_inst .should be_a(@hshlike_subklass)
290
- @hshlike_subklass_inst .should_not be_an_instance_of(SimpleReceiver)
291
- @hshlike .should_not be_a(@hshlike_subklass)
292
- @hshlike .should be_an_instance_of(SimpleReceiver)
293
- end
294
-
295
- end