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.
data/lib/array/compositing.rb
CHANGED
@@ -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
|
-
|
183
|
+
return to_enum unless block_given?
|
172
184
|
|
173
|
-
|
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
|
-
|
184
|
-
|
185
|
-
return super
|
199
|
+
includes = false
|
186
200
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
-
|
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
|
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(
|
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
|
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
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
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
|
-
|
346
|
-
|
347
|
-
|
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
|
-
|
350
|
-
|
351
|
-
|
355
|
+
unless @without_child_hooks
|
356
|
+
object = child_pre_set_hook( local_index, object, false )
|
357
|
+
end
|
352
358
|
|
353
|
-
|
354
|
-
|
355
|
-
|
359
|
+
unless @without_hooks
|
360
|
+
object = pre_set_hook( local_index, object, false )
|
361
|
+
end
|
356
362
|
|
357
|
-
|
363
|
+
undecorated_set( local_index, object )
|
358
364
|
|
359
|
-
|
365
|
+
@parent_index_map.looked_up!( local_index )
|
360
366
|
|
361
|
-
|
362
|
-
|
363
|
-
|
367
|
+
unless @without_hooks
|
368
|
+
post_set_hook( local_index, object, false )
|
369
|
+
end
|
364
370
|
|
365
|
-
|
366
|
-
|
367
|
-
|
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(
|
415
|
+
def update_for_parent_insert( requested_parent_index, parent_index, object )
|
402
416
|
|
403
|
-
local_index = @parent_index_map.parent_insert(
|
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
|
501
|
-
|
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.
|
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-
|
12
|
+
date: 2012-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: array-hooked
|