cascading-configuration-array 2.0.3 → 2.1.0
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.
- data/README.md +1 -1
- data/README.rdoc +1 -1
- data/lib/cascading-configuration-array.rb +2 -10
- data/lib/cascading-configuration-array/CascadingConfiguration/Array.rb +45 -4
- data/spec/CascadingConfiguration/Array_spec.rb +25 -0
- metadata +5 -9
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/Interface.rb +0 -111
- data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb +0 -865
- data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/ModuleSupportMethods.rb +0 -44
- data/spec/_private_/CascadingConfiguration/Array/CompositingArray_spec.rb +0 -1020
data/README.md
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
|
2
|
+
require 'compositing-array'
|
3
|
+
|
2
4
|
if $__cascading_configuration__spec__development
|
3
5
|
require_relative '../../variable/lib/cascading-configuration-variable.rb'
|
4
6
|
else
|
@@ -7,19 +9,9 @@ end
|
|
7
9
|
|
8
10
|
module ::CascadingConfiguration
|
9
11
|
module Array
|
10
|
-
class CompositingArray < ::Array
|
11
|
-
end
|
12
|
-
module ModuleSupportMethods
|
13
|
-
end
|
14
|
-
module Interface
|
15
|
-
end
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
require_relative 'cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb'
|
20
|
-
require_relative 'cascading-configuration-array/_private_/CascadingConfiguration/Array/ModuleSupportMethods.rb'
|
21
|
-
|
22
|
-
require_relative 'cascading-configuration-array/CascadingConfiguration/Array/Interface.rb'
|
23
15
|
require_relative 'cascading-configuration-array/CascadingConfiguration/Array.rb'
|
24
16
|
|
25
17
|
|
@@ -2,11 +2,52 @@
|
|
2
2
|
module ::CascadingConfiguration::Array
|
3
3
|
|
4
4
|
# Configuration modules for storage of settings arrays
|
5
|
-
include ::CascadingConfiguration::
|
5
|
+
include ::CascadingConfiguration::Inheritance
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
#######################################
|
8
|
+
# attr_configuration_array #
|
9
|
+
# attr_module_configuration_array #
|
10
|
+
# attr_local_configuration_array #
|
11
|
+
# attr_object_configuration_array #
|
12
|
+
# attr_instance_configuration_array #
|
13
|
+
#######################################
|
9
14
|
|
10
|
-
|
15
|
+
def attr_configuration_array( *configuration_names, & define_block ) ;; end
|
16
|
+
def attr_module_configuration_array( *configuration_names, & define_block ) ;; end
|
17
|
+
def attr_class_configuration_array( *configuration_names, & define_block ) ;; end
|
18
|
+
def attr_local_configuration_array( *configuration_names, & define_block ) ;; end
|
19
|
+
def attr_object_configuration_array( *configuration_names, & define_block ) ;; end
|
20
|
+
def attr_instance_configuration_array( *configuration_names, & define_block ) ;; end
|
21
|
+
|
22
|
+
cca = self
|
23
|
+
ccv = ::CascadingConfiguration::Variable
|
24
|
+
ccm = ::CascadingConfiguration::Methods
|
25
|
+
|
26
|
+
setter_proc = ::Proc.new do |instance, configuration_name, value|
|
27
|
+
|
28
|
+
return instance.__send__( configuration_name ).replace( value )
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
getter_proc = ::Proc.new do |instance, configuration_name|
|
33
|
+
|
34
|
+
composite_array = nil
|
35
|
+
|
36
|
+
if ccv.has_configuration_variable?( instance, configuration_name )
|
37
|
+
composite_array = ccv.get_configuration_variable( instance, configuration_name )
|
38
|
+
else
|
39
|
+
parent_composite_array = nil
|
40
|
+
if ancestor = ::CascadingConfiguration::Variable.ancestor( instance, configuration_name )
|
41
|
+
parent_composite_array = ancestor.__send__( configuration_name )
|
42
|
+
end
|
43
|
+
composite_array = ::CompositingArray.new( parent_composite_array )
|
44
|
+
ccv.set_configuration_variable( instance, configuration_name, composite_array )
|
45
|
+
end
|
46
|
+
|
47
|
+
return composite_array
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
ccm.declare_compositing_configuration_object( self, :array, setter_proc, getter_proc )
|
11
52
|
|
12
53
|
end
|
@@ -744,5 +744,30 @@ describe CascadingConfiguration::Array do
|
|
744
744
|
end
|
745
745
|
|
746
746
|
end
|
747
|
+
|
748
|
+
#########################################
|
749
|
+
# attr_configuration_array with hooks #
|
750
|
+
#########################################
|
751
|
+
|
752
|
+
it 'can define a configuration array with hooks' do
|
753
|
+
module ::CascadingConfiguration::Array::HooksMock
|
754
|
+
include ::CascadingConfiguration::Array
|
755
|
+
module ExtensionModule
|
756
|
+
def push( arg )
|
757
|
+
super( 2 )
|
758
|
+
end
|
759
|
+
end
|
760
|
+
attr_configuration_array :configuration_setting, ExtensionModule
|
761
|
+
configuration_setting.push( 1 )
|
762
|
+
configuration_setting[ 0 ].should == 2
|
763
|
+
attr_configuration_array :other_configuration_setting do
|
764
|
+
def push( arg )
|
765
|
+
super( 2 )
|
766
|
+
end
|
767
|
+
end
|
768
|
+
other_configuration_setting.push( 1 )
|
769
|
+
other_configuration_setting[ 0 ].should == 2
|
770
|
+
end
|
771
|
+
end
|
747
772
|
|
748
773
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cascading-configuration-array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
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-03-
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cascading-configuration-variable
|
16
|
-
requirement: &
|
16
|
+
requirement: &70132135355540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,19 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70132135355540
|
25
25
|
description: Provides :attr_configuration_array.
|
26
26
|
email: asher@ridiculouspower.com
|
27
27
|
executables: []
|
28
28
|
extensions: []
|
29
29
|
extra_rdoc_files: []
|
30
30
|
files:
|
31
|
-
- lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb
|
32
|
-
- lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/ModuleSupportMethods.rb
|
33
|
-
- lib/cascading-configuration-array/CascadingConfiguration/Array/Interface.rb
|
34
31
|
- lib/cascading-configuration-array/CascadingConfiguration/Array.rb
|
35
32
|
- lib/cascading-configuration-array.rb
|
36
|
-
- spec/_private_/CascadingConfiguration/Array/CompositingArray_spec.rb
|
37
33
|
- spec/CascadingConfiguration/Array_spec.rb
|
38
34
|
- README.md
|
39
35
|
- README.rdoc
|
@@ -57,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
53
|
version: '0'
|
58
54
|
requirements: []
|
59
55
|
rubyforge_project: cascading-configuration-array
|
60
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.11
|
61
57
|
signing_key:
|
62
58
|
specification_version: 3
|
63
59
|
summary: Support package for cascading-configuration.
|
@@ -1,111 +0,0 @@
|
|
1
|
-
|
2
|
-
module ::CascadingConfiguration::Array::Interface
|
3
|
-
|
4
|
-
######################
|
5
|
-
# self.setter_proc #
|
6
|
-
######################
|
7
|
-
|
8
|
-
def self.setter_proc( configuration_name )
|
9
|
-
|
10
|
-
return Proc.new do |array|
|
11
|
-
|
12
|
-
return ::CascadingConfiguration::Array.set_composite_array( self,
|
13
|
-
configuration_name,
|
14
|
-
array )
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
######################
|
21
|
-
# self.getter_proc #
|
22
|
-
######################
|
23
|
-
|
24
|
-
def self.getter_proc( configuration_name )
|
25
|
-
|
26
|
-
return Proc.new do
|
27
|
-
|
28
|
-
return ::CascadingConfiguration::Array.composite_array( self,
|
29
|
-
configuration_name )
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
##############################
|
36
|
-
# attr_configuration_array #
|
37
|
-
##############################
|
38
|
-
|
39
|
-
# defines configuration in class or module
|
40
|
-
# configuration cascades downward to instance including all classes or modules in-between
|
41
|
-
def attr_configuration_array( *configuration_names )
|
42
|
-
|
43
|
-
return ::CascadingConfiguration::Variable.
|
44
|
-
define_cascading_configuration( self,
|
45
|
-
::CascadingConfiguration::Array::Interface,
|
46
|
-
*configuration_names )
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
#####################################
|
51
|
-
# attr_module_configuration_array #
|
52
|
-
#####################################
|
53
|
-
|
54
|
-
# defines configuration in class or module
|
55
|
-
# configuration cascades downward to last class or module
|
56
|
-
def attr_module_configuration_array( *configuration_names )
|
57
|
-
|
58
|
-
return ::CascadingConfiguration::Variable.
|
59
|
-
define_module_configuration( self,
|
60
|
-
::CascadingConfiguration::Array::Interface,
|
61
|
-
*configuration_names )
|
62
|
-
|
63
|
-
end
|
64
|
-
alias_method :attr_class_configuration_array, :attr_module_configuration_array
|
65
|
-
|
66
|
-
####################################
|
67
|
-
# attr_local_configuration_array #
|
68
|
-
####################################
|
69
|
-
|
70
|
-
# defines configuration in present class or module context
|
71
|
-
# configuration does not cascade
|
72
|
-
def attr_local_configuration_array( *configuration_names )
|
73
|
-
|
74
|
-
return ::CascadingConfiguration::Variable.
|
75
|
-
define_local_configuration( self,
|
76
|
-
::CascadingConfiguration::Array::Interface,
|
77
|
-
*configuration_names )
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
#####################################
|
82
|
-
# attr_object_configuration_array #
|
83
|
-
#####################################
|
84
|
-
|
85
|
-
# defines configuration in present instance
|
86
|
-
# configuration does not cascade
|
87
|
-
def attr_object_configuration_array( *configuration_names )
|
88
|
-
|
89
|
-
return ::CascadingConfiguration::Variable.
|
90
|
-
define_object_configuration( self,
|
91
|
-
::CascadingConfiguration::Array::Interface,
|
92
|
-
*configuration_names )
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
#######################################
|
97
|
-
# attr_instance_configuration_array #
|
98
|
-
#######################################
|
99
|
-
|
100
|
-
# defines configuration in present class or module context
|
101
|
-
# configuration does not cascade
|
102
|
-
def attr_instance_configuration_array( *configuration_names )
|
103
|
-
|
104
|
-
return ::CascadingConfiguration::Variable.
|
105
|
-
define_instance_configuration( self,
|
106
|
-
::CascadingConfiguration::Array::Interface,
|
107
|
-
*configuration_names )
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb
DELETED
@@ -1,865 +0,0 @@
|
|
1
|
-
|
2
|
-
class ::CascadingConfiguration::Array::CompositingArray < ::Array
|
3
|
-
|
4
|
-
################
|
5
|
-
# initialize #
|
6
|
-
################
|
7
|
-
|
8
|
-
def initialize( configuration_instance, configuration_name )
|
9
|
-
|
10
|
-
@configuration_instance = configuration_instance
|
11
|
-
@configuration_name = configuration_name
|
12
|
-
|
13
|
-
# hash tracking index in self corresponding to index in parent
|
14
|
-
# this is since objects can be inserted before/between parent objects
|
15
|
-
@local_index_for_parent_index = { }
|
16
|
-
|
17
|
-
# we keep track of how many objects are interpolated between parent objects
|
18
|
-
# plus number of parent objects
|
19
|
-
@parent_and_interpolated_object_count = 0
|
20
|
-
@replaced_parents = {}
|
21
|
-
|
22
|
-
# arrays that inherit from us
|
23
|
-
@sub_composite_arrays = [ ]
|
24
|
-
|
25
|
-
# store self for sub composites
|
26
|
-
::CascadingConfiguration::Variable.set_configuration_variable( configuration_instance,
|
27
|
-
configuration_name,
|
28
|
-
self )
|
29
|
-
|
30
|
-
# if first ancestor can have a composite array, register self with it
|
31
|
-
# in case it gets updated in the future
|
32
|
-
if ancestor = ::CascadingConfiguration::Variable.ancestor( configuration_instance,
|
33
|
-
configuration_name )
|
34
|
-
|
35
|
-
@super_composite_array = ::CascadingConfiguration::Variable.
|
36
|
-
get_configuration_variable( ancestor, configuration_name )
|
37
|
-
|
38
|
-
if @super_composite_array.respond_to?( :register_sub_composite_array )
|
39
|
-
|
40
|
-
@super_composite_array.register_sub_composite_array( self )
|
41
|
-
|
42
|
-
push( *@super_composite_array )
|
43
|
-
|
44
|
-
@super_composite_array.count.times do |this_time|
|
45
|
-
@local_index_for_parent_index[ this_time ] = this_time
|
46
|
-
end
|
47
|
-
|
48
|
-
# since we have a super array we have to note how many objects it has before we insert any
|
49
|
-
@parent_and_interpolated_object_count = @super_composite_array.count
|
50
|
-
|
51
|
-
else
|
52
|
-
|
53
|
-
@super_composite_array = nil
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
################################### Sub-Array Management #######################################
|
62
|
-
|
63
|
-
##################################
|
64
|
-
# register_sub_composite_array #
|
65
|
-
##################################
|
66
|
-
|
67
|
-
def register_sub_composite_array( sub_composite_array )
|
68
|
-
|
69
|
-
@sub_composite_arrays.push( sub_composite_array )
|
70
|
-
|
71
|
-
return self
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
####################################
|
76
|
-
# unregister_sub_composite_array #
|
77
|
-
####################################
|
78
|
-
|
79
|
-
def unregister_sub_composite_array( sub_composite_array )
|
80
|
-
|
81
|
-
@sub_composite_arrays.delete( sub_composite_array )
|
82
|
-
|
83
|
-
return self
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
##################################### Self Management ##########################################
|
88
|
-
|
89
|
-
#########
|
90
|
-
# []= #
|
91
|
-
#########
|
92
|
-
|
93
|
-
private
|
94
|
-
alias_method :non_cascading_set, :[]=
|
95
|
-
public
|
96
|
-
|
97
|
-
def []=( index, object )
|
98
|
-
|
99
|
-
# we are either replacing or adding at the end
|
100
|
-
# if we are replacing we are either replacing a parent element or an element in self
|
101
|
-
# * if replacing parent element, track and exclude parent changes
|
102
|
-
|
103
|
-
non_cascading_set( index, object )
|
104
|
-
|
105
|
-
if index_inside_parent_objects?( index )
|
106
|
-
@replaced_parents[ index ] = true
|
107
|
-
end
|
108
|
-
|
109
|
-
@sub_composite_arrays.each do |this_sub_array|
|
110
|
-
this_sub_array.instance_eval do
|
111
|
-
update_as_sub_array_for_parent_set( index, object )
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
return object
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
############
|
120
|
-
# insert #
|
121
|
-
############
|
122
|
-
|
123
|
-
private
|
124
|
-
alias_method :non_cascading_insert, :insert
|
125
|
-
public
|
126
|
-
|
127
|
-
def insert( index, *objects )
|
128
|
-
|
129
|
-
# if we have less elements in self than the index we are inserting at
|
130
|
-
# we need to make sure the nils inserted cascade
|
131
|
-
if index > count
|
132
|
-
nils_created = index - count
|
133
|
-
index -= nils_created
|
134
|
-
nils = [ ]
|
135
|
-
nils_created.times do |this_time|
|
136
|
-
nils.push( nil )
|
137
|
-
end
|
138
|
-
objects = nils.concat( objects )
|
139
|
-
end
|
140
|
-
|
141
|
-
non_cascading_insert( index, *objects )
|
142
|
-
|
143
|
-
if index_inside_parent_objects?( index )
|
144
|
-
update_corresponding_index_for_local_change( index, objects.count )
|
145
|
-
end
|
146
|
-
|
147
|
-
@sub_composite_arrays.each do |this_sub_array|
|
148
|
-
this_sub_array.instance_eval do
|
149
|
-
update_as_sub_array_for_parent_insert( index, *objects )
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
return self
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
##########
|
158
|
-
# push #
|
159
|
-
##########
|
160
|
-
|
161
|
-
def push( *objects )
|
162
|
-
|
163
|
-
insert( count, *objects )
|
164
|
-
|
165
|
-
return self
|
166
|
-
|
167
|
-
end
|
168
|
-
alias_method :<<, :push
|
169
|
-
|
170
|
-
############
|
171
|
-
# concat #
|
172
|
-
############
|
173
|
-
|
174
|
-
def concat( *arrays )
|
175
|
-
|
176
|
-
arrays.each do |this_array|
|
177
|
-
push( *this_array )
|
178
|
-
end
|
179
|
-
|
180
|
-
return self
|
181
|
-
|
182
|
-
end
|
183
|
-
alias_method :+, :concat
|
184
|
-
|
185
|
-
############
|
186
|
-
# delete #
|
187
|
-
############
|
188
|
-
|
189
|
-
def delete( object )
|
190
|
-
|
191
|
-
return_value = nil
|
192
|
-
|
193
|
-
if index = index( object )
|
194
|
-
return_value = delete_at( index )
|
195
|
-
end
|
196
|
-
|
197
|
-
return return_value
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
####################
|
202
|
-
# delete_objects #
|
203
|
-
####################
|
204
|
-
|
205
|
-
def delete_objects( *objects )
|
206
|
-
|
207
|
-
return_value = nil
|
208
|
-
|
209
|
-
indexes = [ ]
|
210
|
-
objects.each do |this_object|
|
211
|
-
this_index = index( this_object )
|
212
|
-
if this_index
|
213
|
-
indexes.push( this_index )
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
unless indexes.empty?
|
218
|
-
return_value = delete_at_indexes( *indexes )
|
219
|
-
end
|
220
|
-
|
221
|
-
return return_value
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
#######
|
226
|
-
# - #
|
227
|
-
#######
|
228
|
-
|
229
|
-
def -( *arrays )
|
230
|
-
|
231
|
-
arrays.each do |this_array|
|
232
|
-
delete_objects( *this_array )
|
233
|
-
end
|
234
|
-
|
235
|
-
return self
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
###############
|
240
|
-
# delete_at #
|
241
|
-
###############
|
242
|
-
|
243
|
-
private
|
244
|
-
alias_method :non_cascading_delete_at, :delete_at
|
245
|
-
public
|
246
|
-
|
247
|
-
def delete_at( index )
|
248
|
-
|
249
|
-
deleted_object = non_cascading_delete_at( index )
|
250
|
-
|
251
|
-
@replaced_parents.delete( index )
|
252
|
-
|
253
|
-
if index_inside_parent_objects?( index )
|
254
|
-
update_corresponding_index_for_local_change( index, -1 )
|
255
|
-
end
|
256
|
-
|
257
|
-
@sub_composite_arrays.each do |this_sub_array|
|
258
|
-
this_sub_array.instance_eval do
|
259
|
-
update_as_sub_array_for_parent_delete( index )
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
return deleted_object
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
#######################
|
268
|
-
# delete_at_indexes #
|
269
|
-
#######################
|
270
|
-
|
271
|
-
def delete_at_indexes( *indexes )
|
272
|
-
|
273
|
-
indexes = indexes.sort.uniq.reverse
|
274
|
-
|
275
|
-
objects = [ ]
|
276
|
-
|
277
|
-
indexes.each do |this_index|
|
278
|
-
objects.push( delete_at( this_index ) )
|
279
|
-
end
|
280
|
-
|
281
|
-
return objects
|
282
|
-
|
283
|
-
end
|
284
|
-
|
285
|
-
###############
|
286
|
-
# delete_if #
|
287
|
-
###############
|
288
|
-
|
289
|
-
def delete_if
|
290
|
-
|
291
|
-
return to_enum unless block_given?
|
292
|
-
|
293
|
-
indexes = [ ]
|
294
|
-
|
295
|
-
self.each_with_index do |this_object, index|
|
296
|
-
if yield( this_object )
|
297
|
-
indexes.push( index )
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
delete_at_indexes( *indexes )
|
302
|
-
|
303
|
-
return self
|
304
|
-
|
305
|
-
end
|
306
|
-
|
307
|
-
#############
|
308
|
-
# keep_if #
|
309
|
-
#############
|
310
|
-
|
311
|
-
def keep_if
|
312
|
-
|
313
|
-
indexes = [ ]
|
314
|
-
|
315
|
-
self.each_with_index do |this_object, index|
|
316
|
-
unless yield( this_object )
|
317
|
-
indexes.push( index )
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
delete_at_indexes( *indexes )
|
322
|
-
|
323
|
-
return self
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
-
##############
|
328
|
-
# compact! #
|
329
|
-
##############
|
330
|
-
|
331
|
-
def compact!
|
332
|
-
|
333
|
-
return keep_if do |object|
|
334
|
-
object != nil
|
335
|
-
end
|
336
|
-
|
337
|
-
end
|
338
|
-
|
339
|
-
##############
|
340
|
-
# flatten! #
|
341
|
-
##############
|
342
|
-
|
343
|
-
def flatten!
|
344
|
-
|
345
|
-
return_value = nil
|
346
|
-
|
347
|
-
indexes = [ ]
|
348
|
-
|
349
|
-
self.each_with_index do |this_object, index|
|
350
|
-
if this_object.is_a?( Array )
|
351
|
-
indexes.push( index )
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
unless indexes.empty?
|
356
|
-
indexes.sort!.reverse!
|
357
|
-
indexes.each do |this_index|
|
358
|
-
this_array = delete_at( this_index )
|
359
|
-
insert( this_index, *this_array )
|
360
|
-
end
|
361
|
-
return_value = self
|
362
|
-
end
|
363
|
-
|
364
|
-
return return_value
|
365
|
-
|
366
|
-
end
|
367
|
-
|
368
|
-
#############
|
369
|
-
# reject! #
|
370
|
-
#############
|
371
|
-
|
372
|
-
def reject!
|
373
|
-
|
374
|
-
return to_enum unless block_given?
|
375
|
-
|
376
|
-
return_value = nil
|
377
|
-
|
378
|
-
deleted_objects = 0
|
379
|
-
|
380
|
-
iteration_dup = dup
|
381
|
-
iteration_dup.each_with_index do |this_object, index|
|
382
|
-
if yield( this_object )
|
383
|
-
delete_at( index - deleted_objects )
|
384
|
-
deleted_objects += 1
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
if deleted_objects > 0
|
389
|
-
return_value = self
|
390
|
-
end
|
391
|
-
|
392
|
-
return return_value
|
393
|
-
|
394
|
-
end
|
395
|
-
|
396
|
-
#############
|
397
|
-
# replace #
|
398
|
-
#############
|
399
|
-
|
400
|
-
def replace( other_array )
|
401
|
-
|
402
|
-
clear
|
403
|
-
|
404
|
-
other_array.each_with_index do |this_object, index|
|
405
|
-
unless self[ index ] == this_object
|
406
|
-
self[ index ] = this_object
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
return self
|
411
|
-
|
412
|
-
end
|
413
|
-
|
414
|
-
##############
|
415
|
-
# reverse! #
|
416
|
-
##############
|
417
|
-
|
418
|
-
def reverse!
|
419
|
-
|
420
|
-
reversed_array = reverse
|
421
|
-
|
422
|
-
clear
|
423
|
-
|
424
|
-
reversed_array.each_with_index do |this_object, index|
|
425
|
-
self[ index ] = this_object
|
426
|
-
end
|
427
|
-
|
428
|
-
return self
|
429
|
-
|
430
|
-
end
|
431
|
-
|
432
|
-
#############
|
433
|
-
# rotate! #
|
434
|
-
#############
|
435
|
-
|
436
|
-
def rotate!( rotate_count = 1 )
|
437
|
-
|
438
|
-
reversed_array = rotate( rotate_count )
|
439
|
-
|
440
|
-
clear
|
441
|
-
|
442
|
-
reversed_array.each_with_index do |this_object, index|
|
443
|
-
self[ index ] = this_object
|
444
|
-
end
|
445
|
-
|
446
|
-
return self
|
447
|
-
|
448
|
-
end
|
449
|
-
|
450
|
-
#############
|
451
|
-
# select! #
|
452
|
-
#############
|
453
|
-
|
454
|
-
def select!
|
455
|
-
|
456
|
-
return to_enum unless block_given?
|
457
|
-
|
458
|
-
deleted_objects = 0
|
459
|
-
|
460
|
-
iteration_dup = dup
|
461
|
-
iteration_dup.each_with_index do |this_object, index|
|
462
|
-
unless yield( this_object )
|
463
|
-
delete_at( index - deleted_objects )
|
464
|
-
deleted_objects += 1
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
return self
|
469
|
-
|
470
|
-
end
|
471
|
-
|
472
|
-
##############
|
473
|
-
# shuffle! #
|
474
|
-
##############
|
475
|
-
|
476
|
-
def shuffle!( random_number_generator = nil )
|
477
|
-
|
478
|
-
shuffled_array = shuffle( random: random_number_generator )
|
479
|
-
|
480
|
-
clear
|
481
|
-
|
482
|
-
shuffled_array.each_with_index do |this_object, index|
|
483
|
-
self[ index ] = this_object
|
484
|
-
end
|
485
|
-
|
486
|
-
return self
|
487
|
-
|
488
|
-
end
|
489
|
-
|
490
|
-
##############
|
491
|
-
# collect! #
|
492
|
-
# map! #
|
493
|
-
##############
|
494
|
-
|
495
|
-
def collect!
|
496
|
-
|
497
|
-
return to_enum unless block_given?
|
498
|
-
|
499
|
-
self.each_with_index do |this_object, index|
|
500
|
-
replacement_object = yield( this_object )
|
501
|
-
self[ index ] = replacement_object
|
502
|
-
end
|
503
|
-
|
504
|
-
return self
|
505
|
-
|
506
|
-
end
|
507
|
-
alias_method :map!, :collect!
|
508
|
-
|
509
|
-
###########
|
510
|
-
# sort! #
|
511
|
-
###########
|
512
|
-
|
513
|
-
def sort!( & block )
|
514
|
-
|
515
|
-
sorted_array = sort( & block )
|
516
|
-
|
517
|
-
unless sorted_array == self
|
518
|
-
|
519
|
-
replace( sorted_array )
|
520
|
-
|
521
|
-
end
|
522
|
-
|
523
|
-
return self
|
524
|
-
|
525
|
-
end
|
526
|
-
|
527
|
-
##############
|
528
|
-
# sort_by! #
|
529
|
-
##############
|
530
|
-
|
531
|
-
def sort_by!( & block )
|
532
|
-
|
533
|
-
return to_enum unless block_given?
|
534
|
-
|
535
|
-
sorted_array = sort_by( & block )
|
536
|
-
|
537
|
-
unless sorted_array == self
|
538
|
-
|
539
|
-
replace( sorted_array )
|
540
|
-
|
541
|
-
end
|
542
|
-
|
543
|
-
return self
|
544
|
-
|
545
|
-
end
|
546
|
-
|
547
|
-
###########
|
548
|
-
# uniq! #
|
549
|
-
###########
|
550
|
-
|
551
|
-
def uniq!
|
552
|
-
|
553
|
-
return_value = nil
|
554
|
-
|
555
|
-
uniq_array = uniq
|
556
|
-
|
557
|
-
unless uniq_array == self
|
558
|
-
|
559
|
-
clear
|
560
|
-
|
561
|
-
replace( uniq_array )
|
562
|
-
|
563
|
-
end
|
564
|
-
|
565
|
-
return return_value
|
566
|
-
|
567
|
-
end
|
568
|
-
|
569
|
-
#############
|
570
|
-
# unshift #
|
571
|
-
#############
|
572
|
-
|
573
|
-
def unshift( object )
|
574
|
-
|
575
|
-
insert( 0, object )
|
576
|
-
|
577
|
-
end
|
578
|
-
|
579
|
-
#########
|
580
|
-
# pop #
|
581
|
-
#########
|
582
|
-
|
583
|
-
def pop
|
584
|
-
|
585
|
-
object = delete_at( count - 1 )
|
586
|
-
|
587
|
-
return object
|
588
|
-
|
589
|
-
end
|
590
|
-
|
591
|
-
###########
|
592
|
-
# shift #
|
593
|
-
###########
|
594
|
-
|
595
|
-
def shift
|
596
|
-
|
597
|
-
object = delete_at( 0 )
|
598
|
-
|
599
|
-
return object
|
600
|
-
|
601
|
-
end
|
602
|
-
|
603
|
-
############
|
604
|
-
# slice! #
|
605
|
-
############
|
606
|
-
|
607
|
-
def slice!( index_start_or_range, length = nil )
|
608
|
-
|
609
|
-
slice = nil
|
610
|
-
|
611
|
-
start_index = nil
|
612
|
-
end_index = nil
|
613
|
-
|
614
|
-
if index_start_or_range.is_a?( Range )
|
615
|
-
|
616
|
-
start_index = index_start_or_range.begin
|
617
|
-
end_index = index_start_or_range.end
|
618
|
-
|
619
|
-
elsif length
|
620
|
-
|
621
|
-
start_index = index_start_or_range
|
622
|
-
end_index = index_start_or_range + length
|
623
|
-
|
624
|
-
end
|
625
|
-
|
626
|
-
if end_index
|
627
|
-
|
628
|
-
indexes = [ ]
|
629
|
-
|
630
|
-
( end_index - start_index ).times do |this_time|
|
631
|
-
indexes.push( end_index - this_time - 1 )
|
632
|
-
end
|
633
|
-
|
634
|
-
slice = delete_at_indexes( *indexes )
|
635
|
-
|
636
|
-
else
|
637
|
-
|
638
|
-
slice = delete_at( start_index )
|
639
|
-
|
640
|
-
end
|
641
|
-
|
642
|
-
|
643
|
-
return slice
|
644
|
-
|
645
|
-
end
|
646
|
-
|
647
|
-
###########
|
648
|
-
# clear #
|
649
|
-
###########
|
650
|
-
|
651
|
-
def clear
|
652
|
-
|
653
|
-
indexes = [ ]
|
654
|
-
|
655
|
-
count.times do |this_time|
|
656
|
-
indexes.push( count - this_time - 1 )
|
657
|
-
end
|
658
|
-
|
659
|
-
delete_at_indexes( *indexes )
|
660
|
-
|
661
|
-
return self
|
662
|
-
|
663
|
-
end
|
664
|
-
|
665
|
-
#############
|
666
|
-
# freeze! #
|
667
|
-
#############
|
668
|
-
|
669
|
-
# freezes configuration and prevents ancestors from changing this configuration in the future
|
670
|
-
def freeze!
|
671
|
-
|
672
|
-
# unregister with parent composite so we don't get future updates from it
|
673
|
-
if @super_composite_array
|
674
|
-
@super_composite_array.unregister_sub_composite_array( self )
|
675
|
-
end
|
676
|
-
|
677
|
-
return self
|
678
|
-
|
679
|
-
end
|
680
|
-
|
681
|
-
##################################################################################################
|
682
|
-
private ######################################################################################
|
683
|
-
##################################################################################################
|
684
|
-
|
685
|
-
################ Self Management for Inserts between Parent-Provided Elements ##################
|
686
|
-
|
687
|
-
###################################
|
688
|
-
# index_inside_parent_objects? #
|
689
|
-
###################################
|
690
|
-
|
691
|
-
def index_inside_parent_objects?( index )
|
692
|
-
|
693
|
-
index_inside_parent_objects = false
|
694
|
-
|
695
|
-
if index < @parent_and_interpolated_object_count
|
696
|
-
|
697
|
-
index_inside_parent_objects = true
|
698
|
-
|
699
|
-
end
|
700
|
-
|
701
|
-
return index_inside_parent_objects
|
702
|
-
|
703
|
-
end
|
704
|
-
|
705
|
-
#################################################
|
706
|
-
# update_corresponding_index_for_local_change #
|
707
|
-
#################################################
|
708
|
-
|
709
|
-
def update_corresponding_index_for_local_change( index, step_value )
|
710
|
-
|
711
|
-
# update corresponding indexes for changes in self
|
712
|
-
|
713
|
-
indexes_to_delete = [ ]
|
714
|
-
|
715
|
-
@local_index_for_parent_index.each do |this_parent_index, this_local_index|
|
716
|
-
if this_parent_index >= index
|
717
|
-
existing_corresponding_value = @local_index_for_parent_index[ this_parent_index ]
|
718
|
-
new_corresponding_value = existing_corresponding_value + step_value
|
719
|
-
if new_corresponding_value >= 0
|
720
|
-
@local_index_for_parent_index[ this_parent_index ] = new_corresponding_value
|
721
|
-
else
|
722
|
-
indexes_to_delete.push( this_parent_index )
|
723
|
-
end
|
724
|
-
end
|
725
|
-
end
|
726
|
-
|
727
|
-
step_parent_and_interpolated_object_count( step_value )
|
728
|
-
|
729
|
-
end
|
730
|
-
|
731
|
-
######################### Self-as-Sub Management for Parent Updates ############################
|
732
|
-
|
733
|
-
########################################
|
734
|
-
# update_as_sub_array_for_parent_set #
|
735
|
-
########################################
|
736
|
-
|
737
|
-
def update_as_sub_array_for_parent_set( index, object )
|
738
|
-
|
739
|
-
# if our index is bigger than current parent set we are inserting
|
740
|
-
if index >= @parent_and_interpolated_object_count
|
741
|
-
|
742
|
-
update_as_sub_array_for_parent_insert( index, object )
|
743
|
-
|
744
|
-
# otherwise we are replacing and have a corresponding element defined already
|
745
|
-
else
|
746
|
-
|
747
|
-
unless @replaced_parents[ index ]
|
748
|
-
|
749
|
-
corresponding_index = @local_index_for_parent_index[ index ]
|
750
|
-
non_cascading_set( corresponding_index, object )
|
751
|
-
|
752
|
-
@sub_composite_arrays.each do |this_array|
|
753
|
-
this_array.instance_eval do
|
754
|
-
update_as_sub_array_for_parent_set( corresponding_index, object )
|
755
|
-
end
|
756
|
-
end
|
757
|
-
|
758
|
-
end
|
759
|
-
|
760
|
-
end
|
761
|
-
|
762
|
-
end
|
763
|
-
|
764
|
-
###########################################
|
765
|
-
# update_as_sub_array_for_parent_insert #
|
766
|
-
###########################################
|
767
|
-
|
768
|
-
def update_as_sub_array_for_parent_insert( index, *objects )
|
769
|
-
|
770
|
-
# new parent indexes have been inserted at index in parent
|
771
|
-
|
772
|
-
# we need the corresponding index in self where parallel insert will occur
|
773
|
-
if corresponding_index = @local_index_for_parent_index[ index ]
|
774
|
-
|
775
|
-
if corresponding_index < 0
|
776
|
-
corresponding_index = 0
|
777
|
-
else
|
778
|
-
update_corresponding_index_for_parent_change( index, objects.count )
|
779
|
-
end
|
780
|
-
|
781
|
-
else
|
782
|
-
|
783
|
-
corresponding_index = @parent_and_interpolated_object_count
|
784
|
-
@parent_and_interpolated_object_count += objects.count
|
785
|
-
|
786
|
-
end
|
787
|
-
|
788
|
-
# then we're going to increment existing correspondences
|
789
|
-
# now since we added a space for the new elements we can add their new correspondences
|
790
|
-
objects.count.times do |this_time|
|
791
|
-
new_parent_index = index + this_time
|
792
|
-
new_corresponding_index = corresponding_index + this_time
|
793
|
-
@local_index_for_parent_index[ new_parent_index ] = new_corresponding_index
|
794
|
-
end
|
795
|
-
|
796
|
-
non_cascading_insert( corresponding_index, *objects )
|
797
|
-
|
798
|
-
@sub_composite_arrays.each do |this_array|
|
799
|
-
this_array.instance_eval do
|
800
|
-
update_as_sub_array_for_parent_insert( corresponding_index, *objects )
|
801
|
-
end
|
802
|
-
end
|
803
|
-
|
804
|
-
end
|
805
|
-
|
806
|
-
###########################################
|
807
|
-
# update_as_sub_array_for_parent_delete #
|
808
|
-
###########################################
|
809
|
-
|
810
|
-
def update_as_sub_array_for_parent_delete( index )
|
811
|
-
|
812
|
-
corresponding_index = @local_index_for_parent_index[ index ]
|
813
|
-
|
814
|
-
object = non_cascading_delete_at( corresponding_index )
|
815
|
-
|
816
|
-
@parent_and_interpolated_object_count -= 1
|
817
|
-
|
818
|
-
@sub_composite_arrays.each do |this_array|
|
819
|
-
this_array.instance_eval do
|
820
|
-
update_as_sub_array_for_parent_delete( corresponding_index )
|
821
|
-
end
|
822
|
-
end
|
823
|
-
|
824
|
-
end
|
825
|
-
|
826
|
-
##################################################
|
827
|
-
# update_corresponding_index_for_parent_change #
|
828
|
-
##################################################
|
829
|
-
|
830
|
-
def update_corresponding_index_for_parent_change( parent_index, step_value )
|
831
|
-
|
832
|
-
# update corresponding indexes for changes in parent
|
833
|
-
|
834
|
-
stepped_indices = { }
|
835
|
-
|
836
|
-
# iterate the hash with all indices included and increment/decrement any >= parent_index
|
837
|
-
@local_index_for_parent_index.each do |this_parent_index, this_local_index|
|
838
|
-
if this_parent_index >= parent_index
|
839
|
-
new_index = this_parent_index + step_value
|
840
|
-
stepped_indices[ new_index ] = @local_index_for_parent_index.delete( this_parent_index ) + step_value
|
841
|
-
end
|
842
|
-
end
|
843
|
-
|
844
|
-
# merge stepped indices back in
|
845
|
-
@local_index_for_parent_index.merge!( stepped_indices )
|
846
|
-
|
847
|
-
step_parent_and_interpolated_object_count( step_value )
|
848
|
-
|
849
|
-
end
|
850
|
-
|
851
|
-
###############################################
|
852
|
-
# step_parent_and_interpolated_object_count #
|
853
|
-
###############################################
|
854
|
-
|
855
|
-
def step_parent_and_interpolated_object_count( step_value )
|
856
|
-
|
857
|
-
@parent_and_interpolated_object_count += step_value
|
858
|
-
|
859
|
-
if @parent_and_interpolated_object_count < 0
|
860
|
-
@parent_and_interpolated_object_count = 0
|
861
|
-
end
|
862
|
-
|
863
|
-
end
|
864
|
-
|
865
|
-
end
|