cascading-configuration-array 1.4.1 → 1.5.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.
Files changed (19) hide show
  1. data/lib/cascading-configuration-array/CascadingConfiguration/Array/Interface.rb +58 -21
  2. data/lib/cascading-configuration-array/CascadingConfiguration/Array.rb +6 -21
  3. data/lib/cascading-configuration-array/{CascadingConfiguration → _private_/CascadingConfiguration/Array/CompositingArray}/LocalConfigurationArray.rb +27 -1
  4. data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/CompositingArray.rb +295 -0
  5. data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/Interface/GettersSetters.rb +246 -0
  6. data/lib/cascading-configuration-array/_private_/CascadingConfiguration/Array/ModuleSupportMethods.rb +48 -0
  7. data/lib/cascading-configuration-array.rb +16 -23
  8. data/spec/CascadingConfiguration/Array_spec.rb +2 -3
  9. data/spec/{CascadingConfiguration → _private_/CascadingConfiguration/Array/CompositingArray}/LocalConfigurationArray_spec.rb +13 -13
  10. data/spec/_private_/CascadingConfiguration/Array/CompositingArray_spec.rb +569 -0
  11. metadata +10 -28
  12. data/lib/cascading-configuration-array/CascadingConfiguration/Array/AccessorDefinitionMethods.rb +0 -175
  13. data/lib/cascading-configuration-array/CascadingConfiguration/Array/Interface/Instance.rb +0 -22
  14. data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray/Instance.rb +0 -31
  15. data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray.rb +0 -215
  16. data/lib/cascading-configuration-array/CascadingConfiguration/_private_/CompositingArray.rb +0 -57
  17. data/lib/cascading-configuration-array/CascadingConfiguration/_private_/LocalConfigurationArray.rb +0 -26
  18. data/spec/CascadingConfiguration/Array/AccessorDefinitionMethods_spec.rb +0 -30
  19. data/spec/CascadingConfiguration/CompositingArray_spec.rb +0 -541
@@ -1,175 +0,0 @@
1
-
2
- module CascadingConfiguration::Array::AccessorDefinitionMethods
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ###################################
7
- # define_cascading_array_setter #
8
- ###################################
9
-
10
- def define_cascading_array_setter( configuration_name )
11
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
12
- self_instance = self
13
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
14
- accessor_module_support.module_eval do
15
- define_method( configuration_setter_name ) do |array|
16
- composite_array = composite_array_for_cascading_configuration( configuration_name )
17
- # we want the array to supplant existing config
18
- # clear the array (excludes everything explicitly)
19
- composite_array.clear
20
- # push array elements (removes anything excluded from exclude)
21
- composite_array.push( *array )
22
- return composite_array
23
- end
24
- end
25
- end
26
- end
27
-
28
- ###################################
29
- # define_cascading_array_getter #
30
- ###################################
31
-
32
- def define_cascading_array_getter( configuration_name )
33
- configuration_getter_name = configuration_name
34
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
35
- accessor_module_support.module_eval do
36
- define_method( configuration_getter_name ) do
37
- return composite_array_for_cascading_configuration( configuration_name )
38
- end
39
- end
40
- end
41
- end
42
-
43
- #############################################
44
- # define_class_configuration_array_setter #
45
- #############################################
46
-
47
- def define_class_configuration_array_setter( configuration_name )
48
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
49
- accessor_module_support.module_eval do
50
- define_method( configuration_setter_name ) do |array|
51
- composite_array = composite_array_for_cascading_configuration( configuration_name )
52
- # we want the array to supplant existing config
53
- # clear the array (excludes everything explicitly)
54
- composite_array.clear
55
- # push array elements (removes anything excluded from exclude)
56
- composite_array.push( *array )
57
- return composite_array
58
- end
59
- end
60
- end
61
-
62
- #############################################
63
- # define_class_configuration_array_getter #
64
- #############################################
65
-
66
- def define_class_configuration_array_getter( configuration_name )
67
- configuration_getter_name = configuration_name
68
- accessor_module_support.module_eval do
69
- define_method( configuration_getter_name ) do
70
- return composite_array_for_cascading_configuration( configuration_name )
71
- end
72
- end
73
- end
74
-
75
- #############################################
76
- # define_local_configuration_array_setter #
77
- #############################################
78
-
79
- def define_local_configuration_array_setter( configuration_name )
80
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
81
- [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
82
- module_support.module_eval do
83
- define_method( configuration_setter_name ) do |array|
84
- composite_array = composite_array_for_cascading_configuration( configuration_name )
85
- # we want the array to supplant existing config
86
- # clear the array (excludes everything explicitly)
87
- composite_array.clear
88
- # push array elements (removes anything excluded from exclude)
89
- composite_array.push( *array )
90
- return composite_array
91
- end
92
- end
93
- end
94
- end
95
-
96
- #############################################
97
- # define_local_configuration_array_getter #
98
- #############################################
99
-
100
- def define_local_configuration_array_getter( configuration_name )
101
- configuration_getter_name = configuration_name
102
- [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
103
- module_support.module_eval do
104
- define_method( configuration_getter_name ) do
105
- return composite_array_for_cascading_configuration( configuration_name )
106
- end
107
- end
108
- end
109
- end
110
-
111
- ################################################
112
- # define_instance_configuration_array_setter #
113
- ################################################
114
-
115
- def define_instance_configuration_array_setter( configuration_name )
116
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
117
- accessor_instance_support.module_eval do
118
- define_method( configuration_setter_name ) do |array|
119
- composite_array = composite_array_for_cascading_configuration( configuration_name )
120
- # we want the array to supplant existing config
121
- # clear the array (excludes everything explicitly)
122
- composite_array.clear
123
- # push array elements (removes anything excluded from exclude)
124
- composite_array.push( *array )
125
- return composite_array
126
- end
127
- end
128
- end
129
-
130
- ################################################
131
- # define_instance_configuration_array_getter #
132
- ################################################
133
-
134
- def define_instance_configuration_array_getter( configuration_name )
135
- configuration_getter_name = configuration_name
136
- accessor_instance_support.module_eval do
137
- define_method( configuration_getter_name ) do
138
- return composite_array_for_cascading_configuration( configuration_name )
139
- end
140
- end
141
- end
142
-
143
- ##############################################
144
- # define_object_configuration_array_setter #
145
- ##############################################
146
-
147
- def define_object_configuration_array_setter( configuration_name )
148
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
149
- accessor_local_instance_support.module_eval do
150
- define_method( configuration_setter_name ) do |array|
151
- composite_array = composite_array_for_cascading_configuration( configuration_name )
152
- # we want the array to supplant existing config
153
- # clear the array (excludes everything explicitly)
154
- composite_array.clear
155
- # push array elements (removes anything excluded from exclude)
156
- composite_array.push( *array )
157
- return composite_array
158
- end
159
- end
160
- end
161
-
162
- ##############################################
163
- # define_object_configuration_array_getter #
164
- ##############################################
165
-
166
- def define_object_configuration_array_getter( configuration_name )
167
- configuration_getter_name = configuration_name
168
- accessor_local_instance_support.module_eval do
169
- define_method( configuration_getter_name ) do
170
- return composite_array_for_cascading_configuration( configuration_name )
171
- end
172
- end
173
- end
174
-
175
- end
@@ -1,22 +0,0 @@
1
-
2
- module CascadingConfiguration::Array::Interface::Instance
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- #######################################
7
- # attr_instance_configuration_array #
8
- #######################################
9
-
10
- # defines configuration in present class or module context
11
- # configuration does not cascade
12
- def attr_instance_configuration_array( *property_names )
13
- property_names.each do |this_property_name|
14
- # define configuration setter
15
- define_instance_configuration_array_setter( this_property_name )
16
- # define configuration getter
17
- define_instance_configuration_array_getter( this_property_name )
18
- end
19
- return self
20
- end
21
-
22
- end
@@ -1,31 +0,0 @@
1
-
2
- module CascadingConfiguration::CompositingArray::Instance
3
-
4
- extend ModuleCluster
5
-
6
- extend CascadingConfiguration::InternalModuleStub
7
-
8
- include_also_extends( self )
9
-
10
- #################################################
11
- # composite_array_for_cascading_configuration #
12
- #################################################
13
-
14
- def composite_array_for_cascading_configuration( cascading_name )
15
-
16
- composite_array = nil
17
-
18
- klass = ( is_a?( Module ) ? self : self.class )
19
- self_instance = self
20
- accessor_module_support.module_eval do
21
- unless composite_array = ( ( @composite_arrays ||= Hash.new )[ cascading_name ] ||= Hash.new )[ self_instance ]
22
- composite_array = ::CascadingConfiguration::CompositingArray.new( cascading_name, self_instance )
23
- @composite_arrays[ cascading_name ][ self_instance ] = composite_array
24
- end
25
- end
26
-
27
- return composite_array
28
-
29
- end
30
-
31
- end
@@ -1,215 +0,0 @@
1
-
2
- class CascadingConfiguration::CompositingArray < Array
3
-
4
- attr_accessor :working_instance, :local_cascading_array
5
-
6
- ################
7
- # initialize #
8
- ################
9
-
10
- def initialize( cascading_name, working_instance )
11
- @cascading_name = cascading_name
12
- @working_class = ( working_instance.is_a?( Module ) ? working_instance : working_instance.class )
13
- @working_instance = working_instance
14
- # if first ancestor can have a composite array, register self with it in case it gets updated in the future
15
- if ( first_ancestor = @working_instance.first_ancestor ).respond_to?( :composite_array_for_cascading_configuration )
16
- @parent_composite_array = first_ancestor.composite_array_for_cascading_configuration( @cascading_name )
17
- @parent_composite_array.register_child_composite_array( self )
18
- end
19
- # get local cascading array (not included in parent composite)
20
- @local_cascading_array = ::CascadingConfiguration::LocalConfigurationArray.new
21
- # we may later have our own child composites
22
- @child_composite_arrays = ::Array.new
23
- # initialize self status for parent and local
24
- update_self_as_cascading_composite
25
- end
26
-
27
- ####################################
28
- # register_child_composite_array #
29
- ####################################
30
-
31
- def register_child_composite_array( child_composite_array )
32
- @child_composite_arrays.push( child_composite_array )
33
- return self
34
- end
35
-
36
- ######################################
37
- # unregister_child_composite_array #
38
- ######################################
39
-
40
- def unregister_child_composite_array( child_composite_array )
41
- @child_composite_arrays.delete( child_composite_array )
42
- return self
43
- end
44
-
45
- #########
46
- # []= #
47
- #########
48
-
49
- def []=( index, element )
50
- # we sort internally, so index is irrelevant
51
- # no reason to differentiate from push
52
- push( element )
53
- end
54
-
55
- ########
56
- # << #
57
- ########
58
-
59
- def <<( *elements )
60
- # no reason to differentiate from push
61
- push( *elements )
62
- end
63
-
64
- #######
65
- # + #
66
- #######
67
-
68
- def +( *arrays )
69
- # no reason to differentiate from push
70
- arrays.each do |this_array|
71
- push( *this_array )
72
- end
73
- return self
74
- end
75
-
76
- ############
77
- # concat #
78
- ############
79
-
80
- def concat( *arrays )
81
- arrays.each do |this_array|
82
- push( *this_array )
83
- end
84
- end
85
-
86
- ##########
87
- # push #
88
- ##########
89
-
90
- alias_method :super_push, :push
91
- def push( *elements )
92
-
93
- # we are a composite array
94
- # that means we have to set the value for our class
95
- @local_cascading_array.push( *elements )
96
-
97
- update_adding_composite_elements( *elements )
98
-
99
- return self
100
-
101
- end
102
-
103
- #######
104
- # - #
105
- #######
106
-
107
- def -( *arrays )
108
-
109
- arrays.each do |this_array|
110
- delete( *this_array )
111
- end
112
-
113
- return self
114
-
115
- end
116
-
117
- ############
118
- # delete #
119
- ############
120
-
121
- alias_method :super_delete, :delete
122
- def delete( *elements )
123
-
124
- @local_cascading_array.delete( *elements )
125
-
126
- update_removing_composite_elements( *elements )
127
-
128
- return self
129
-
130
- end
131
-
132
- #########
133
- # pop #
134
- #########
135
-
136
- def pop
137
-
138
- element = super
139
-
140
- @local_cascading_array.delete( element )
141
-
142
- update_removing_composite_elements( element )
143
-
144
- return element
145
-
146
- end
147
-
148
- ###########
149
- # shift #
150
- ###########
151
-
152
- def shift
153
-
154
- element = super
155
-
156
- @local_cascading_array.delete( element )
157
-
158
- update_removing_composite_elements( element )
159
-
160
- return element
161
-
162
- end
163
-
164
- ############
165
- # slice! #
166
- ############
167
-
168
- def slice!( *args )
169
-
170
- elements = super
171
-
172
- @local_cascading_array.delete( *elements )
173
-
174
- update_removing_composite_elements( *elements )
175
-
176
- return elements
177
-
178
- end
179
-
180
- ###########
181
- # clear #
182
- ###########
183
-
184
- alias_method :super_clear, :clear
185
- def clear
186
-
187
- # add all existing values to exclude array
188
- @local_cascading_array.delete( *self )
189
-
190
- update_removing_composite_elements( *self )
191
-
192
- return self
193
-
194
- end
195
-
196
- #############
197
- # freeze! #
198
- #############
199
-
200
- # freezes configuration and prevents ancestors from changing this configuration in the future
201
- def freeze!
202
-
203
- # move current configuration into local configuration
204
- @local_cascading_array.clear
205
- @local_cascading_array.exclude_array.clear
206
- @local_cascading_array.push( *self )
207
-
208
- # unregister with parent composite so we don't get future updates from it
209
- @parent_composite_array.unregister_child_composite_array( self ) if @parent_composite_array
210
-
211
- return self
212
-
213
- end
214
-
215
- end
@@ -1,57 +0,0 @@
1
-
2
- class CascadingConfiguration::CompositingArray < Array
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- ########################################
9
- # update_self_as_cascading_composite #
10
- ########################################
11
-
12
- def update_self_as_cascading_composite
13
- # start fresh
14
- super_clear
15
- # add parent config
16
- super_push( *@parent_composite_array ) if @parent_composite_array
17
- # add additional local config
18
- super_push( *@local_cascading_array )
19
- # remove local exclude
20
- super_delete( *@local_cascading_array.exclude_array ) unless @local_cascading_array.exclude_array.empty?
21
- # notify children to update their composite status
22
- update_child_composite_arrays
23
- return self
24
- end
25
-
26
- ######################################
27
- # update_adding_composite_elements #
28
- ######################################
29
-
30
- def update_adding_composite_elements( *elements_to_cascade )
31
- super_push( *elements_to_cascade )
32
- sort!.uniq!
33
- update_child_composite_arrays
34
- end
35
-
36
- ########################################
37
- # update_removing_composite_elements #
38
- ########################################
39
-
40
- def update_removing_composite_elements( *elements_to_exclude )
41
- elements_to_exclude.each do |this_excluded_element|
42
- super_delete( this_excluded_element )
43
- end
44
- update_child_composite_arrays
45
- end
46
-
47
- ###################################
48
- # update_child_composite_arrays #
49
- ###################################
50
-
51
- def update_child_composite_arrays
52
- @child_composite_arrays.each do |this_composite_array|
53
- this_composite_array.instance_eval { update_self_as_cascading_composite }
54
- end
55
- end
56
-
57
- end
@@ -1,26 +0,0 @@
1
-
2
- class CascadingConfiguration::LocalConfigurationArray < Array
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- ##########################
9
- # add_to_exclude_array #
10
- ##########################
11
-
12
- def add_to_exclude_array( *elements )
13
- @exclude_array += elements
14
- @exclude_array.sort!.uniq!
15
- end
16
-
17
- ###############################
18
- # remove_from_exclude_array #
19
- ###############################
20
-
21
- def remove_from_exclude_array( *elements )
22
- @exclude_array -= elements
23
- @exclude_array.sort!.uniq!
24
- end
25
-
26
- end
@@ -1,30 +0,0 @@
1
-
2
- require_relative '../../../lib/cascading-configuration-array.rb'
3
-
4
- describe CascadingConfiguration::Array::AccessorDefinitionMethods do
5
-
6
- ###################################
7
- # define_cascading_array_setter #
8
- # define_cascading_array_getter #
9
- ###################################
10
-
11
- it 'can define a method to get and modify the configuration array' do
12
- class CascadingConfiguration::Array::Mock
13
- include CascadingConfiguration::Variable
14
- CascadingConfiguration::Variable.define_accessor_module_support( self )
15
- CascadingConfiguration::Variable.define_accessor_instance_support( self )
16
- extend CascadingConfiguration::Array::AccessorDefinitionMethods
17
- include CascadingConfiguration::Array::ObjectInstance
18
- extend CascadingConfiguration::Array::Interface
19
- end
20
- # setter
21
- CascadingConfiguration::Array::Mock.define_cascading_array_setter( :some_configuration )
22
- CascadingConfiguration::Array::Mock.respond_to?( :some_configuration= ).should == true
23
- CascadingConfiguration::Array::Mock.instance_methods.include?( :some_configuration= ).should == true
24
- # getter
25
- CascadingConfiguration::Array::Mock.define_cascading_array_getter( :some_configuration )
26
- CascadingConfiguration::Array::Mock.respond_to?( :some_configuration ).should == true
27
- CascadingConfiguration::Array::Mock.instance_methods.include?( :some_configuration ).should == true
28
- end
29
-
30
- end