gorillib 0.4.1pre → 0.4.2pre

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 (89) hide show
  1. data/.gitignore +13 -10
  2. data/.rspec +1 -1
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +47 -0
  5. data/Gemfile +22 -19
  6. data/Guardfile +23 -9
  7. data/README.md +12 -12
  8. data/Rakefile +29 -40
  9. data/VERSION +1 -1
  10. data/examples/benchmark/factories_benchmark.rb +87 -0
  11. data/examples/builder/ironfan.rb +1 -19
  12. data/examples/hash/slicing_methods.rb +101 -0
  13. data/gorillib.gemspec +36 -35
  14. data/lib/gorillib/array/deep_compact.rb +4 -3
  15. data/lib/gorillib/array/simple_statistics.rb +76 -0
  16. data/lib/gorillib/base.rb +0 -1
  17. data/lib/gorillib/builder.rb +15 -30
  18. data/lib/gorillib/collection.rb +159 -57
  19. data/lib/gorillib/collection/model_collection.rb +136 -43
  20. data/lib/gorillib/datetime/parse.rb +4 -2
  21. data/lib/gorillib/{array → deprecated/array}/average.rb +0 -0
  22. data/lib/gorillib/{array → deprecated/array}/random.rb +2 -1
  23. data/lib/gorillib/{array → deprecated/array}/sorted_median.rb +0 -0
  24. data/lib/gorillib/{array → deprecated/array}/sorted_percentile.rb +0 -0
  25. data/lib/gorillib/deprecated/array/sorted_sample.rb +13 -0
  26. data/lib/gorillib/{metaprogramming → deprecated/metaprogramming}/aliasing.rb +0 -0
  27. data/lib/gorillib/enumerable/sum.rb +3 -3
  28. data/lib/gorillib/exception/raisers.rb +92 -22
  29. data/lib/gorillib/factories.rb +550 -0
  30. data/lib/gorillib/hash/mash.rb +15 -58
  31. data/lib/gorillib/hashlike/deep_compact.rb +2 -2
  32. data/lib/gorillib/hashlike/slice.rb +55 -40
  33. data/lib/gorillib/model.rb +5 -3
  34. data/lib/gorillib/model/base.rb +33 -119
  35. data/lib/gorillib/model/defaults.rb +58 -14
  36. data/lib/gorillib/model/errors.rb +10 -0
  37. data/lib/gorillib/model/factories.rb +1 -367
  38. data/lib/gorillib/model/field.rb +40 -18
  39. data/lib/gorillib/model/fixup.rb +16 -0
  40. data/lib/gorillib/model/positional_fields.rb +35 -0
  41. data/lib/gorillib/model/schema_magic.rb +162 -0
  42. data/lib/gorillib/model/serialization.rb +1 -2
  43. data/lib/gorillib/model/serialization/csv.rb +59 -0
  44. data/lib/gorillib/pathname.rb +19 -8
  45. data/lib/gorillib/some.rb +2 -0
  46. data/lib/gorillib/string/constantize.rb +17 -10
  47. data/lib/gorillib/string/inflector.rb +11 -7
  48. data/lib/gorillib/type/boolean.rb +40 -0
  49. data/lib/gorillib/type/extended.rb +76 -40
  50. data/lib/gorillib/type/url.rb +6 -4
  51. data/lib/gorillib/utils/console.rb +1 -18
  52. data/lib/gorillib/utils/edge_cases.rb +18 -0
  53. data/spec/examples/builder/ironfan_spec.rb +5 -10
  54. data/spec/gorillib/array/compact_blank_spec.rb +36 -21
  55. data/spec/gorillib/array/simple_statistics_spec.rb +143 -0
  56. data/spec/gorillib/builder_spec.rb +16 -20
  57. data/spec/gorillib/collection_spec.rb +131 -35
  58. data/spec/gorillib/exception/raisers_spec.rb +39 -0
  59. data/spec/gorillib/hash/deep_compact_spec.rb +3 -3
  60. data/spec/gorillib/model/{record/defaults_spec.rb → defaults_spec.rb} +5 -1
  61. data/spec/gorillib/model/factories_spec.rb +335 -0
  62. data/spec/gorillib/model/{record/overlay_spec.rb → overlay_spec.rb} +0 -0
  63. data/spec/gorillib/model/serialization_spec.rb +2 -2
  64. data/spec/gorillib/model_spec.rb +19 -18
  65. data/spec/gorillib/pathname_spec.rb +7 -7
  66. data/spec/gorillib/string/truncate_spec.rb +3 -13
  67. data/spec/gorillib/type/extended_spec.rb +50 -2
  68. data/spec/gorillib/utils/capture_output_spec.rb +1 -1
  69. data/spec/spec_helper.rb +10 -7
  70. data/spec/support/factory_test_helpers.rb +76 -0
  71. data/spec/support/gorillib_test_helpers.rb +36 -24
  72. data/spec/support/model_test_helpers.rb +39 -2
  73. metadata +86 -51
  74. data/lib/alt/kernel/call_stack.rb +0 -56
  75. data/lib/gorillib/array/sorted_sample.rb +0 -12
  76. data/lib/gorillib/builder/field.rb +0 -5
  77. data/lib/gorillib/collection/has_collection.rb +0 -31
  78. data/lib/gorillib/collection/list_collection.rb +0 -58
  79. data/lib/gorillib/exception/confidence.rb +0 -17
  80. data/lib/gorillib/io/system_helpers.rb +0 -30
  81. data/lib/gorillib/model/record_schema.rb +0 -9
  82. data/lib/gorillib/utils/stub_module.rb +0 -33
  83. data/spec/array/average_spec.rb +0 -24
  84. data/spec/array/sorted_median_spec.rb +0 -18
  85. data/spec/array/sorted_percentile_spec.rb +0 -24
  86. data/spec/array/sorted_sample_spec.rb +0 -28
  87. data/spec/gorillib/metaprogramming/aliasing_spec.rb +0 -180
  88. data/spec/gorillib/model/record/factories_spec.rb +0 -335
  89. data/spec/support/kcode_test_helper.rb +0 -16
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorillib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1pre
4
+ version: 0.4.2pre
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70333747262840 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '1.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70333747262840
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: bundler
27
- requirement: &70333747262300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '1.1'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70333747262300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &70333747261280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,29 +53,60 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70333747261280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
- name: oj
49
- requirement: &70333747260520 !ruby/object:Gem::Requirement
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
53
68
  - !ruby/object:Gem::Version
54
- version: '1.2'
69
+ version: '0.7'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70333747260520
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0.7'
58
78
  - !ruby/object:Gem::Dependency
59
- name: json
60
- requirement: &70333747259920 !ruby/object:Gem::Requirement
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
64
84
  - !ruby/object:Gem::Version
65
- version: '0'
85
+ version: '2.8'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70333747259920
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '2.8'
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '1.6'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '1.6'
69
110
  description: ! 'Gorillib: infochimps lightweight subset of ruby convenience methods'
70
111
  email: coders@infochimps.org
71
112
  executables: []
@@ -85,32 +126,32 @@ files:
85
126
  - Rakefile
86
127
  - TODO.md
87
128
  - VERSION
129
+ - examples/benchmark/factories_benchmark.rb
88
130
  - examples/builder/ironfan.rb
131
+ - examples/hash/slicing_methods.rb
89
132
  - examples/model/simple.rb
90
133
  - gorillib.gemspec
91
- - lib/alt/kernel/call_stack.rb
92
134
  - lib/gorillib.rb
93
- - lib/gorillib/array/average.rb
94
135
  - lib/gorillib/array/compact_blank.rb
95
136
  - lib/gorillib/array/deep_compact.rb
96
137
  - lib/gorillib/array/extract_options.rb
97
- - lib/gorillib/array/random.rb
98
- - lib/gorillib/array/sorted_median.rb
99
- - lib/gorillib/array/sorted_percentile.rb
100
- - lib/gorillib/array/sorted_sample.rb
138
+ - lib/gorillib/array/simple_statistics.rb
101
139
  - lib/gorillib/array/wrap.rb
102
140
  - lib/gorillib/base.rb
103
141
  - lib/gorillib/builder.rb
104
- - lib/gorillib/builder/field.rb
105
142
  - lib/gorillib/collection.rb
106
- - lib/gorillib/collection/has_collection.rb
107
- - lib/gorillib/collection/list_collection.rb
108
143
  - lib/gorillib/collection/model_collection.rb
109
144
  - lib/gorillib/datetime/parse.rb
110
145
  - lib/gorillib/datetime/to_flat.rb
146
+ - lib/gorillib/deprecated/array/average.rb
147
+ - lib/gorillib/deprecated/array/random.rb
148
+ - lib/gorillib/deprecated/array/sorted_median.rb
149
+ - lib/gorillib/deprecated/array/sorted_percentile.rb
150
+ - lib/gorillib/deprecated/array/sorted_sample.rb
151
+ - lib/gorillib/deprecated/metaprogramming/aliasing.rb
111
152
  - lib/gorillib/enumerable/sum.rb
112
- - lib/gorillib/exception/confidence.rb
113
153
  - lib/gorillib/exception/raisers.rb
154
+ - lib/gorillib/factories.rb
114
155
  - lib/gorillib/hash/compact.rb
115
156
  - lib/gorillib/hash/deep_compact.rb
116
157
  - lib/gorillib/hash/deep_dup.rb
@@ -130,9 +171,7 @@ files:
130
171
  - lib/gorillib/hashlike/keys.rb
131
172
  - lib/gorillib/hashlike/reverse_merge.rb
132
173
  - lib/gorillib/hashlike/slice.rb
133
- - lib/gorillib/io/system_helpers.rb
134
174
  - lib/gorillib/logger/log.rb
135
- - lib/gorillib/metaprogramming/aliasing.rb
136
175
  - lib/gorillib/metaprogramming/class_attribute.rb
137
176
  - lib/gorillib/metaprogramming/concern.rb
138
177
  - lib/gorillib/metaprogramming/delegation.rb
@@ -148,11 +187,14 @@ files:
148
187
  - lib/gorillib/model/errors.rb
149
188
  - lib/gorillib/model/factories.rb
150
189
  - lib/gorillib/model/field.rb
190
+ - lib/gorillib/model/fixup.rb
151
191
  - lib/gorillib/model/lint.rb
152
192
  - lib/gorillib/model/named_schema.rb
153
193
  - lib/gorillib/model/overlay.rb
154
- - lib/gorillib/model/record_schema.rb
194
+ - lib/gorillib/model/positional_fields.rb
195
+ - lib/gorillib/model/schema_magic.rb
155
196
  - lib/gorillib/model/serialization.rb
197
+ - lib/gorillib/model/serialization/csv.rb
156
198
  - lib/gorillib/model/validate.rb
157
199
  - lib/gorillib/numeric/clamp.rb
158
200
  - lib/gorillib/object/blank.rb
@@ -167,12 +209,13 @@ files:
167
209
  - lib/gorillib/string/inflector.rb
168
210
  - lib/gorillib/string/simple_inflector.rb
169
211
  - lib/gorillib/string/truncate.rb
212
+ - lib/gorillib/type/boolean.rb
170
213
  - lib/gorillib/type/extended.rb
171
214
  - lib/gorillib/type/url.rb
172
215
  - lib/gorillib/utils/capture_output.rb
173
216
  - lib/gorillib/utils/console.rb
217
+ - lib/gorillib/utils/edge_cases.rb
174
218
  - lib/gorillib/utils/nuke_constants.rb
175
- - lib/gorillib/utils/stub_module.rb
176
219
  - notes/HOWTO.md
177
220
  - notes/bucket.md
178
221
  - notes/builder.md
@@ -181,15 +224,12 @@ files:
181
224
  - notes/model-overlay.md
182
225
  - notes/model.md
183
226
  - notes/structured-data-classes.md
184
- - spec/array/average_spec.rb
185
- - spec/array/sorted_median_spec.rb
186
- - spec/array/sorted_percentile_spec.rb
187
- - spec/array/sorted_sample_spec.rb
188
227
  - spec/examples/builder/ironfan_spec.rb
189
228
  - spec/extlib/hash_spec.rb
190
229
  - spec/extlib/mash_spec.rb
191
230
  - spec/gorillib/array/compact_blank_spec.rb
192
231
  - spec/gorillib/array/extract_options_spec.rb
232
+ - spec/gorillib/array/simple_statistics_spec.rb
193
233
  - spec/gorillib/builder_spec.rb
194
234
  - spec/gorillib/collection_spec.rb
195
235
  - spec/gorillib/datetime/parse_spec.rb
@@ -209,14 +249,13 @@ files:
209
249
  - spec/gorillib/hashlike/hashlike_via_accessors_spec.rb
210
250
  - spec/gorillib/hashlike_spec.rb
211
251
  - spec/gorillib/logger/log_spec.rb
212
- - spec/gorillib/metaprogramming/aliasing_spec.rb
213
252
  - spec/gorillib/metaprogramming/class_attribute_spec.rb
214
253
  - spec/gorillib/metaprogramming/delegation_spec.rb
215
254
  - spec/gorillib/metaprogramming/singleton_class_spec.rb
255
+ - spec/gorillib/model/defaults_spec.rb
256
+ - spec/gorillib/model/factories_spec.rb
216
257
  - spec/gorillib/model/lint_spec.rb
217
- - spec/gorillib/model/record/defaults_spec.rb
218
- - spec/gorillib/model/record/factories_spec.rb
219
- - spec/gorillib/model/record/overlay_spec.rb
258
+ - spec/gorillib/model/overlay_spec.rb
220
259
  - spec/gorillib/model/serialization_spec.rb
221
260
  - spec/gorillib/model_spec.rb
222
261
  - spec/gorillib/numeric/clamp_spec.rb
@@ -232,20 +271,20 @@ files:
232
271
  - spec/gorillib/type/extended_spec.rb
233
272
  - spec/gorillib/utils/capture_output_spec.rb
234
273
  - spec/spec_helper.rb
274
+ - spec/support/factory_test_helpers.rb
235
275
  - spec/support/gorillib_test_helpers.rb
236
276
  - spec/support/hashlike_fuzzing_helper.rb
237
277
  - spec/support/hashlike_helper.rb
238
278
  - spec/support/hashlike_struct_helper.rb
239
279
  - spec/support/hashlike_via_delegation.rb
240
- - spec/support/kcode_test_helper.rb
241
280
  - spec/support/matchers/be_array_eql.rb
242
281
  - spec/support/matchers/be_hash_eql.rb
243
282
  - spec/support/matchers/enumerate_method.rb
244
283
  - spec/support/matchers/evaluate_to_true.rb
245
284
  - spec/support/model_test_helpers.rb
246
- homepage: http://infochimps.com/labs
285
+ homepage: https://github.com/infochimps-labs/gorillib
247
286
  licenses:
248
- - MIT
287
+ - Apache 2.0
249
288
  post_install_message:
250
289
  rdoc_options: []
251
290
  require_paths:
@@ -264,20 +303,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
303
  version: '0'
265
304
  requirements: []
266
305
  rubyforge_project:
267
- rubygems_version: 1.8.11
306
+ rubygems_version: 1.8.24
268
307
  signing_key:
269
308
  specification_version: 3
270
309
  summary: include only what you need. No dependencies, no creep
271
310
  test_files:
272
- - spec/array/average_spec.rb
273
- - spec/array/sorted_median_spec.rb
274
- - spec/array/sorted_percentile_spec.rb
275
- - spec/array/sorted_sample_spec.rb
276
311
  - spec/examples/builder/ironfan_spec.rb
277
312
  - spec/extlib/hash_spec.rb
278
313
  - spec/extlib/mash_spec.rb
279
314
  - spec/gorillib/array/compact_blank_spec.rb
280
315
  - spec/gorillib/array/extract_options_spec.rb
316
+ - spec/gorillib/array/simple_statistics_spec.rb
281
317
  - spec/gorillib/builder_spec.rb
282
318
  - spec/gorillib/collection_spec.rb
283
319
  - spec/gorillib/datetime/parse_spec.rb
@@ -297,14 +333,13 @@ test_files:
297
333
  - spec/gorillib/hashlike/hashlike_via_accessors_spec.rb
298
334
  - spec/gorillib/hashlike_spec.rb
299
335
  - spec/gorillib/logger/log_spec.rb
300
- - spec/gorillib/metaprogramming/aliasing_spec.rb
301
336
  - spec/gorillib/metaprogramming/class_attribute_spec.rb
302
337
  - spec/gorillib/metaprogramming/delegation_spec.rb
303
338
  - spec/gorillib/metaprogramming/singleton_class_spec.rb
339
+ - spec/gorillib/model/defaults_spec.rb
340
+ - spec/gorillib/model/factories_spec.rb
304
341
  - spec/gorillib/model/lint_spec.rb
305
- - spec/gorillib/model/record/defaults_spec.rb
306
- - spec/gorillib/model/record/factories_spec.rb
307
- - spec/gorillib/model/record/overlay_spec.rb
342
+ - spec/gorillib/model/overlay_spec.rb
308
343
  - spec/gorillib/model/serialization_spec.rb
309
344
  - spec/gorillib/model_spec.rb
310
345
  - spec/gorillib/numeric/clamp_spec.rb
@@ -320,12 +355,12 @@ test_files:
320
355
  - spec/gorillib/type/extended_spec.rb
321
356
  - spec/gorillib/utils/capture_output_spec.rb
322
357
  - spec/spec_helper.rb
358
+ - spec/support/factory_test_helpers.rb
323
359
  - spec/support/gorillib_test_helpers.rb
324
360
  - spec/support/hashlike_fuzzing_helper.rb
325
361
  - spec/support/hashlike_helper.rb
326
362
  - spec/support/hashlike_struct_helper.rb
327
363
  - spec/support/hashlike_via_delegation.rb
328
- - spec/support/kcode_test_helper.rb
329
364
  - spec/support/matchers/be_array_eql.rb
330
365
  - spec/support/matchers/be_hash_eql.rb
331
366
  - spec/support/matchers/enumerate_method.rb
@@ -1,56 +0,0 @@
1
- module Kernel
2
-
3
- alias_method :pp_callstack, :caller
4
- alias_method :pp_call_stack, :caller
5
-
6
- # Parse a caller string and break it into its components,
7
- # returning an array composed of:
8
- #
9
- # * file (String)
10
- # * lineno (Integer)
11
- # * method (Symbol)
12
- #
13
- # For example, from irb
14
- #
15
- # call_stack(1)
16
- #
17
- # _produces_ ...
18
- #
19
- # [["(irb)", 2, :irb_binding],
20
- # ["/usr/lib/ruby/1.8/irb/workspace.rb", 52, :irb_binding],
21
- # ["/usr/lib/ruby/1.8/irb/workspace.rb", 52, nil]]
22
- #
23
- # Note: If the user decides to redefine caller() to output data
24
- # in a different format, _prior_ to requiring this, then the
25
- # results will be indeterminate.
26
- #
27
- # CREDIT: Trans
28
-
29
- def call_stack(level = 1)
30
- call_str_array = pp_call_stack(level)
31
- stack = []
32
- call_str_array.each{ |call_str|
33
- file, lineno, method = call_str.split(':')
34
- if method =~ /in `(.*)'/ then
35
- method = $1.intern()
36
- end
37
- stack << [file, lineno.to_i, method]
38
- }
39
- stack
40
- end
41
-
42
- alias_method :callstack, :call_stack
43
-
44
- end
45
-
46
-
47
- class Binding
48
-
49
- # Returns the call stack, in array format.
50
- def call_stack(level=1)
51
- eval( "callstack( #{level} )" )
52
- end
53
-
54
- alias_method :callstack, :call_stack
55
- end
56
-
@@ -1,12 +0,0 @@
1
- class Array
2
- #
3
- # Returns the middle element of odd-sized arrays. For even arrays,
4
- # it will return one of the two middle elements. Precisely which is
5
- # undefined, except that it will consistently return one or the
6
- # other.
7
- #
8
- def sorted_sample num
9
- return [] if empty?
10
- (1..num).map{|i| self[(size - 1) * i / (num)]}.uniq
11
- end
12
- end
@@ -1,5 +0,0 @@
1
- module Gorillib
2
- module Builder
3
-
4
- end
5
- end
@@ -1,31 +0,0 @@
1
- # module Gorillib
2
- # class Collection
3
- # module HasCollection
4
- #
5
- # def has_collection(clxn_name, type, key_method=:name)
6
- # plural_name = clxn_name
7
- # singular_name = Gorillib::Inflector.singularize(clxn_name.to_s).to_sym
8
- #
9
- # instance_variable_set("@#{plural_name}", Gorillib::Collection.new(type, key_method))
10
- #
11
- # define_singleton_method(plural_name) do
12
- # instance_variable_get("@#{plural_name}") if instance_variable_defined?("@#{plural_name}")
13
- # end
14
- #
15
- # define_singleton_method(singular_name) do |item_key, attrs={}, options={}, &block|
16
- # collection = instance_variable_get("@#{clxn_name}")
17
- # val = collection.fetch(item_key) do
18
- # attrs.merge!(key_method => item_key, :owner => self) if attrs.respond_to?(:merge!)
19
- # factory = options.fetch(:factory){ type }
20
- # new_val = factory.receive(attrs)
21
- # collection << new_val
22
- # new_val
23
- # end
24
- # val.instance_exec(&block) if block
25
- # val
26
- # end
27
- # end
28
- #
29
- # end
30
- # end
31
- # end
@@ -1,58 +0,0 @@
1
- require 'gorillib/collection'
2
-
3
- module Gorillib
4
- class ListCollection < Gorillib::GenericCollection
5
-
6
- def initialize
7
- @clxn = Array.new
8
- end
9
-
10
- # common to all collections, delegable to array
11
- delegate :to_a, :each, :to => :clxn
12
-
13
- # Add the new items in-place; given items clobber existing items
14
- # @param other [{Symbol => Object}, Array<Object>] a hash of key=>item pairs or a list of items
15
- # @return [Gorillib::Collection] the collection
16
- def receive!(other)
17
- clxn.concat( convert_collection(other) ).uniq!
18
- self
19
- end
20
-
21
- # @return [Array] an array holding the items
22
- def values ; to_a ; end
23
-
24
- # iterate over each value in the collection
25
- def each_value(&block); each(&block) ; end
26
-
27
- # # removed on purpose, pending us understanding what the
28
- # # even-yet-simpler-still collection should be.
29
- #
30
- # delegate :[], :[]=, :fetch, :to => :clxn
31
- #
32
- # # Deletes the entry whose index is `idx`, returning the corresponding
33
- # # value. If the index is out of bounds, returns nil. If the optional code
34
- # # block is given and the index is out of bounds, pass it the index and
35
- # # return the result of block.
36
- # #
37
- # # @return the now-delete value, if found; otherwise, the result of the
38
- # # block, if given; otherwise nil.
39
- # def delete(idx, &block)
40
- # if idx < length
41
- # clxn.delete_at(idx)
42
- # elsif block_given?
43
- # yield(idx)
44
- # else
45
- # nil
46
- # end
47
- # end
48
-
49
- protected
50
-
51
- # - if the given collection responds_to `to_hash`, it is received into the internal collection; each hash key *must* match the id of its value or results are undefined.
52
- # - otherwise, it uses a hash generated from the id/value pairs of each object in the given collection.
53
- def convert_collection(cc)
54
- cc.respond_to?(:values) ? cc.values : cc.to_a
55
- end
56
- end
57
-
58
- end