cascading_configuration 1.0.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/CHANGELOG.md +40 -0
- data/README.md +211 -0
- data/lib/cascading_configuration/array/sorted/unique.rb +110 -0
- data/lib/cascading_configuration/array/sorted.rb +106 -0
- data/lib/cascading_configuration/array/unique.rb +106 -0
- data/lib/cascading_configuration/array.rb +103 -0
- data/lib/cascading_configuration/core/enable_instance_support.rb +22 -0
- data/lib/cascading_configuration/core/enable_module_support.rb +24 -0
- data/lib/cascading_configuration/core/encapsulation.rb +343 -0
- data/lib/cascading_configuration/core/instance_controller/extension_module.rb +38 -0
- data/lib/cascading_configuration/core/instance_controller/support_module/instance_support_module.rb +21 -0
- data/lib/cascading_configuration/core/instance_controller/support_module/singleton_support_module.rb +21 -0
- data/lib/cascading_configuration/core/instance_controller/support_module.rb +253 -0
- data/lib/cascading_configuration/core/instance_controller.rb +840 -0
- data/lib/cascading_configuration/core/module/block_configurations/cascading_variables.rb +129 -0
- data/lib/cascading_configuration/core/module/block_configurations.rb +15 -0
- data/lib/cascading_configuration/core/module/extended_configurations/compositing_objects.rb +173 -0
- data/lib/cascading_configuration/core/module/extended_configurations.rb +65 -0
- data/lib/cascading_configuration/core/module/inheriting_values.rb +64 -0
- data/lib/cascading_configuration/core/module.rb +284 -0
- data/lib/cascading_configuration/core.rb +23 -0
- data/lib/cascading_configuration/hash.rb +103 -0
- data/lib/cascading_configuration/setting.rb +87 -0
- data/lib/cascading_configuration.rb +47 -0
- data/lib/namespaces.rb +9 -0
- data/lib/requires.rb +46 -0
- data/spec/cascading_configuration/array/sorted/unique_spec.rb +742 -0
- data/spec/cascading_configuration/array/sorted_spec.rb +741 -0
- data/spec/cascading_configuration/array/unique_spec.rb +746 -0
- data/spec/cascading_configuration/array_spec.rb +768 -0
- data/spec/cascading_configuration/core/encapsulation_spec.rb +208 -0
- data/spec/cascading_configuration/core/instance_controller/extension_module_spec.rb +26 -0
- data/spec/cascading_configuration/core/instance_controller/support_module_spec.rb +269 -0
- data/spec/cascading_configuration/core/instance_controller_spec.rb +273 -0
- data/spec/cascading_configuration/core/module/block_configurations/cascading_variables_spec.rb +17 -0
- data/spec/cascading_configuration/core/module/extended_configurations/compositing_objects_spec.rb +127 -0
- data/spec/cascading_configuration/core/module/extended_configurations_spec.rb +37 -0
- data/spec/cascading_configuration/core/module/inheriting_values_spec.rb +87 -0
- data/spec/cascading_configuration/core/module_spec.rb +491 -0
- data/spec/cascading_configuration/hash_spec.rb +826 -0
- data/spec/cascading_configuration/setting_spec.rb +687 -0
- data/spec/cascading_configuration_spec.rb +58 -0
- metadata +185 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
|
2
|
+
class ::CascadingConfiguration::Core::InstanceController::SupportModule < ::Module
|
3
|
+
|
4
|
+
# Peripheral method modules for configuration encapsulations.
|
5
|
+
#
|
6
|
+
# Currently CascadingConfiguration uses three types in the :cascading_configuration encapsulation:
|
7
|
+
#
|
8
|
+
# * Module Support - which cascade through includes and the first extend.
|
9
|
+
# * Instance Support - which cascade through includes
|
10
|
+
# * Local Instance Support - which do not cascade
|
11
|
+
|
12
|
+
################
|
13
|
+
# initialize #
|
14
|
+
################
|
15
|
+
|
16
|
+
def initialize( instance_controller, encapsulation_or_name, module_type_name )
|
17
|
+
|
18
|
+
encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( encapsulation_or_name )
|
19
|
+
|
20
|
+
@instance_controller = instance_controller
|
21
|
+
@encapsulation = encapsulation
|
22
|
+
@module_type_name = module_type_name
|
23
|
+
|
24
|
+
@included = ::UniqueArray.new( self )
|
25
|
+
@extended = ::UniqueArray.new( self )
|
26
|
+
|
27
|
+
# include modules like ourselves above us
|
28
|
+
existing_super_modules = super_modules
|
29
|
+
unless existing_super_modules.empty?
|
30
|
+
# Modules are gathered from lowest ancestor upward. This means that they are already
|
31
|
+
# in the proper order for include/extend (which usually we would have to reverse).
|
32
|
+
include *existing_super_modules
|
33
|
+
end
|
34
|
+
|
35
|
+
cascade_new_support_for_child_modules
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
##############
|
40
|
+
# included #
|
41
|
+
##############
|
42
|
+
|
43
|
+
def included( class_or_module )
|
44
|
+
|
45
|
+
super
|
46
|
+
|
47
|
+
@included.push( class_or_module )
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
##############
|
52
|
+
# extended #
|
53
|
+
##############
|
54
|
+
|
55
|
+
def extended( class_or_module_or_instance )
|
56
|
+
|
57
|
+
super
|
58
|
+
|
59
|
+
@extended.push( class_or_module_or_instance )
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
###############
|
64
|
+
# included? #
|
65
|
+
###############
|
66
|
+
|
67
|
+
def included?( class_or_module )
|
68
|
+
|
69
|
+
return @included.include?( class_or_module )
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
###############
|
74
|
+
# extended? #
|
75
|
+
###############
|
76
|
+
|
77
|
+
def extended?( class_or_module_or_instance )
|
78
|
+
|
79
|
+
return @extended.include?( class_or_module_or_instance )
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
###################
|
84
|
+
# super_modules #
|
85
|
+
###################
|
86
|
+
|
87
|
+
def super_modules
|
88
|
+
|
89
|
+
ancestor_controller = nil
|
90
|
+
|
91
|
+
return @encapsulation.lowest_parents( @instance_controller.instance ) do |this_parent|
|
92
|
+
|
93
|
+
ancestor_controller = ::CascadingConfiguration::Core::InstanceController.instance_controller( this_parent )
|
94
|
+
|
95
|
+
if ancestor_controller and
|
96
|
+
ancestor_support = ancestor_controller.support( @module_type_name, @encapsulation ) and
|
97
|
+
is_super_module?( ancestor_support )
|
98
|
+
|
99
|
+
true
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
false
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end.collect do |this_ancestor|
|
108
|
+
|
109
|
+
ancestor_controller = ::CascadingConfiguration::Core::InstanceController.instance_controller( this_ancestor )
|
110
|
+
|
111
|
+
ancestor_controller.support( @module_type_name, @encapsulation )
|
112
|
+
|
113
|
+
end.uniq
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
######################
|
118
|
+
# is_super_module? #
|
119
|
+
######################
|
120
|
+
|
121
|
+
def is_super_module?( module_instance )
|
122
|
+
|
123
|
+
is_super_module = false
|
124
|
+
|
125
|
+
if module_instance.is_a?( self.class )
|
126
|
+
is_super_module = true
|
127
|
+
end
|
128
|
+
|
129
|
+
return is_super_module
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
###################
|
134
|
+
# child_modules #
|
135
|
+
###################
|
136
|
+
|
137
|
+
def child_modules
|
138
|
+
|
139
|
+
ancestor_controller = nil
|
140
|
+
|
141
|
+
return @encapsulation.highest_children( @instance_controller.instance ) do |this_child|
|
142
|
+
|
143
|
+
ancestor_controller = ::CascadingConfiguration::Core::InstanceController.instance_controller( this_child )
|
144
|
+
|
145
|
+
if ancestor_controller and
|
146
|
+
ancestor_controller.support( @module_type_name, @encapsulation )
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
|
152
|
+
end.collect do |this_ancestor|
|
153
|
+
|
154
|
+
ancestor_controller = ::CascadingConfiguration::Core::InstanceController.instance_controller( this_ancestor )
|
155
|
+
|
156
|
+
ancestor_controller.support( @module_type_name, @encapsulation )
|
157
|
+
|
158
|
+
end.uniq
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
###########################################
|
163
|
+
# cascade_new_support_for_child_modules #
|
164
|
+
###########################################
|
165
|
+
|
166
|
+
def cascade_new_support_for_child_modules
|
167
|
+
|
168
|
+
reference_to_self = self
|
169
|
+
|
170
|
+
@included.each do |this_class_or_module|
|
171
|
+
this_class_or_module.module_eval do
|
172
|
+
include( reference_to_self )
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
@extended.each do |this_class_or_module_or_instance|
|
177
|
+
this_class_or_module_or_instance.extend( self )
|
178
|
+
end
|
179
|
+
|
180
|
+
child_modules.each do |this_child_module|
|
181
|
+
|
182
|
+
this_child_module.module_eval do
|
183
|
+
include( reference_to_self )
|
184
|
+
end
|
185
|
+
|
186
|
+
# and continue down this tree
|
187
|
+
this_child_module.cascade_new_support_for_child_modules
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
return self
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
###################
|
196
|
+
# define_method #
|
197
|
+
###################
|
198
|
+
|
199
|
+
# redefined to make public
|
200
|
+
def define_method( method_name, *args, & block )
|
201
|
+
|
202
|
+
return super
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
##################
|
207
|
+
# alias_method #
|
208
|
+
##################
|
209
|
+
|
210
|
+
# redefined to make public
|
211
|
+
def alias_method( alias_name, method_name )
|
212
|
+
|
213
|
+
return super
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
###################
|
218
|
+
# remove_method #
|
219
|
+
###################
|
220
|
+
|
221
|
+
# redefined to make public
|
222
|
+
def remove_method( method_name )
|
223
|
+
|
224
|
+
removed = false
|
225
|
+
|
226
|
+
if method_defined?( method_name )
|
227
|
+
super
|
228
|
+
removed = true
|
229
|
+
end
|
230
|
+
|
231
|
+
return removed
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
##################
|
236
|
+
# undef_method #
|
237
|
+
##################
|
238
|
+
|
239
|
+
# redefined to make public
|
240
|
+
def undef_method( method_name )
|
241
|
+
|
242
|
+
undefined = false
|
243
|
+
|
244
|
+
if method_defined?( method_name )
|
245
|
+
super
|
246
|
+
undefined = true
|
247
|
+
end
|
248
|
+
|
249
|
+
return undefined
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|