cascading-configuration-array 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/Interface.rb +58 -21
- data/lib/cascading-configuration-array/CascadingConfiguration/Array.rb +6 -21
- data/lib/cascading-configuration-array/{CascadingConfiguration → _private_/CascadingConfiguration/Array/CompositingArray}/LocalConfigurationArray.rb +27 -1
- data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb +295 -0
- data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/Interface/GettersSetters.rb +246 -0
- data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/ModuleSupportMethods.rb +48 -0
- data/lib/cascading-configuration-array.rb +16 -23
- data/spec/CascadingConfiguration/Array_spec.rb +2 -3
- data/spec/{CascadingConfiguration → _private_/CascadingConfiguration/Array/CompositingArray}/LocalConfigurationArray_spec.rb +13 -13
- data/spec/_private_/CascadingConfiguration/Array/CompositingArray_spec.rb +569 -0
- metadata +10 -28
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/AccessorDefinitionMethods.rb +0 -175
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/Interface/Instance.rb +0 -22
- data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray/Instance.rb +0 -31
- data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray.rb +0 -215
- data/lib/cascading-configuration-array/CascadingConfiguration/_private_/CompositingArray.rb +0 -57
- data/lib/cascading-configuration-array/CascadingConfiguration/_private_/LocalConfigurationArray.rb +0 -26
- data/spec/CascadingConfiguration/Array/AccessorDefinitionMethods_spec.rb +0 -30
- data/spec/CascadingConfiguration/CompositingArray_spec.rb +0 -541
@@ -1,21 +1,26 @@
|
|
1
1
|
|
2
2
|
module CascadingConfiguration::Array::Interface
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
# Support methods that define configuration settings array methods
|
5
|
+
include ::CascadingConfiguration::Array::Interface::GettersSetters
|
6
|
+
|
6
7
|
##############################
|
7
8
|
# attr_configuration_array #
|
8
9
|
##############################
|
9
10
|
|
10
11
|
# defines configuration in class or module
|
11
12
|
# configuration cascades downward to instance including all classes or modules in-between
|
12
|
-
def attr_configuration_array( *
|
13
|
-
|
13
|
+
def attr_configuration_array( *configuration_names )
|
14
|
+
|
15
|
+
configuration_names.each do |this_configuration_name|
|
14
16
|
# define configuration setter
|
15
|
-
define_cascading_array_setter(
|
17
|
+
define_cascading_array_setter( this_configuration_name )
|
16
18
|
# define configuration getter
|
17
|
-
define_cascading_array_getter(
|
19
|
+
define_cascading_array_getter( this_configuration_name )
|
18
20
|
end
|
21
|
+
|
22
|
+
return self
|
23
|
+
|
19
24
|
end
|
20
25
|
|
21
26
|
#####################################
|
@@ -24,13 +29,17 @@ module CascadingConfiguration::Array::Interface
|
|
24
29
|
|
25
30
|
# defines configuration in class or module
|
26
31
|
# configuration cascades downward to last class or module
|
27
|
-
def attr_module_configuration_array( *
|
28
|
-
|
32
|
+
def attr_module_configuration_array( *configuration_names )
|
33
|
+
|
34
|
+
configuration_names.each do |this_configuration_name|
|
29
35
|
# define configuration setter
|
30
|
-
define_class_configuration_array_setter(
|
36
|
+
define_class_configuration_array_setter( this_configuration_name )
|
31
37
|
# define configuration getter
|
32
|
-
define_class_configuration_array_getter(
|
38
|
+
define_class_configuration_array_getter( this_configuration_name )
|
33
39
|
end
|
40
|
+
|
41
|
+
return self
|
42
|
+
|
34
43
|
end
|
35
44
|
alias_method :attr_class_configuration_array, :attr_module_configuration_array
|
36
45
|
|
@@ -40,15 +49,19 @@ module CascadingConfiguration::Array::Interface
|
|
40
49
|
|
41
50
|
# defines configuration in present class or module context
|
42
51
|
# configuration does not cascade
|
43
|
-
def attr_local_configuration_array( *
|
44
|
-
|
45
|
-
|
52
|
+
def attr_local_configuration_array( *configuration_names )
|
53
|
+
|
54
|
+
CascadingConfiguration::Variable.initialize_local_instance_configuration_module( self )
|
55
|
+
|
56
|
+
configuration_names.each do |this_configuration_name|
|
46
57
|
# define configuration setter
|
47
|
-
define_local_configuration_array_setter(
|
58
|
+
define_local_configuration_array_setter( this_configuration_name )
|
48
59
|
# define configuration getter
|
49
|
-
define_local_configuration_array_getter(
|
60
|
+
define_local_configuration_array_getter( this_configuration_name )
|
50
61
|
end
|
51
|
-
|
62
|
+
|
63
|
+
return self
|
64
|
+
|
52
65
|
end
|
53
66
|
|
54
67
|
#####################################
|
@@ -57,14 +70,38 @@ module CascadingConfiguration::Array::Interface
|
|
57
70
|
|
58
71
|
# defines configuration in present instance
|
59
72
|
# configuration does not cascade
|
60
|
-
def attr_object_configuration_array( *
|
61
|
-
|
62
|
-
|
73
|
+
def attr_object_configuration_array( *configuration_names )
|
74
|
+
|
75
|
+
CascadingConfiguration::Variable.initialize_local_instance_configuration_module( self )
|
76
|
+
|
77
|
+
configuration_names.each do |this_configuration_name|
|
78
|
+
# define configuration setter
|
79
|
+
define_object_configuration_array_setter( this_configuration_name )
|
80
|
+
# define configuration getter
|
81
|
+
define_object_configuration_array_getter( this_configuration_name )
|
82
|
+
end
|
83
|
+
|
84
|
+
return self
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
#######################################
|
89
|
+
# attr_instance_configuration_array #
|
90
|
+
#######################################
|
91
|
+
|
92
|
+
# defines configuration in present class or module context
|
93
|
+
# configuration does not cascade
|
94
|
+
def attr_instance_configuration_array( *configuration_names )
|
95
|
+
|
96
|
+
configuration_names.each do |this_configuration_name|
|
63
97
|
# define configuration setter
|
64
|
-
|
98
|
+
define_instance_configuration_array_setter( this_configuration_name )
|
65
99
|
# define configuration getter
|
66
|
-
|
100
|
+
define_instance_configuration_array_getter( this_configuration_name )
|
67
101
|
end
|
102
|
+
|
103
|
+
return self
|
104
|
+
|
68
105
|
end
|
69
106
|
|
70
107
|
end
|
@@ -1,27 +1,12 @@
|
|
1
1
|
|
2
2
|
module CascadingConfiguration::Array
|
3
3
|
|
4
|
-
|
4
|
+
# Configuration modules for storage of settings arrays
|
5
|
+
include ::CascadingConfiguration::Variable
|
5
6
|
|
6
|
-
|
7
|
+
# Interface to declare configuration settings arrays
|
8
|
+
include ::CascadingConfiguration::Array::Interface
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
include CascadingConfiguration::Array::Interface
|
11
|
-
include CascadingConfiguration::Array::AccessorDefinitionMethods
|
12
|
-
|
13
|
-
prepend_module_include do |class_or_module|
|
14
|
-
class_or_module.extend_also_extends( CascadingConfiguration::Variable::EigenclassConfigurationChain )
|
15
|
-
end
|
16
|
-
|
17
|
-
include_cascades_extends( CascadingConfiguration::Array::Interface::Instance )
|
18
|
-
|
19
|
-
include_cascades_extends( CascadingConfiguration::Array )
|
20
|
-
|
21
|
-
prepend_module_include do |class_or_module|
|
22
|
-
class_or_module.include_or_extend_cascades_prepending_extends do
|
23
|
-
accessor_module_support
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
10
|
+
extend ::CascadingConfiguration::Array::ModuleSupportMethods
|
11
|
+
|
27
12
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
|
2
|
-
class CascadingConfiguration::LocalConfigurationArray < Array
|
2
|
+
class CascadingConfiguration::Array::CompositingArray::LocalConfigurationArray < Array
|
3
|
+
|
4
|
+
# A LocalConfigurationArray is a single layer of a CompositingArray.
|
5
|
+
# The LocalConfigurationArray holds the layer's settings and exclude values.
|
6
|
+
# CompositingArray uses LocalConfigurationArray to cascade.
|
3
7
|
|
4
8
|
attr_accessor :exclude_array
|
5
9
|
|
@@ -163,4 +167,26 @@ class CascadingConfiguration::LocalConfigurationArray < Array
|
|
163
167
|
|
164
168
|
end
|
165
169
|
|
170
|
+
###########################################################################################################
|
171
|
+
private ###############################################################################################
|
172
|
+
###########################################################################################################
|
173
|
+
|
174
|
+
##########################
|
175
|
+
# add_to_exclude_array #
|
176
|
+
##########################
|
177
|
+
|
178
|
+
def add_to_exclude_array( *elements )
|
179
|
+
@exclude_array += elements
|
180
|
+
@exclude_array.sort!.uniq!
|
181
|
+
end
|
182
|
+
|
183
|
+
###############################
|
184
|
+
# remove_from_exclude_array #
|
185
|
+
###############################
|
186
|
+
|
187
|
+
def remove_from_exclude_array( *elements )
|
188
|
+
@exclude_array -= elements
|
189
|
+
@exclude_array.sort!.uniq!
|
190
|
+
end
|
191
|
+
|
166
192
|
end
|
data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
|
2
|
+
class CascadingConfiguration::Array::CompositingArray < Array
|
3
|
+
|
4
|
+
attr_accessor :local_cascading_array
|
5
|
+
|
6
|
+
################
|
7
|
+
# initialize #
|
8
|
+
################
|
9
|
+
|
10
|
+
def initialize( configuration_instance, configuration_name )
|
11
|
+
|
12
|
+
for_instance = false
|
13
|
+
|
14
|
+
@configuration_instance = configuration_instance
|
15
|
+
|
16
|
+
module_configuration_module = ::CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance )
|
17
|
+
if ! module_configuration_module and ! configuration_instance.is_a?( Module )
|
18
|
+
module_configuration_module = ::CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance.class )
|
19
|
+
for_instance = true
|
20
|
+
end
|
21
|
+
|
22
|
+
@configuration_name = configuration_name
|
23
|
+
|
24
|
+
# store self for sub composites
|
25
|
+
module_configuration_module.set_configuration_variable( configuration_name, self, for_instance )
|
26
|
+
|
27
|
+
# if first ancestor can have a composite array, register self with it in case it gets updated in the future
|
28
|
+
super_configuration_module = nil
|
29
|
+
if for_instance
|
30
|
+
super_configuration_module = module_configuration_module
|
31
|
+
else
|
32
|
+
super_configuration_module = module_configuration_module.super_configuration_module
|
33
|
+
end
|
34
|
+
|
35
|
+
if super_configuration_module and
|
36
|
+
@super_composite_array = super_configuration_module.get_configuration_variable( configuration_name ) and
|
37
|
+
@super_composite_array.respond_to?( :register_sub_composite_array )
|
38
|
+
|
39
|
+
@super_composite_array.register_sub_composite_array( self )
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# instantiate local cascading array
|
44
|
+
@local_cascading_array = ::CascadingConfiguration::Array::CompositingArray::LocalConfigurationArray.new
|
45
|
+
|
46
|
+
# we may later have our own child composites that register with us
|
47
|
+
@sub_composite_arrays = ::Array.new
|
48
|
+
|
49
|
+
# initialize self status for parent and local
|
50
|
+
update_self_as_cascading_composite
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
##################################
|
55
|
+
# register_sub_composite_array #
|
56
|
+
##################################
|
57
|
+
|
58
|
+
def register_sub_composite_array( sub_composite_array )
|
59
|
+
@sub_composite_arrays.push( sub_composite_array )
|
60
|
+
return self
|
61
|
+
end
|
62
|
+
|
63
|
+
####################################
|
64
|
+
# unregister_sub_composite_array #
|
65
|
+
####################################
|
66
|
+
|
67
|
+
def unregister_sub_composite_array( sub_composite_array )
|
68
|
+
@sub_composite_arrays.delete( sub_composite_array )
|
69
|
+
return self
|
70
|
+
end
|
71
|
+
|
72
|
+
#########
|
73
|
+
# []= #
|
74
|
+
#########
|
75
|
+
|
76
|
+
def []=( index, element )
|
77
|
+
# we sort internally, so index is irrelevant
|
78
|
+
# no reason to differentiate from push
|
79
|
+
push( element )
|
80
|
+
end
|
81
|
+
|
82
|
+
########
|
83
|
+
# << #
|
84
|
+
########
|
85
|
+
|
86
|
+
def <<( *elements )
|
87
|
+
# no reason to differentiate from push
|
88
|
+
push( *elements )
|
89
|
+
end
|
90
|
+
|
91
|
+
#######
|
92
|
+
# + #
|
93
|
+
#######
|
94
|
+
|
95
|
+
def +( *arrays )
|
96
|
+
# no reason to differentiate from push
|
97
|
+
arrays.each do |this_array|
|
98
|
+
push( *this_array )
|
99
|
+
end
|
100
|
+
return self
|
101
|
+
end
|
102
|
+
|
103
|
+
############
|
104
|
+
# concat #
|
105
|
+
############
|
106
|
+
|
107
|
+
def concat( *arrays )
|
108
|
+
arrays.each do |this_array|
|
109
|
+
push( *this_array )
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
##########
|
114
|
+
# push #
|
115
|
+
##########
|
116
|
+
|
117
|
+
alias_method :super_push, :push
|
118
|
+
def push( *elements )
|
119
|
+
|
120
|
+
# we are a composite array
|
121
|
+
# that means we have to set the value for our class
|
122
|
+
@local_cascading_array.push( *elements )
|
123
|
+
|
124
|
+
update_adding_composite_elements( *elements )
|
125
|
+
|
126
|
+
return self
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
#######
|
131
|
+
# - #
|
132
|
+
#######
|
133
|
+
|
134
|
+
def -( *arrays )
|
135
|
+
|
136
|
+
arrays.each do |this_array|
|
137
|
+
delete( *this_array )
|
138
|
+
end
|
139
|
+
|
140
|
+
return self
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
############
|
145
|
+
# delete #
|
146
|
+
############
|
147
|
+
|
148
|
+
alias_method :super_delete, :delete
|
149
|
+
def delete( *elements )
|
150
|
+
|
151
|
+
@local_cascading_array.delete( *elements )
|
152
|
+
|
153
|
+
update_removing_composite_elements( *elements )
|
154
|
+
|
155
|
+
return self
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
#########
|
160
|
+
# pop #
|
161
|
+
#########
|
162
|
+
|
163
|
+
def pop
|
164
|
+
|
165
|
+
element = super
|
166
|
+
|
167
|
+
@local_cascading_array.delete( element )
|
168
|
+
|
169
|
+
update_removing_composite_elements( element )
|
170
|
+
|
171
|
+
return element
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
###########
|
176
|
+
# shift #
|
177
|
+
###########
|
178
|
+
|
179
|
+
def shift
|
180
|
+
|
181
|
+
element = super
|
182
|
+
|
183
|
+
@local_cascading_array.delete( element )
|
184
|
+
|
185
|
+
update_removing_composite_elements( element )
|
186
|
+
|
187
|
+
return element
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
############
|
192
|
+
# slice! #
|
193
|
+
############
|
194
|
+
|
195
|
+
def slice!( *args )
|
196
|
+
|
197
|
+
elements = super
|
198
|
+
|
199
|
+
@local_cascading_array.delete( *elements )
|
200
|
+
|
201
|
+
update_removing_composite_elements( *elements )
|
202
|
+
|
203
|
+
return elements
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
###########
|
208
|
+
# clear #
|
209
|
+
###########
|
210
|
+
|
211
|
+
alias_method :super_clear, :clear
|
212
|
+
def clear
|
213
|
+
|
214
|
+
# add all existing values to exclude array
|
215
|
+
@local_cascading_array.delete( *self )
|
216
|
+
|
217
|
+
update_removing_composite_elements( *self )
|
218
|
+
|
219
|
+
return self
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
#############
|
224
|
+
# freeze! #
|
225
|
+
#############
|
226
|
+
|
227
|
+
# freezes configuration and prevents ancestors from changing this configuration in the future
|
228
|
+
def freeze!
|
229
|
+
|
230
|
+
# move current configuration into local configuration
|
231
|
+
@local_cascading_array.clear
|
232
|
+
@local_cascading_array.exclude_array.clear
|
233
|
+
@local_cascading_array.push( *self )
|
234
|
+
|
235
|
+
# unregister with parent composite so we don't get future updates from it
|
236
|
+
@super_composite_array.unregister_sub_composite_array( self ) if @super_composite_array
|
237
|
+
|
238
|
+
return self
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
###########################################################################################################
|
243
|
+
private ###############################################################################################
|
244
|
+
###########################################################################################################
|
245
|
+
|
246
|
+
########################################
|
247
|
+
# update_self_as_cascading_composite #
|
248
|
+
########################################
|
249
|
+
|
250
|
+
def update_self_as_cascading_composite
|
251
|
+
# start fresh
|
252
|
+
super_clear
|
253
|
+
# add parent config
|
254
|
+
super_push( *@super_composite_array ) if @super_composite_array
|
255
|
+
# add additional local config
|
256
|
+
super_push( *@local_cascading_array )
|
257
|
+
# remove local exclude
|
258
|
+
super_delete( *@local_cascading_array.exclude_array ) unless @local_cascading_array.exclude_array.empty?
|
259
|
+
# notify children to update their composite status
|
260
|
+
update_sub_composite_arrays
|
261
|
+
return self
|
262
|
+
end
|
263
|
+
|
264
|
+
######################################
|
265
|
+
# update_adding_composite_elements #
|
266
|
+
######################################
|
267
|
+
|
268
|
+
def update_adding_composite_elements( *elements_to_cascade )
|
269
|
+
super_push( *elements_to_cascade )
|
270
|
+
sort!.uniq!
|
271
|
+
update_sub_composite_arrays
|
272
|
+
end
|
273
|
+
|
274
|
+
########################################
|
275
|
+
# update_removing_composite_elements #
|
276
|
+
########################################
|
277
|
+
|
278
|
+
def update_removing_composite_elements( *elements_to_exclude )
|
279
|
+
elements_to_exclude.each do |this_excluded_element|
|
280
|
+
super_delete( this_excluded_element )
|
281
|
+
end
|
282
|
+
update_sub_composite_arrays
|
283
|
+
end
|
284
|
+
|
285
|
+
###################################
|
286
|
+
# update_sub_composite_arrays #
|
287
|
+
###################################
|
288
|
+
|
289
|
+
def update_sub_composite_arrays
|
290
|
+
@sub_composite_arrays.each do |this_composite_array|
|
291
|
+
this_composite_array.instance_eval { update_self_as_cascading_composite }
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|