array-hooked 1.1.0 → 1.1.1

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.
@@ -10,3 +10,7 @@ Added missing :get_without_hooks and corresponding hooks.
10
10
  == 6/30/2012
11
11
 
12
12
  Renamed from hooked-array to array-hooked. File schema updated to reflect gem name.
13
+
14
+ == 7/4/2012
15
+
16
+ Updated to use module-cluster to ensure interface encapsulation.
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'identifies_as'
3
+ require 'module/cluster'
3
4
 
4
5
  # namespaces that have to be declared ahead of time for proper load order
5
6
  require_relative './namespaces'
@@ -9,35 +10,6 @@ require_relative './requires.rb'
9
10
 
10
11
  class ::Array::Hooked < ::Array
11
12
 
12
- ###############################
13
- # perform_set_between_hooks #
14
- ###############################
15
-
16
- # Alias to original :[]= method. Used to perform actual set between hooks.
17
- # @param [Fixnum] index Index at which set is taking place.
18
- # @param [Object] object Element being set.
19
- # @return [Object] Element returned.
20
- alias_method :perform_set_between_hooks, :[]=
21
-
22
- ##################################
23
- # perform_insert_between_hooks #
24
- ##################################
25
-
26
- # Alias to original :insert method. Used to perform actual insert between hooks.
27
- # @param [Fixnum] index Index at which insert is taking place.
28
- # @param [Array<Object>] objects Elements being inserted.
29
- # @return [Object] Element returned.
30
- alias_method :perform_insert_between_hooks, :insert
31
-
32
- ##################################
33
- # perform_delete_between_hooks #
34
- ##################################
35
-
36
- # Alias to original :delete method. Used to perform actual delete between hooks.
37
- # @param [Fixnum] index Index at which delete is taking place.
38
- # @return [Object] Element returned.
39
- alias_method :perform_delete_between_hooks, :delete_at
40
-
41
13
  include ::Array::Hooked::ArrayInterface
42
14
 
43
15
  end
@@ -2,7 +2,64 @@
2
2
  module ::Array::Hooked::ArrayInterface
3
3
 
4
4
  instances_identify_as!( ::Array::Hooked )
5
+
6
+ extend ::Module::Cluster
7
+
8
+ cluster( :hooked_array_interface ).before_include.cascade_to( :class ) do |hooked_instance|
9
+
10
+ hooked_instance.class_eval do
11
+
12
+ #####################
13
+ # undecorated_set #
14
+ #####################
15
+
16
+ # Alias to original :[]= method. Used to perform actual set between hooks.
17
+ # @param [Fixnum] index Index at which set is taking place.
18
+ # @param [Object] object Element being set.
19
+ # @return [Object] Element returned.
20
+ unless method_defined?( :undecorated_set )
21
+ alias_method :undecorated_set, :[]=
22
+ end
23
+
24
+ #####################
25
+ # undecorated_get #
26
+ #####################
5
27
 
28
+ # Alias to original :[]= method. Used to perform actual set between hooks.
29
+ # @param [Fixnum] index Index at which set is taking place.
30
+ # @param [Object] object Element being set.
31
+ # @return [Object] Element returned.
32
+ unless method_defined?( :undecorated_get )
33
+ alias_method :undecorated_get, :[]
34
+ end
35
+
36
+ ########################
37
+ # undecorated_insert #
38
+ ########################
39
+
40
+ # Alias to original :insert method. Used to perform actual insert between hooks.
41
+ # @param [Fixnum] index Index at which insert is taking place.
42
+ # @param [Array<Object>] objects Elements being inserted.
43
+ # @return [Object] Element returned.
44
+ unless method_defined?( :undecorated_insert )
45
+ alias_method :undecorated_insert, :insert
46
+ end
47
+
48
+ ###########################
49
+ # undecorated_delete_at #
50
+ ###########################
51
+
52
+ # Alias to original :delete method. Used to perform actual delete between hooks.
53
+ # @param [Fixnum] index Index at which delete is taking place.
54
+ # @return [Object] Element returned.
55
+ unless method_defined?( :undecorated_delete_at )
56
+ alias_method :undecorated_delete_at, :delete_at
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
6
63
  ################
7
64
  # initialize #
8
65
  ################
@@ -19,14 +76,14 @@ module ::Array::Hooked::ArrayInterface
19
76
  super( *args )
20
77
 
21
78
  end
22
-
79
+
23
80
  ############################
24
81
  # configuration_instance #
25
82
  ############################
26
83
 
27
84
  attr_accessor :configuration_instance
28
85
 
29
- ###################################### Subclass Hooks ##########################################
86
+ ################################################ Subclass Hooks ####################################################
30
87
 
31
88
  ##################
32
89
  # pre_set_hook #
@@ -144,28 +201,10 @@ module ::Array::Hooked::ArrayInterface
144
201
 
145
202
  end
146
203
 
147
- #######################
148
- # get_without_hooks #
149
- #######################
150
-
151
- # Alias to :[] that bypasses hooks.
152
- # @param [Fixnum] index Index at which set is taking place.
153
- # @return [Object] Element returned.
154
- def get_without_hooks( index )
155
-
156
- @without_hooks = true
157
-
158
- self[ index ] = object
159
-
160
- @without_hooks = false
161
-
162
- return object
163
-
164
- end
165
-
166
- #########
167
- # []= #
168
- #########
204
+ ################
205
+ # []= #
206
+ # hooked_set #
207
+ ################
169
208
 
170
209
  def []=( index, object )
171
210
 
@@ -187,55 +226,22 @@ module ::Array::Hooked::ArrayInterface
187
226
 
188
227
  end
189
228
 
190
- #######################
191
- # set_without_hooks #
192
- #######################
193
-
194
- # Alias to :[]= that bypasses hooks.
195
- # @param [Fixnum] index Index at which set is taking place.
196
- # @param [Object] object Element being set.
197
- # @return [Object] Element returned.
198
- def set_without_hooks( index, object )
199
-
200
- @without_hooks = true
229
+ alias_method :hooked_set, :[]=
230
+
231
+ ###################
232
+ # insert #
233
+ # hooked_insert #
234
+ ###################
201
235
 
202
- self[ index ] = object
203
-
204
- @without_hooks = false
205
-
206
- return object
207
-
208
- end
236
+ def insert( index, *objects )
209
237
 
210
- ############
211
- # insert #
212
- ############
238
+ index = filter_insert_objects( index, objects )
213
239
 
214
- def insert( index, *objects )
215
-
216
- objects_to_insert = nil
217
- if @without_hooks
218
- objects_to_insert = objects
219
- else
220
- objects_to_insert = [ ]
240
+ unless @without_hooks
221
241
  objects.each_with_index do |this_object, this_index|
222
- this_insert_index = index + this_index
223
- this_object = pre_set_hook( this_insert_index, this_object, true )
224
- objects_to_insert.push( this_object )
225
- end
226
- end
227
- objects = objects_to_insert
228
-
229
- # if we have less elements in self than the index we are inserting at
230
- # we need to make sure the nils inserted cascade
231
- if index > count
232
- nils_created = index - count
233
- index -= nils_created
234
- nils = [ ]
235
- nils_created.times do |this_time|
236
- nils.push( nil )
242
+ this_object = pre_set_hook( index + this_index, this_object, true )
243
+ objects[ this_index ] = this_object
237
244
  end
238
- objects = nils.concat( objects )
239
245
  end
240
246
 
241
247
  perform_insert_between_hooks( index, *objects )
@@ -249,26 +255,8 @@ module ::Array::Hooked::ArrayInterface
249
255
  return objects
250
256
 
251
257
  end
252
-
253
- ##########################
254
- # insert_without_hooks #
255
- ##########################
256
-
257
- # Alias to :insert that bypasses hooks.
258
- # @param [Fixnum] index Index at which set is taking place.
259
- # @param [Array<Object>] objects Elements being inserted.
260
- # @return [Object] Element returned.
261
- def insert_without_hooks( index, *objects )
262
-
263
- @without_hooks = true
264
-
265
- super( index, *objects )
266
-
267
- @without_hooks = false
268
-
269
- return objects
270
-
271
- end
258
+
259
+ alias_method :hooked_insert, :insert
272
260
 
273
261
  ##########
274
262
  # push #
@@ -282,25 +270,6 @@ module ::Array::Hooked::ArrayInterface
282
270
 
283
271
  alias_method :<<, :push
284
272
 
285
- ########################
286
- # push_without_hooks #
287
- ########################
288
-
289
- # Alias to :push that bypasses hooks.
290
- # @param [Array<Object>] objects Elements being pushed.
291
- # @return [Object] Element returned.
292
- def push_without_hooks( *objects )
293
-
294
- @without_hooks = true
295
-
296
- push( *objects )
297
-
298
- @without_hooks = false
299
-
300
- return objects
301
-
302
- end
303
-
304
273
  ############
305
274
  # concat #
306
275
  ############
@@ -317,28 +286,10 @@ module ::Array::Hooked::ArrayInterface
317
286
 
318
287
  alias_method :+, :concat
319
288
 
320
- ##########################
321
- # concat_without_hooks #
322
- ##########################
323
-
324
- # Alias to :concat that bypasses hooks.
325
- # @param [Array<Object>] objects Elements being concatenated.
326
- # @return [Object] Element returned.
327
- def concat_without_hooks( *arrays )
328
-
329
- @without_hooks = true
330
-
331
- concat( *arrays )
332
-
333
- @without_hooks = false
334
-
335
- return arrays
336
-
337
- end
338
-
339
- ############
340
- # delete #
341
- ############
289
+ ###################
290
+ # delete #
291
+ # hooked_delete #
292
+ ###################
342
293
 
343
294
  def delete( object )
344
295
 
@@ -351,30 +302,22 @@ module ::Array::Hooked::ArrayInterface
351
302
  return return_value
352
303
 
353
304
  end
354
-
355
- ##########################
356
- # delete_without_hooks #
357
- ##########################
358
-
359
- # Alias to :delete that bypasses hooks.
360
- # @param [Object] object Element being deleted.
361
- # @return [Object] Element returned.
362
- def delete_without_hooks( object )
363
-
364
- @without_hooks = true
365
-
366
- return_value = delete( object )
367
-
368
- @without_hooks = false
369
-
370
- return return_value
371
-
372
- end
305
+
306
+ alias_method :hooked_delete, :delete
373
307
 
374
308
  ####################
375
309
  # delete_objects #
376
310
  ####################
377
311
 
312
+ ###
313
+ # Delete more than one object at a time.
314
+ #
315
+ # @overload delete_objects( object, ... )
316
+ #
317
+ # @param object Object to delete.
318
+ #
319
+ # @return [Array<Object>] Deleted objects.
320
+ #
378
321
  def delete_objects( *objects )
379
322
 
380
323
  return_value = nil
@@ -395,25 +338,6 @@ module ::Array::Hooked::ArrayInterface
395
338
 
396
339
  end
397
340
 
398
- ##################################
399
- # delete_objects_without_hooks #
400
- ##################################
401
-
402
- # Alias to :delete that bypasses hooks and takes multiple objects.
403
- # @param [Array<Object>] objects Elements being deleted.
404
- # @return [Object] Element returned.
405
- def delete_objects_without_hooks( *objects )
406
-
407
- @without_hooks = true
408
-
409
- return_value = delete_objects( *objects )
410
-
411
- @without_hooks = false
412
-
413
- return return_value
414
-
415
- end
416
-
417
341
  #######
418
342
  # - #
419
343
  #######
@@ -444,7 +368,7 @@ module ::Array::Hooked::ArrayInterface
444
368
 
445
369
  if pre_delete_hook_result
446
370
 
447
- deleted_object = perform_delete_between_hooks( index )
371
+ deleted_object = perform_delete_at_between_hooks( index )
448
372
 
449
373
  unless @without_hooks
450
374
  deleted_object = post_delete_hook( index, deleted_object )
@@ -455,25 +379,8 @@ module ::Array::Hooked::ArrayInterface
455
379
  return deleted_object
456
380
 
457
381
  end
458
-
459
- #############################
460
- # delete_at_without_hooks #
461
- #############################
462
-
463
- # Alias to :delete_at that bypasses hooks.
464
- # @param [Fixnum] index Index to delete.
465
- # @return [Object] Deleted element.
466
- def delete_at_without_hooks( index )
467
-
468
- @without_hooks = true
469
-
470
- object = delete_at( index )
471
-
472
- @without_hooks = false
473
-
474
- return object
475
-
476
- end
382
+
383
+ alias_method :hooked_delete_at, :delete_at
477
384
 
478
385
  #######################
479
386
  # delete_at_indexes #
@@ -493,25 +400,6 @@ module ::Array::Hooked::ArrayInterface
493
400
 
494
401
  end
495
402
 
496
- #####################################
497
- # delete_at_indexes_without_hooks #
498
- #####################################
499
-
500
- # Alias to :delete_at that bypasses hooks and takes multiple indexes.
501
- # @param [Array<Fixnum>] index Index to delete.
502
- # @return [Object] Deleted element.
503
- def delete_at_indexes_without_hooks( *indexes )
504
-
505
- @without_hooks = true
506
-
507
- objects = delete_at_indexes( *indexes )
508
-
509
- @without_hooks = false
510
-
511
- return objects
512
-
513
- end
514
-
515
403
  ###############
516
404
  # delete_if #
517
405
  ###############
@@ -534,25 +422,6 @@ module ::Array::Hooked::ArrayInterface
534
422
 
535
423
  end
536
424
 
537
- #############################
538
- # delete_if_without_hooks #
539
- #############################
540
-
541
- # Alias to :delete_if that bypasses hooks.
542
- # @yield Block passed to :delete_if.
543
- # @return [Object] Deleted element.
544
- def delete_if_without_hooks( & block )
545
-
546
- @without_hooks = true
547
-
548
- delete_if( & block )
549
-
550
- @without_hooks = false
551
-
552
- return self
553
-
554
- end
555
-
556
425
  #############
557
426
  # keep_if #
558
427
  #############
@@ -573,52 +442,15 @@ module ::Array::Hooked::ArrayInterface
573
442
 
574
443
  end
575
444
 
576
- ###########################
577
- # keep_if_without_hooks #
578
- ###########################
445
+ ##############
446
+ # compact! #
447
+ ##############
579
448
 
580
- # Alias to :keep_if that bypasses hooks.
581
- # @yield Block passed to :keep_if.
582
- # @return [Object] Deleted element.
583
- def keep_if_without_hooks( & block )
449
+ def compact!
584
450
 
585
- @without_hooks = true
586
-
587
- keep_if( & block )
588
-
589
- @without_hooks = false
590
-
591
- return self
592
-
593
- end
594
-
595
- ##############
596
- # compact! #
597
- ##############
598
-
599
- def compact!
600
-
601
- return keep_if do |object|
602
- object != nil
603
- end
604
-
605
- end
606
-
607
- ############################
608
- # compact_without_hooks! #
609
- ############################
610
-
611
- # Alias to :compact that bypasses hooks.
612
- # @return [Object] Self.
613
- def compact_without_hooks!
614
-
615
- @without_hooks = true
616
-
617
- compact!
618
-
619
- @without_hooks = false
620
-
621
- return self
451
+ return keep_if do |object|
452
+ object != nil
453
+ end
622
454
 
623
455
  end
624
456
 
@@ -632,9 +464,9 @@ module ::Array::Hooked::ArrayInterface
632
464
 
633
465
  indexes = [ ]
634
466
 
635
- self.each_with_index do |this_object, index|
636
- if this_object.is_a?( Array )
637
- indexes.push( index )
467
+ self.each_with_index do |this_object, this_index|
468
+ if this_object.is_a?( ::Array )
469
+ indexes.push( this_index )
638
470
  end
639
471
  end
640
472
 
@@ -651,24 +483,6 @@ module ::Array::Hooked::ArrayInterface
651
483
 
652
484
  end
653
485
 
654
- ############################
655
- # flatten_without_hooks! #
656
- ############################
657
-
658
- # Alias to :flatten that bypasses hooks.
659
- # @return [Object] Self.
660
- def flatten_without_hooks!
661
-
662
- @without_hooks = true
663
-
664
- return_value = flatten!
665
-
666
- @without_hooks = false
667
-
668
- return return_value
669
-
670
- end
671
-
672
486
  #############
673
487
  # reject! #
674
488
  #############
@@ -697,25 +511,6 @@ module ::Array::Hooked::ArrayInterface
697
511
 
698
512
  end
699
513
 
700
- ###########################
701
- # reject_without_hooks! #
702
- ###########################
703
-
704
- # Alias to :reject that bypasses hooks.
705
- # @yield Block passed to :keep_if.
706
- # @return [Object] Self.
707
- def reject_without_hooks!( & block )
708
-
709
- @without_hooks = true
710
-
711
- reject!( & block )
712
-
713
- @without_hooks = false
714
-
715
- return return_value
716
-
717
- end
718
-
719
514
  #############
720
515
  # replace #
721
516
  #############
@@ -734,25 +529,6 @@ module ::Array::Hooked::ArrayInterface
734
529
 
735
530
  end
736
531
 
737
- ###########################
738
- # replace_without_hooks #
739
- ###########################
740
-
741
- # Alias to :replace that bypasses hooks.
742
- # @param [Array] other_array Other array to replace self with.
743
- # @return [Object] Self.
744
- def replace_without_hooks( other_array )
745
-
746
- @without_hooks = true
747
-
748
- replace( other_array )
749
-
750
- @without_hooks = false
751
-
752
- return self
753
-
754
- end
755
-
756
532
  ##############
757
533
  # reverse! #
758
534
  ##############
@@ -761,29 +537,7 @@ module ::Array::Hooked::ArrayInterface
761
537
 
762
538
  reversed_array = reverse
763
539
 
764
- clear
765
-
766
- reversed_array.each_with_index do |this_object, index|
767
- self[ index ] = this_object
768
- end
769
-
770
- return self
771
-
772
- end
773
-
774
- ############################
775
- # reverse_without_hooks! #
776
- ############################
777
-
778
- # Alias to :reverse that bypasses hooks.
779
- # @return [Object] Self.
780
- def reverse_without_hooks!
781
-
782
- @without_hooks = true
783
-
784
- reverse!
785
-
786
- @without_hooks = false
540
+ replace( reversed_array )
787
541
 
788
542
  return self
789
543
 
@@ -806,25 +560,6 @@ module ::Array::Hooked::ArrayInterface
806
560
  return self
807
561
 
808
562
  end
809
-
810
- ###########################
811
- # rotate_without_hooks! #
812
- ###########################
813
-
814
- # Alias to :rotate that bypasses hooks.
815
- # @param [Fixnum] rotate_count Integer count of how many elements to rotate.
816
- # @return [Object] Self.
817
- def rotate_without_hooks!( rotate_count = 1 )
818
-
819
- @without_hooks = true
820
-
821
- rotate!( rotate_count )
822
-
823
- @without_hooks = false
824
-
825
- return self
826
-
827
- end
828
563
 
829
564
  #############
830
565
  # select! #
@@ -836,8 +571,7 @@ module ::Array::Hooked::ArrayInterface
836
571
 
837
572
  deleted_objects = 0
838
573
 
839
- iteration_dup = dup
840
- iteration_dup.each_with_index do |this_object, index|
574
+ dup.each_with_index do |this_object, index|
841
575
  unless yield( this_object )
842
576
  delete_at( index - deleted_objects )
843
577
  deleted_objects += 1
@@ -848,25 +582,6 @@ module ::Array::Hooked::ArrayInterface
848
582
 
849
583
  end
850
584
 
851
- ###########################
852
- # select_without_hooks! #
853
- ###########################
854
-
855
- # Alias to :select that bypasses hooks.
856
- # @yield Block passed to :select!.
857
- # @return [Object] Self.
858
- def select_without_hooks!( & block )
859
-
860
- @without_hooks = true
861
-
862
- select!( & block )
863
-
864
- @without_hooks = false
865
-
866
- return self
867
-
868
- end
869
-
870
585
  ##############
871
586
  # shuffle! #
872
587
  ##############
@@ -884,25 +599,6 @@ module ::Array::Hooked::ArrayInterface
884
599
  return self
885
600
 
886
601
  end
887
-
888
- ############################
889
- # shuffle_without_hooks! #
890
- ############################
891
-
892
- # Alias to :shuffle that bypasses hooks.
893
- # @param [Object] random_number_generator Random number generator passed to :shuffle!.
894
- # @return [Object] Self.
895
- def shuffle_without_hooks!( random_number_generator = nil )
896
-
897
- @without_hooks = true
898
-
899
- shuffle!( random_number_generator )
900
-
901
- @without_hooks = false
902
-
903
- return self
904
-
905
- end
906
602
 
907
603
  ##############
908
604
  # collect! #
@@ -924,28 +620,6 @@ module ::Array::Hooked::ArrayInterface
924
620
 
925
621
  alias_method :map!, :collect!
926
622
 
927
- ############################
928
- # collect_without_hooks! #
929
- # map_without_hooks! #
930
- ############################
931
-
932
- # Alias to :select that bypasses hooks.
933
- # @yield Block passed to :collect!.
934
- # @return [Object] Self.
935
- def collect_without_hooks!( & block )
936
-
937
- @without_hooks = true
938
-
939
- collect!( & block )
940
-
941
- @without_hooks = false
942
-
943
- return self
944
-
945
- end
946
-
947
- alias_method :map_without_hooks!, :collect_without_hooks!
948
-
949
623
  ###########
950
624
  # sort! #
951
625
  ###########
@@ -964,25 +638,6 @@ module ::Array::Hooked::ArrayInterface
964
638
 
965
639
  end
966
640
 
967
- #########################
968
- # sort_without_hooks! #
969
- #########################
970
-
971
- # Alias to :sort that bypasses hooks.
972
- # @yield Block passed to :sort!.
973
- # @return [Object] Self.
974
- def sort_without_hooks!( & block )
975
-
976
- @without_hooks = true
977
-
978
- sort!
979
-
980
- @without_hooks = false
981
-
982
- return self
983
-
984
- end
985
-
986
641
  ##############
987
642
  # sort_by! #
988
643
  ##############
@@ -1003,25 +658,6 @@ module ::Array::Hooked::ArrayInterface
1003
658
 
1004
659
  end
1005
660
 
1006
- ############################
1007
- # sort_by_without_hooks! #
1008
- ############################
1009
-
1010
- # Alias to :sort_by! that bypasses hooks.
1011
- # @yield Block passed to :sort_by!.
1012
- # @return [Object] Self.
1013
- def sort_by_without_hooks!( & block )
1014
-
1015
- @without_hooks = true
1016
-
1017
- sort_by!( & block )
1018
-
1019
- @without_hooks = false
1020
-
1021
- return self
1022
-
1023
- end
1024
-
1025
661
  ###########
1026
662
  # uniq! #
1027
663
  ###########
@@ -1032,10 +668,10 @@ module ::Array::Hooked::ArrayInterface
1032
668
 
1033
669
  uniq_array = uniq
1034
670
 
1035
- unless uniq_array == self
671
+ unless self == uniq_array
1036
672
 
1037
673
  clear
1038
-
674
+
1039
675
  replace( uniq_array )
1040
676
 
1041
677
  end
@@ -1044,24 +680,6 @@ module ::Array::Hooked::ArrayInterface
1044
680
 
1045
681
  end
1046
682
 
1047
- #########################
1048
- # uniq_without_hooks! #
1049
- #########################
1050
-
1051
- # Alias to :uniq! that bypasses hooks.
1052
- # @return [Object] Self.
1053
- def uniq_without_hooks!
1054
-
1055
- @without_hooks = true
1056
-
1057
- return_value = uniq!
1058
-
1059
- @without_hooks = false
1060
-
1061
- return return_value
1062
-
1063
- end
1064
-
1065
683
  #############
1066
684
  # unshift #
1067
685
  #############
@@ -1074,25 +692,6 @@ module ::Array::Hooked::ArrayInterface
1074
692
 
1075
693
  end
1076
694
 
1077
- ###########################
1078
- # unshift_without_hooks #
1079
- ###########################
1080
-
1081
- # Alias to :unshift that bypasses hooks.
1082
- # @param [Object] object Object to unshift onto self.
1083
- # @return [Object] Self.
1084
- def unshift_without_hooks( object )
1085
-
1086
- @without_hooks = true
1087
-
1088
- unshift( object )
1089
-
1090
- @without_hooks = false
1091
-
1092
- return self
1093
-
1094
- end
1095
-
1096
695
  #########
1097
696
  # pop #
1098
697
  #########
@@ -1105,24 +704,6 @@ module ::Array::Hooked::ArrayInterface
1105
704
 
1106
705
  end
1107
706
 
1108
- #######################
1109
- # pop_without_hooks #
1110
- #######################
1111
-
1112
- # Alias to :pop that bypasses hooks.
1113
- # @return [Object] Self.
1114
- def pop_without_hooks
1115
-
1116
- @without_hooks = true
1117
-
1118
- object = pop
1119
-
1120
- @without_hooks = false
1121
-
1122
- return object
1123
-
1124
- end
1125
-
1126
707
  ###########
1127
708
  # shift #
1128
709
  ###########
@@ -1135,24 +716,6 @@ module ::Array::Hooked::ArrayInterface
1135
716
 
1136
717
  end
1137
718
 
1138
- #########################
1139
- # shift_without_hooks #
1140
- #########################
1141
-
1142
- # Alias to :shift that bypasses hooks.
1143
- # @return [Object] Self.
1144
- def shift_without_hooks
1145
-
1146
- @without_hooks = true
1147
-
1148
- object = shift
1149
-
1150
- @without_hooks = false
1151
-
1152
- return object
1153
-
1154
- end
1155
-
1156
719
  ############
1157
720
  # slice! #
1158
721
  ############
@@ -1196,60 +759,652 @@ module ::Array::Hooked::ArrayInterface
1196
759
  return slice
1197
760
 
1198
761
  end
762
+
763
+ ###########
764
+ # clear #
765
+ ###########
766
+
767
+ def clear
768
+
769
+ indexes = [ ]
770
+
771
+ count.times do |this_time|
772
+ indexes.push( count - this_time - 1 )
773
+ end
774
+
775
+ delete_at_indexes( *indexes )
776
+
777
+ return self
778
+
779
+ end
780
+
781
+ ################################################ Without Hooks #####################################################
782
+
783
+ #######################
784
+ # get_without_hooks #
785
+ #######################
786
+
787
+ # Alias to :[] that bypasses hooks.
788
+ # @param [Fixnum] index Index at which set is taking place.
789
+ # @return [Object] Element returned.
790
+ def get_without_hooks( index )
791
+
792
+ @without_hooks = true
793
+
794
+ self[ index ] = object
795
+
796
+ @without_hooks = false
797
+
798
+ return object
799
+
800
+ end
801
+
802
+ #######################
803
+ # set_without_hooks #
804
+ #######################
805
+
806
+ # Alias to :[]= that bypasses hooks.
807
+ # @param [Fixnum] index Index at which set is taking place.
808
+ # @param [Object] object Element being set.
809
+ # @return [Object] Element returned.
810
+ def set_without_hooks( index, object )
811
+
812
+ @without_hooks = true
813
+
814
+ self[ index ] = object
815
+
816
+ @without_hooks = false
817
+
818
+ return object
819
+
820
+ end
1199
821
 
1200
822
  ##########################
1201
- # slice_without_hooks! #
823
+ # insert_without_hooks #
1202
824
  ##########################
1203
825
 
1204
- # Alias to :slice! that bypasses hooks.
1205
- # @param [Fixnum] index_start_or_range Index at which to begin slice.
1206
- # @param [Fixnum] length Length of slice.
1207
- # @return [Object] Self.
1208
- def slice_without_hooks!( index_start_or_range, length = nil )
826
+ ###
827
+ # Alias to :insert that bypasses hooks.
828
+ #
829
+ # @param [Fixnum] index Index at which set is taking place.
830
+ #
831
+ # @param [Array<Object>] objects Elements being inserted.
832
+ #
833
+ # @return [Object] Element returned.
834
+ #
835
+ def insert_without_hooks( index, *objects )
1209
836
 
1210
837
  @without_hooks = true
1211
838
 
1212
- slice = slice!( index_start_or_range, length )
839
+ super( index, *objects )
840
+
841
+ @without_hooks = false
842
+
843
+ return objects
844
+
845
+ end
846
+
847
+ ########################
848
+ # push_without_hooks #
849
+ ########################
850
+
851
+ # Alias to :push that bypasses hooks.
852
+ # @param [Array<Object>] objects Elements being pushed.
853
+ # @return [Object] Element returned.
854
+ def push_without_hooks( *objects )
855
+
856
+ @without_hooks = true
857
+
858
+ push( *objects )
1213
859
 
1214
860
  @without_hooks = false
861
+
862
+ return objects
863
+
864
+ end
865
+
866
+ ##########################
867
+ # concat_without_hooks #
868
+ ##########################
869
+
870
+ # Alias to :concat that bypasses hooks.
871
+ # @param [Array<Object>] objects Elements being concatenated.
872
+ # @return [Object] Element returned.
873
+ def concat_without_hooks( *arrays )
874
+
875
+ @without_hooks = true
876
+
877
+ concat( *arrays )
1215
878
 
1216
- return slice
879
+ @without_hooks = false
880
+
881
+ return arrays
882
+
883
+ end
884
+
885
+ ##########################
886
+ # delete_without_hooks #
887
+ ##########################
888
+
889
+ # Alias to :delete that bypasses hooks.
890
+ # @param [Object] object Element being deleted.
891
+ # @return [Object] Element returned.
892
+ def delete_without_hooks( object )
893
+
894
+ @without_hooks = true
895
+
896
+ return_value = delete( object )
1217
897
 
898
+ @without_hooks = false
899
+
900
+ return return_value
901
+
1218
902
  end
1219
-
1220
- ###########
1221
- # clear #
1222
- ###########
1223
903
 
1224
- def clear
904
+ ##################################
905
+ # delete_objects_without_hooks #
906
+ ##################################
1225
907
 
1226
- indexes = [ ]
908
+ # Alias to :delete that bypasses hooks and takes multiple objects.
909
+ # @param [Array<Object>] objects Elements being deleted.
910
+ # @return [Object] Element returned.
911
+ def delete_objects_without_hooks( *objects )
1227
912
 
1228
- count.times do |this_time|
1229
- indexes.push( count - this_time - 1 )
1230
- end
913
+ @without_hooks = true
1231
914
 
1232
- delete_at_indexes( *indexes )
915
+ return_value = delete_objects( *objects )
916
+
917
+ @without_hooks = false
1233
918
 
1234
- return self
919
+ return return_value
1235
920
 
1236
921
  end
1237
922
 
1238
- #########################
1239
- # clear_without_hooks #
1240
- #########################
923
+ #############################
924
+ # delete_at_without_hooks #
925
+ #############################
1241
926
 
1242
- # Alias to :clear that bypasses hooks.
1243
- # @return [Object] Self.
1244
- def clear_without_hooks
927
+ # Alias to :delete_at that bypasses hooks.
928
+ # @param [Fixnum] index Index to delete.
929
+ # @return [Object] Deleted element.
930
+ def delete_at_without_hooks( index )
1245
931
 
1246
932
  @without_hooks = true
1247
933
 
1248
- clear
934
+ object = delete_at( index )
935
+
936
+ @without_hooks = false
937
+
938
+ return object
939
+
940
+ end
941
+
942
+ #####################################
943
+ # delete_at_indexes_without_hooks #
944
+ #####################################
945
+
946
+ # Alias to :delete_at that bypasses hooks and takes multiple indexes.
947
+ # @param [Array<Fixnum>] index Index to delete.
948
+ # @return [Object] Deleted element.
949
+ def delete_at_indexes_without_hooks( *indexes )
950
+
951
+ @without_hooks = true
952
+
953
+ objects = delete_at_indexes( *indexes )
1249
954
 
1250
955
  @without_hooks = false
956
+
957
+ return objects
1251
958
 
1252
- return self
959
+ end
960
+
961
+ #############################
962
+ # delete_if_without_hooks #
963
+ #############################
964
+
965
+ # Alias to :delete_if that bypasses hooks.
966
+ # @yield Block passed to :delete_if.
967
+ # @return [Object] Deleted element.
968
+ def delete_if_without_hooks( & block )
969
+
970
+ @without_hooks = true
971
+
972
+ delete_if( & block )
973
+
974
+ @without_hooks = false
975
+
976
+ return self
977
+
978
+ end
979
+
980
+ ###########################
981
+ # keep_if_without_hooks #
982
+ ###########################
983
+
984
+ # Alias to :keep_if that bypasses hooks.
985
+ # @yield Block passed to :keep_if.
986
+ # @return [Object] Deleted element.
987
+ def keep_if_without_hooks( & block )
988
+
989
+ @without_hooks = true
990
+
991
+ keep_if( & block )
992
+
993
+ @without_hooks = false
994
+
995
+ return self
996
+
997
+ end
998
+
999
+ ############################
1000
+ # compact_without_hooks! #
1001
+ ############################
1002
+
1003
+ # Alias to :compact that bypasses hooks.
1004
+ # @return [Object] Self.
1005
+ def compact_without_hooks!
1006
+
1007
+ @without_hooks = true
1008
+
1009
+ compact!
1010
+
1011
+ @without_hooks = false
1012
+
1013
+ return self
1014
+
1015
+ end
1016
+
1017
+ ############################
1018
+ # flatten_without_hooks! #
1019
+ ############################
1020
+
1021
+ # Alias to :flatten that bypasses hooks.
1022
+ # @return [Object] Self.
1023
+ def flatten_without_hooks!
1024
+
1025
+ @without_hooks = true
1026
+
1027
+ return_value = flatten!
1028
+
1029
+ @without_hooks = false
1030
+
1031
+ return return_value
1032
+
1033
+ end
1034
+
1035
+ ###########################
1036
+ # reject_without_hooks! #
1037
+ ###########################
1038
+
1039
+ # Alias to :reject that bypasses hooks.
1040
+ # @yield Block passed to :keep_if.
1041
+ # @return [Object] Self.
1042
+ def reject_without_hooks!( & block )
1043
+
1044
+ @without_hooks = true
1045
+
1046
+ reject!( & block )
1047
+
1048
+ @without_hooks = false
1049
+
1050
+ return return_value
1051
+
1052
+ end
1053
+
1054
+ ###########################
1055
+ # replace_without_hooks #
1056
+ ###########################
1057
+
1058
+ # Alias to :replace that bypasses hooks.
1059
+ # @param [Array] other_array Other array to replace self with.
1060
+ # @return [Object] Self.
1061
+ def replace_without_hooks( other_array )
1062
+
1063
+ @without_hooks = true
1064
+
1065
+ replace( other_array )
1066
+
1067
+ @without_hooks = false
1068
+
1069
+ return self
1070
+
1071
+ end
1072
+
1073
+ ############################
1074
+ # reverse_without_hooks! #
1075
+ ############################
1076
+
1077
+ # Alias to :reverse that bypasses hooks.
1078
+ # @return [Object] Self.
1079
+ def reverse_without_hooks!
1080
+
1081
+ @without_hooks = true
1082
+
1083
+ reverse!
1084
+
1085
+ @without_hooks = false
1086
+
1087
+ return self
1088
+
1089
+ end
1090
+
1091
+ ###########################
1092
+ # rotate_without_hooks! #
1093
+ ###########################
1094
+
1095
+ # Alias to :rotate that bypasses hooks.
1096
+ # @param [Fixnum] rotate_count Integer count of how many elements to rotate.
1097
+ # @return [Object] Self.
1098
+ def rotate_without_hooks!( rotate_count = 1 )
1099
+
1100
+ @without_hooks = true
1101
+
1102
+ rotate!( rotate_count )
1103
+
1104
+ @without_hooks = false
1105
+
1106
+ return self
1107
+
1108
+ end
1109
+
1110
+ ###########################
1111
+ # select_without_hooks! #
1112
+ ###########################
1113
+
1114
+ # Alias to :select that bypasses hooks.
1115
+ # @yield Block passed to :select!.
1116
+ # @return [Object] Self.
1117
+ def select_without_hooks!( & block )
1118
+
1119
+ @without_hooks = true
1120
+
1121
+ select!( & block )
1122
+
1123
+ @without_hooks = false
1124
+
1125
+ return self
1126
+
1127
+ end
1128
+
1129
+ ############################
1130
+ # shuffle_without_hooks! #
1131
+ ############################
1132
+
1133
+ # Alias to :shuffle that bypasses hooks.
1134
+ # @param [Object] random_number_generator Random number generator passed to :shuffle!.
1135
+ # @return [Object] Self.
1136
+ def shuffle_without_hooks!( random_number_generator = nil )
1137
+
1138
+ @without_hooks = true
1139
+
1140
+ shuffle!( random_number_generator )
1141
+
1142
+ @without_hooks = false
1143
+
1144
+ return self
1145
+
1146
+ end
1147
+
1148
+ ############################
1149
+ # collect_without_hooks! #
1150
+ # map_without_hooks! #
1151
+ ############################
1152
+
1153
+ # Alias to :select that bypasses hooks.
1154
+ # @yield Block passed to :collect!.
1155
+ # @return [Object] Self.
1156
+ def collect_without_hooks!( & block )
1157
+
1158
+ @without_hooks = true
1159
+
1160
+ collect!( & block )
1161
+
1162
+ @without_hooks = false
1163
+
1164
+ return self
1165
+
1166
+ end
1167
+
1168
+ alias_method :map_without_hooks!, :collect_without_hooks!
1169
+
1170
+ #########################
1171
+ # sort_without_hooks! #
1172
+ #########################
1173
+
1174
+ # Alias to :sort that bypasses hooks.
1175
+ # @yield Block passed to :sort!.
1176
+ # @return [Object] Self.
1177
+ def sort_without_hooks!( & block )
1178
+
1179
+ @without_hooks = true
1180
+
1181
+ sort!
1182
+
1183
+ @without_hooks = false
1184
+
1185
+ return self
1186
+
1187
+ end
1188
+
1189
+ ############################
1190
+ # sort_by_without_hooks! #
1191
+ ############################
1192
+
1193
+ # Alias to :sort_by! that bypasses hooks.
1194
+ # @yield Block passed to :sort_by!.
1195
+ # @return [Object] Self.
1196
+ def sort_by_without_hooks!( & block )
1197
+
1198
+ @without_hooks = true
1199
+
1200
+ sort_by!( & block )
1201
+
1202
+ @without_hooks = false
1203
+
1204
+ return self
1205
+
1206
+ end
1207
+
1208
+ #########################
1209
+ # uniq_without_hooks! #
1210
+ #########################
1211
+
1212
+ # Alias to :uniq! that bypasses hooks.
1213
+ # @return [Object] Self.
1214
+ def uniq_without_hooks!
1215
+
1216
+ @without_hooks = true
1217
+
1218
+ return_value = uniq!
1219
+
1220
+ @without_hooks = false
1221
+
1222
+ return return_value
1223
+
1224
+ end
1225
+
1226
+ ###########################
1227
+ # unshift_without_hooks #
1228
+ ###########################
1229
+
1230
+ # Alias to :unshift that bypasses hooks.
1231
+ # @param [Object] object Object to unshift onto self.
1232
+ # @return [Object] Self.
1233
+ def unshift_without_hooks( object )
1234
+
1235
+ @without_hooks = true
1236
+
1237
+ unshift( object )
1238
+
1239
+ @without_hooks = false
1240
+
1241
+ return self
1242
+
1243
+ end
1244
+
1245
+ #######################
1246
+ # pop_without_hooks #
1247
+ #######################
1248
+
1249
+ # Alias to :pop that bypasses hooks.
1250
+ # @return [Object] Self.
1251
+ def pop_without_hooks
1252
+
1253
+ @without_hooks = true
1254
+
1255
+ object = pop
1256
+
1257
+ @without_hooks = false
1258
+
1259
+ return object
1260
+
1261
+ end
1262
+
1263
+ #########################
1264
+ # shift_without_hooks #
1265
+ #########################
1266
+
1267
+ # Alias to :shift that bypasses hooks.
1268
+ # @return [Object] Self.
1269
+ def shift_without_hooks
1270
+
1271
+ @without_hooks = true
1272
+
1273
+ object = shift
1274
+
1275
+ @without_hooks = false
1276
+
1277
+ return object
1278
+
1279
+ end
1280
+
1281
+ ##########################
1282
+ # slice_without_hooks! #
1283
+ ##########################
1284
+
1285
+ # Alias to :slice! that bypasses hooks.
1286
+ # @param [Fixnum] index_start_or_range Index at which to begin slice.
1287
+ # @param [Fixnum] length Length of slice.
1288
+ # @return [Object] Self.
1289
+ def slice_without_hooks!( index_start_or_range, length = nil )
1290
+
1291
+ @without_hooks = true
1292
+
1293
+ slice = slice!( index_start_or_range, length )
1294
+
1295
+ @without_hooks = false
1296
+
1297
+ return slice
1298
+
1299
+ end
1300
+
1301
+ #########################
1302
+ # clear_without_hooks #
1303
+ #########################
1304
+
1305
+ # Alias to :clear that bypasses hooks.
1306
+ # @return [Object] Self.
1307
+ def clear_without_hooks
1308
+
1309
+ @without_hooks = true
1310
+
1311
+ clear
1312
+
1313
+ @without_hooks = false
1314
+
1315
+ return self
1316
+
1317
+ end
1318
+
1319
+ ######################################################################################################################
1320
+ private ##########################################################################################################
1321
+ ######################################################################################################################
1322
+
1323
+ ###########################
1324
+ # filter_insert_objects #
1325
+ ###########################
1326
+
1327
+ def filter_insert_objects( index, objects )
1328
+
1329
+ # if we have less elements in self than the index we are inserting at
1330
+ # we need to make sure the nils inserted cascade
1331
+ if index > count
1332
+ nils_created = index - count
1333
+ index -= nils_created
1334
+ nils_created.times do |this_time|
1335
+ objects.unshift( nil )
1336
+ end
1337
+ end
1338
+
1339
+ return index
1340
+
1341
+ end
1342
+
1343
+ ###############################
1344
+ # perform_get_between_hooks #
1345
+ ###############################
1346
+
1347
+ def perform_get_between_hooks( index, *objects )
1348
+
1349
+ return undecorated_get( index, *objects )
1350
+
1351
+ end
1352
+
1353
+ ###############################
1354
+ # perform_set_between_hooks #
1355
+ ###############################
1356
+
1357
+ def perform_set_between_hooks( index, object )
1358
+
1359
+ undecorated_set( index, object )
1360
+
1361
+ return true
1362
+
1363
+ end
1364
+
1365
+ ##################################
1366
+ # perform_insert_between_hooks #
1367
+ ##################################
1368
+
1369
+ def perform_insert_between_hooks( index, *objects )
1370
+
1371
+ first_index = index
1372
+
1373
+ current_index = index
1374
+
1375
+ objects.each do |this_object|
1376
+ # if we get nil back thats an insert did not happen
1377
+ if index = perform_single_object_insert_between_hooks( index, this_object )
1378
+ index += 1
1379
+ current_index = index
1380
+ else
1381
+ index = current_index
1382
+ end
1383
+ end
1384
+
1385
+ return first_index
1386
+
1387
+ end
1388
+
1389
+ ################################################
1390
+ # perform_single_object_insert_between_hooks #
1391
+ ################################################
1392
+
1393
+ def perform_single_object_insert_between_hooks( index, object )
1394
+
1395
+ undecorated_insert( index, object )
1396
+
1397
+ return index
1398
+
1399
+ end
1400
+
1401
+ #####################################
1402
+ # perform_delete_at_between_hooks #
1403
+ #####################################
1404
+
1405
+ def perform_delete_at_between_hooks( index, *objects )
1406
+
1407
+ return undecorated_delete_at( index )
1253
1408
 
1254
1409
  end
1255
1410