array-compositing 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
1
 
2
+ begin ; require 'development' ; rescue ; end
3
+
2
4
  require 'array/hooked'
3
5
 
4
6
  # namespaces that have to be declared ahead of time for proper load order
@@ -40,8 +40,6 @@ module ::Array::Compositing::ArrayInterface
40
40
  # arrays that inherit from us
41
41
  @sub_composite_arrays = [ ]
42
42
 
43
- @parent_index_map = ::Array::Compositing::ParentIndexMap.new
44
-
45
43
  initialize_for_parent( parent_composite_array )
46
44
 
47
45
  end
@@ -56,6 +54,8 @@ module ::Array::Compositing::ArrayInterface
56
54
 
57
55
  if @parent_composite_object = parent_composite_array
58
56
 
57
+ @parent_index_map = ::Array::Compositing::ParentIndexMap.new
58
+
59
59
  @parent_composite_object.register_sub_composite_array( self )
60
60
 
61
61
  # record in our parent index map that parent has elements that have been inserted
@@ -157,7 +157,19 @@ module ::Array::Compositing::ArrayInterface
157
157
  def ==( object )
158
158
 
159
159
  load_parent_state
160
+
161
+ return super
160
162
 
163
+ end
164
+
165
+ #############
166
+ # inspect #
167
+ #############
168
+
169
+ def inspect
170
+
171
+ load_parent_state
172
+
161
173
  super
162
174
 
163
175
  end
@@ -168,9 +180,13 @@ module ::Array::Compositing::ArrayInterface
168
180
 
169
181
  def each( *args, & block )
170
182
 
171
- load_parent_state
183
+ return to_enum unless block_given?
172
184
 
173
- super
185
+ for index in 0...count
186
+ block.call( self[ index ] )
187
+ end
188
+
189
+ return self
174
190
 
175
191
  end
176
192
 
@@ -180,33 +196,16 @@ module ::Array::Compositing::ArrayInterface
180
196
 
181
197
  def include?( object )
182
198
 
183
- load_parent_state
184
-
185
- return super
199
+ includes = false
186
200
 
187
- end
188
-
189
- ##########
190
- # to_s #
191
- ##########
192
-
193
- def to_s
194
-
195
- #load_parent_state
196
-
197
- super
198
-
199
- end
200
-
201
- #############
202
- # inspect #
203
- #############
204
-
205
- def inspect
201
+ each do |this_member|
202
+ if this_member == object
203
+ includes = true
204
+ break
205
+ end
206
+ end
206
207
 
207
- load_parent_state
208
-
209
- super
208
+ return includes
210
209
 
211
210
  end
212
211
 
@@ -218,7 +217,7 @@ module ::Array::Compositing::ArrayInterface
218
217
 
219
218
  return_value = nil
220
219
 
221
- if @parent_index_map.requires_lookup?( local_index )
220
+ if @parent_index_map and @parent_index_map.requires_lookup?( local_index )
222
221
  return_value = lazy_set_parent_element_in_self( local_index )
223
222
  else
224
223
  return_value = super
@@ -233,9 +232,9 @@ module ::Array::Compositing::ArrayInterface
233
232
  #########
234
233
 
235
234
  def []=( local_index, object )
236
-
237
- super
238
235
 
236
+ super
237
+
239
238
  @sub_composite_arrays.each do |this_sub_array|
240
239
  this_sub_array.instance_eval do
241
240
  update_for_parent_set( local_index, object )
@@ -253,9 +252,11 @@ module ::Array::Compositing::ArrayInterface
253
252
  ###############
254
253
 
255
254
  def delete_at( local_index )
256
-
257
- @parent_index_map.local_delete_at( local_index )
258
-
255
+
256
+ if @parent_index_map
257
+ @parent_index_map.local_delete_at( local_index )
258
+ end
259
+
259
260
  deleted_object = non_cascading_delete_at( local_index )
260
261
 
261
262
  @sub_composite_arrays.each do |this_sub_array|
@@ -296,27 +297,30 @@ module ::Array::Compositing::ArrayInterface
296
297
 
297
298
  did_set = false
298
299
 
299
- if did_set = super
300
+ if did_set = super and @parent_index_map
300
301
  @parent_index_map.local_set( local_index )
302
+ else
301
303
  end
302
304
 
303
305
  return did_set
304
306
 
305
307
  end
306
-
308
+
307
309
  ################################################
308
310
  # perform_single_object_insert_between_hooks #
309
311
  ################################################
310
312
 
311
- def perform_single_object_insert_between_hooks( local_index, object )
313
+ def perform_single_object_insert_between_hooks( requested_local_index, object )
312
314
 
313
315
  if local_index = super
314
316
 
315
- @parent_index_map.local_insert( local_index, 1 )
316
-
317
+ if @parent_index_map
318
+ @parent_index_map.local_insert( local_index, 1 )
319
+ end
320
+
317
321
  @sub_composite_arrays.each do |this_sub_array|
318
322
  this_sub_array.instance_eval do
319
- update_for_parent_insert( local_index, object )
323
+ update_for_parent_insert( requested_local_index, local_index, object )
320
324
  end
321
325
  end
322
326
 
@@ -334,38 +338,46 @@ module ::Array::Compositing::ArrayInterface
334
338
 
335
339
  object = nil
336
340
 
337
- case optional_object.count
338
- when 0
339
- parent_index = @parent_index_map.parent_index( local_index )
340
- object = @parent_composite_object[ parent_index ]
341
- when 1
342
- object = optional_object[ 0 ]
343
- end
341
+ if @parent_index_map.requires_lookup?( local_index )
342
+
343
+ case optional_object.count
344
+ when 0
345
+ parent_index = @parent_index_map.parent_index( local_index )
346
+ object = @parent_composite_object[ parent_index ]
347
+ when 1
348
+ object = optional_object[ 0 ]
349
+ end
344
350
 
345
- # We call hooks manually so that we can do a direct undecorated set.
346
- # This is because we already have an object we loaded as a place-holder that we are now updating.
347
- # So we don't want to sort/test uniqueness/etc. We just want to insert at the actual index.
351
+ # We call hooks manually so that we can do a direct undecorated set.
352
+ # This is because we already have an object we loaded as a place-holder that we are now updating.
353
+ # So we don't want to sort/test uniqueness/etc. We just want to insert at the actual index.
348
354
 
349
- unless @without_child_hooks
350
- object = child_pre_set_hook( local_index, object, false )
351
- end
355
+ unless @without_child_hooks
356
+ object = child_pre_set_hook( local_index, object, false )
357
+ end
352
358
 
353
- unless @without_hooks
354
- object = pre_set_hook( local_index, object, false )
355
- end
359
+ unless @without_hooks
360
+ object = pre_set_hook( local_index, object, false )
361
+ end
356
362
 
357
- undecorated_set( local_index, object )
363
+ undecorated_set( local_index, object )
358
364
 
359
- @parent_index_map.looked_up!( local_index )
365
+ @parent_index_map.looked_up!( local_index )
360
366
 
361
- unless @without_hooks
362
- post_set_hook( local_index, object, false )
363
- end
367
+ unless @without_hooks
368
+ post_set_hook( local_index, object, false )
369
+ end
364
370
 
365
- unless @without_child_hooks
366
- child_post_set_hook( local_index, object, false )
367
- end
371
+ unless @without_child_hooks
372
+ child_post_set_hook( local_index, object, false )
373
+ end
368
374
 
375
+ else
376
+
377
+ object = undecorated_get( local_index )
378
+
379
+ end
380
+
369
381
  return object
370
382
 
371
383
  end
@@ -380,6 +392,8 @@ module ::Array::Compositing::ArrayInterface
380
392
 
381
393
  local_index = @parent_index_map.parent_set( parent_index )
382
394
 
395
+ undecorated_set( local_index, nil )
396
+
383
397
  if @parent_index_map.requires_lookup?( local_index )
384
398
 
385
399
  @sub_composite_arrays.each do |this_array|
@@ -398,15 +412,15 @@ module ::Array::Compositing::ArrayInterface
398
412
  # update_for_parent_insert #
399
413
  ##############################
400
414
 
401
- def update_for_parent_insert( parent_insert_index, object )
415
+ def update_for_parent_insert( requested_parent_index, parent_index, object )
402
416
 
403
- local_index = @parent_index_map.parent_insert( parent_insert_index, 1 )
417
+ local_index = @parent_index_map.parent_insert( parent_index, 1 )
404
418
 
405
419
  undecorated_insert( local_index, nil )
406
420
 
407
421
  @sub_composite_arrays.each do |this_array|
408
422
  this_array.instance_eval do
409
- update_for_parent_insert( local_index, object )
423
+ update_for_parent_insert( local_index, local_index, object )
410
424
  end
411
425
  end
412
426
 
@@ -497,8 +511,10 @@ module ::Array::Compositing::ArrayInterface
497
511
  def load_parent_state
498
512
 
499
513
  # if is used for case where duplicate is created (like :uniq) and initialization not called during dupe process
500
- @parent_index_map.indexes_requiring_lookup.each do |this_local_index|
501
- lazy_set_parent_element_in_self( this_local_index )
514
+ if @parent_index_map
515
+ @parent_index_map.indexes_requiring_lookup.each do |this_local_index|
516
+ lazy_set_parent_element_in_self( this_local_index )
517
+ end
502
518
  end
503
519
 
504
520
  end
@@ -18,7 +18,7 @@ describe ::Array::Compositing do
18
18
  sub_cascading_composite_array = ::Array::Compositing.new( cascading_composite_array )
19
19
  sub_cascading_composite_array.instance_variable_get( :@parent_composite_object ).should == cascading_composite_array
20
20
  sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
21
-
21
+
22
22
  end
23
23
 
24
24
  ##################################################################################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array-compositing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-14 00:00:00.000000000 Z
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: array-hooked