cascading_configuration 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,208 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../lib/cascading_configuration.rb'
|
3
|
+
|
4
|
+
describe ::CascadingConfiguration::Core::Encapsulation do
|
5
|
+
|
6
|
+
########################
|
7
|
+
# initialize #
|
8
|
+
# self.encapsulation #
|
9
|
+
########################
|
10
|
+
|
11
|
+
it 'can initialize as an independent encapsulation of its features' do
|
12
|
+
module ::CascadingConfiguration::Core::Encapsulation::InitializeMock
|
13
|
+
Encapsulation = ::CascadingConfiguration::Core::Encapsulation.new( :encapsulation_name )
|
14
|
+
Encapsulation.encapsulation_name.should == :encapsulation_name
|
15
|
+
::CascadingConfiguration::Core::Encapsulation.encapsulation( :encapsulation_name ).should == Encapsulation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
############################
|
20
|
+
# register_configuration #
|
21
|
+
# has_configurations? #
|
22
|
+
# has_configuration? #
|
23
|
+
# configuration_names #
|
24
|
+
# remove_configuration #
|
25
|
+
############################
|
26
|
+
|
27
|
+
it 'can hold configurations' do
|
28
|
+
module ::CascadingConfiguration::Core::Encapsulation::ConfigurationsMock
|
29
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
30
|
+
ForInstance = ::Module.new
|
31
|
+
CCMMock = ::Module.new do
|
32
|
+
def self.create_configuration( encapsulation, instance, this_name )
|
33
|
+
end
|
34
|
+
def self.initialize_configuration( encapsulation, instance, this_name )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
Encapsulation.instance_eval do
|
38
|
+
has_configurations?( ForInstance ).should == false
|
39
|
+
has_configuration?( ForInstance, :some_configuration ).should == false
|
40
|
+
configuration_names( ForInstance ).should == [ ]
|
41
|
+
register_configuration( ForInstance, :some_configuration, CCMMock )
|
42
|
+
has_configurations?( ForInstance ).should == true
|
43
|
+
has_configuration?( ForInstance, :some_configuration ).should == true
|
44
|
+
configuration_names( ForInstance ).should == [ :some_configuration ]
|
45
|
+
remove_configuration( ForInstance, :some_configuration )
|
46
|
+
has_configurations?( ForInstance ).should == false
|
47
|
+
has_configuration?( ForInstance, :some_configuration ).should == false
|
48
|
+
configuration_names( ForInstance ).should == [ ]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#######################################
|
54
|
+
# register_child_for_parent #
|
55
|
+
# parent_for_configuration #
|
56
|
+
# register_parent_for_configuration #
|
57
|
+
#######################################
|
58
|
+
|
59
|
+
it 'can register children for parents' do
|
60
|
+
module ::CascadingConfiguration::Core::Encapsulation::ParentsMock
|
61
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
62
|
+
CCMMock = ::Module.new do
|
63
|
+
def self.create_configuration( encapsulation, instance, this_name )
|
64
|
+
end
|
65
|
+
def self.initialize_configuration( encapsulation, instance, this_name )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
Parent = ::Module.new
|
69
|
+
Child = ::Module.new
|
70
|
+
AnotherParent = ::Module.new
|
71
|
+
Encapsulation.module_eval do
|
72
|
+
register_configuration( Parent, :some_configuration, CCMMock )
|
73
|
+
register_child_for_parent( Child, Parent )
|
74
|
+
has_configuration?( Child, :some_configuration ).should == true
|
75
|
+
parent_for_configuration( Child, :some_configuration ).should == Parent
|
76
|
+
register_configuration( Child, :some_other_configuration, CCMMock )
|
77
|
+
register_parent_for_configuration( Child, AnotherParent, :some_other_configuration )
|
78
|
+
has_configuration?( Child, :some_other_configuration ).should == true
|
79
|
+
parent_for_configuration( Child, :some_other_configuration ).should == AnotherParent
|
80
|
+
parents( Child ).include?( AnotherParent ).should == true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
##############################
|
86
|
+
# parent_for_configuration #
|
87
|
+
##############################
|
88
|
+
|
89
|
+
it 'can find the next ancestor for a configuration name' do
|
90
|
+
module ::CascadingConfiguration::Core::Encapsulation::ParentForConfigurationMock
|
91
|
+
|
92
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
93
|
+
|
94
|
+
CCMMock = ::Module.new do
|
95
|
+
def self.create_configuration( encapsulation, instance, this_name )
|
96
|
+
end
|
97
|
+
def self.initialize_configuration( encapsulation, instance, this_name )
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
module MockA
|
102
|
+
class << self
|
103
|
+
attr_accessor :config_A
|
104
|
+
end
|
105
|
+
end
|
106
|
+
Encapsulation.register_configuration( MockA, :config_A, CCMMock )
|
107
|
+
|
108
|
+
module MockB
|
109
|
+
class << self
|
110
|
+
attr_accessor :config_A, :config_B
|
111
|
+
end
|
112
|
+
end
|
113
|
+
Encapsulation.register_child_for_parent( MockB, MockA )
|
114
|
+
Encapsulation.register_configuration( MockB, :config_A, CCMMock )
|
115
|
+
Encapsulation.register_configuration( MockB, :config_B, CCMMock )
|
116
|
+
|
117
|
+
module MockC1
|
118
|
+
class << self
|
119
|
+
attr_accessor :config_A, :config_B, :config_C1
|
120
|
+
end
|
121
|
+
end
|
122
|
+
Encapsulation.register_child_for_parent( MockC1, MockB )
|
123
|
+
Encapsulation.register_configuration( MockC1, :config_A, CCMMock )
|
124
|
+
Encapsulation.register_configuration( MockC1, :config_B, CCMMock )
|
125
|
+
Encapsulation.register_configuration( MockC1, :config_C1, CCMMock )
|
126
|
+
|
127
|
+
module MockC2
|
128
|
+
class << self
|
129
|
+
attr_accessor :config_A, :config_B, :config_C2
|
130
|
+
end
|
131
|
+
end
|
132
|
+
Encapsulation.register_child_for_parent( MockC2, MockB )
|
133
|
+
Encapsulation.register_configuration( MockC2, :config_A, CCMMock )
|
134
|
+
Encapsulation.register_configuration( MockC2, :config_B, CCMMock )
|
135
|
+
Encapsulation.register_configuration( MockC2, :config_C2, CCMMock )
|
136
|
+
|
137
|
+
module MockD
|
138
|
+
class << self
|
139
|
+
attr_accessor :config_A, :config_B, :config_C1, :config_C2
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
Encapsulation.instance_eval do
|
144
|
+
|
145
|
+
register_child_for_parent( MockD, MockC1 )
|
146
|
+
register_child_for_parent( MockD, MockC2 )
|
147
|
+
register_configuration( MockD, :config_A, CCMMock )
|
148
|
+
register_configuration( MockD, :config_B, CCMMock )
|
149
|
+
register_configuration( MockD, :config_C1, CCMMock )
|
150
|
+
register_configuration( MockD, :config_C2, CCMMock )
|
151
|
+
|
152
|
+
parent_for_configuration( MockD, :config_A ).should == MockC2
|
153
|
+
parent_for_configuration( MockD, :config_B ).should == MockC2
|
154
|
+
parent_for_configuration( MockD, :config_C1 ).should == MockC1
|
155
|
+
parent_for_configuration( MockD, :config_C2 ).should == MockC2
|
156
|
+
|
157
|
+
parent_for_configuration( MockC2, :config_A ).should == MockB
|
158
|
+
parent_for_configuration( MockC2, :config_B ).should == MockB
|
159
|
+
parent_for_configuration( MockC2, :config_C1 ).should == nil
|
160
|
+
parent_for_configuration( MockC2, :config_C2 ).should == nil
|
161
|
+
|
162
|
+
parent_for_configuration( MockC1, :config_A ).should == MockB
|
163
|
+
parent_for_configuration( MockC1, :config_B ).should == MockB
|
164
|
+
parent_for_configuration( MockC1, :config_C1 ).should == nil
|
165
|
+
parent_for_configuration( MockC1, :config_C2 ).should == nil
|
166
|
+
|
167
|
+
parent_for_configuration( MockB, :config_A ).should == MockA
|
168
|
+
parent_for_configuration( MockB, :config_B ).should == nil
|
169
|
+
parent_for_configuration( MockB, :config_C1 ).should == nil
|
170
|
+
parent_for_configuration( MockB, :config_C2 ).should == nil
|
171
|
+
|
172
|
+
parent_for_configuration( MockA, :config_A ).should == nil
|
173
|
+
parent_for_configuration( MockA, :config_B ).should == nil
|
174
|
+
parent_for_configuration( MockA, :config_C1 ).should == nil
|
175
|
+
parent_for_configuration( MockA, :config_C2 ).should == nil
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
###################################
|
184
|
+
# set_configuration #
|
185
|
+
# get_configuration #
|
186
|
+
# has_configuration_value? #
|
187
|
+
# configuration_variables #
|
188
|
+
# remove_configuration_variable #
|
189
|
+
###################################
|
190
|
+
|
191
|
+
it 'can set, get and remove configuration variables' do
|
192
|
+
module ::CascadingConfiguration::Core::Encapsulation::ConfigurationVariableMock
|
193
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
194
|
+
ForInstance = ::Module.new
|
195
|
+
Encapsulation.instance_eval do
|
196
|
+
has_configuration_value?( ForInstance, :some_variable ).should == false
|
197
|
+
set_configuration( ForInstance, :some_variable, :some_value )
|
198
|
+
has_configuration_value?( ForInstance, :some_variable ).should == true
|
199
|
+
get_configuration( ForInstance, :some_variable ).should == :some_value
|
200
|
+
configuration_variables( ForInstance ).should == { :some_variable => :some_value }
|
201
|
+
remove_configuration_variable( ForInstance, :some_variable )
|
202
|
+
configuration_variables( ForInstance ).should == { }
|
203
|
+
has_configuration_value?( ForInstance, :some_variable ).should == false
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/cascading_configuration.rb'
|
3
|
+
|
4
|
+
describe ::CascadingConfiguration::Core::InstanceController::ExtensionModule do
|
5
|
+
|
6
|
+
################
|
7
|
+
# initialize #
|
8
|
+
################
|
9
|
+
|
10
|
+
it 'can create a module for use with an instance for dynamic definition' do
|
11
|
+
module ::CascadingConfiguration::Core::InstanceController::ExtensionModule::InitializeMock
|
12
|
+
|
13
|
+
ForInstance = ::Module.new
|
14
|
+
InstanceController = ::CascadingConfiguration::Core::InstanceController.new( ForInstance )
|
15
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
16
|
+
|
17
|
+
Module_instance = ::CascadingConfiguration::Core::InstanceController::ExtensionModule.new( InstanceController, Encapsulation, :some_configuration )
|
18
|
+
|
19
|
+
Module_instance.instance_controller.should == InstanceController
|
20
|
+
Module_instance.encapsulation.should == Encapsulation
|
21
|
+
Module_instance.configuration_name.should == :some_configuration
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/cascading_configuration.rb'
|
3
|
+
|
4
|
+
describe ::CascadingConfiguration::Core::InstanceController::SupportModule do
|
5
|
+
|
6
|
+
################
|
7
|
+
# initialize #
|
8
|
+
################
|
9
|
+
|
10
|
+
it 'can create a module for use with an instance for dynamic definition' do
|
11
|
+
module ::CascadingConfiguration::Core::InstanceController::SupportModule::InitializeMock
|
12
|
+
ForInstance = ::Module.new
|
13
|
+
InstanceController = ::CascadingConfiguration::Core::InstanceController.new( ForInstance )
|
14
|
+
Encapsulation = ::CascadingConfiguration::Core::Encapsulation.new( :some_encapsulation )
|
15
|
+
Module_instance = ::CascadingConfiguration::Core::InstanceController::SupportModule.new( InstanceController, Encapsulation, :some_type )
|
16
|
+
ForInstance.ancestors.include?( Module_instance ).should == false
|
17
|
+
ForInstance.is_a?( Module_instance ).should == false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
###################
|
22
|
+
# super_modules #
|
23
|
+
###################
|
24
|
+
|
25
|
+
it 'can return the first super module on each parent tree' do
|
26
|
+
module ::CascadingConfiguration::Core::InstanceController::SuperModulesMock
|
27
|
+
|
28
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
29
|
+
|
30
|
+
CCMMock = ::Module.new do
|
31
|
+
def self.create_configuration( encapsulation, instance, this_name )
|
32
|
+
end
|
33
|
+
def self.initialize_configuration( encapsulation, instance, this_name )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# set up hierarchy
|
38
|
+
ForInstance_A = ::Module.new
|
39
|
+
Encapsulation.register_configuration( ForInstance_A, :some_configuration, CCMMock )
|
40
|
+
InstanceController_A = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_A )
|
41
|
+
|
42
|
+
Module_A = InstanceController_A.create_support( :some_type )
|
43
|
+
ForInstance_B1 = ::Module.new do
|
44
|
+
include ForInstance_A
|
45
|
+
end
|
46
|
+
Encapsulation.register_configuration( ForInstance_B1, :some_other_configuration, CCMMock )
|
47
|
+
Encapsulation.register_child_for_parent( ForInstance_B1, ForInstance_A )
|
48
|
+
ForInstance_B2 = ::Module.new do
|
49
|
+
include ForInstance_A
|
50
|
+
end
|
51
|
+
Encapsulation.register_child_for_parent( ForInstance_B2, ForInstance_A )
|
52
|
+
ForInstance_C1 = ::Module.new do
|
53
|
+
include ForInstance_B1
|
54
|
+
end
|
55
|
+
Encapsulation.register_configuration( ForInstance_C1, :yet_another_configuration, CCMMock )
|
56
|
+
Encapsulation.register_child_for_parent( ForInstance_C1, ForInstance_B1 )
|
57
|
+
ForInstance_C2 = ::Module.new do
|
58
|
+
include ForInstance_B1
|
59
|
+
end
|
60
|
+
Encapsulation.register_child_for_parent( ForInstance_C2, ForInstance_B1 )
|
61
|
+
ForInstance_D = ::Module.new do
|
62
|
+
include ForInstance_B2
|
63
|
+
include ForInstance_C1
|
64
|
+
include ForInstance_C2
|
65
|
+
end
|
66
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_B2 )
|
67
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C1 )
|
68
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C2 )
|
69
|
+
Module_A.super_modules.empty?.should == true
|
70
|
+
InstanceController_B2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B2 )
|
71
|
+
Module_B2 = InstanceController_B2.create_support( :some_type )
|
72
|
+
Module_B2.super_modules.should == [ Module_A ]
|
73
|
+
InstanceController_C1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C1 )
|
74
|
+
Module_C1 = InstanceController_C1.create_support( :some_type )
|
75
|
+
Module_B2.super_modules.should == [ Module_A ]
|
76
|
+
Module_C1.super_modules.should == [ Module_A ]
|
77
|
+
InstanceController_C2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C2 )
|
78
|
+
Module_C2 = InstanceController_C2.create_support( :some_type )
|
79
|
+
Module_B2.super_modules.should == [ Module_A ]
|
80
|
+
Module_C1.super_modules.should == [ Module_A ]
|
81
|
+
Module_C2.super_modules.should == [ Module_A ]
|
82
|
+
InstanceController_B1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B1 )
|
83
|
+
Module_B1 = InstanceController_B1.create_support( :some_type )
|
84
|
+
Module_B1.super_modules.should == [ Module_A ]
|
85
|
+
Module_B2.super_modules.should == [ Module_A ]
|
86
|
+
Module_C1.super_modules.should == [ Module_B1 ]
|
87
|
+
Module_C2.super_modules.should == [ Module_B1 ]
|
88
|
+
InstanceController_D = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_D )
|
89
|
+
Module_D = InstanceController_D.create_support( :some_type )
|
90
|
+
Module_B1.super_modules.should == [ Module_A ]
|
91
|
+
Module_B2.super_modules.should == [ Module_A ]
|
92
|
+
Module_C1.super_modules.should == [ Module_B1 ]
|
93
|
+
Module_C2.super_modules.should == [ Module_B1 ]
|
94
|
+
Module_D.super_modules.should == [ Module_C2, Module_C1, Module_B2 ]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
###################
|
99
|
+
# child_modules #
|
100
|
+
###################
|
101
|
+
|
102
|
+
it 'can return the first child module on each child tree' do
|
103
|
+
module ::CascadingConfiguration::Core::InstanceController::ChildModulesMock
|
104
|
+
|
105
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
106
|
+
|
107
|
+
# set up hierarchy
|
108
|
+
ForInstance_A = ::Module.new do
|
109
|
+
# we have to mock the method bc that's how the module determines if it has a configuration defined
|
110
|
+
# since we don't know whether a configuration value has been set yet
|
111
|
+
attr_accessor :some_configuration
|
112
|
+
end
|
113
|
+
InstanceController_A = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_A )
|
114
|
+
Module_A = InstanceController_A.create_support( :some_type )
|
115
|
+
ForInstance_B1 = ::Module.new do
|
116
|
+
# we have to mock the method bc that's how the module determines if it has a configuration defined
|
117
|
+
# since we don't know whether a configuration value has been set yet
|
118
|
+
attr_accessor :some_other_configuration
|
119
|
+
include ForInstance_A
|
120
|
+
end
|
121
|
+
Encapsulation.register_child_for_parent( ForInstance_B1, ForInstance_A )
|
122
|
+
ForInstance_B2 = ::Module.new do
|
123
|
+
include ForInstance_A
|
124
|
+
end
|
125
|
+
Encapsulation.register_child_for_parent( ForInstance_B2, ForInstance_A )
|
126
|
+
ForInstance_C1 = ::Module.new do
|
127
|
+
include ForInstance_B1
|
128
|
+
attr_accessor :yet_another_configuration
|
129
|
+
end
|
130
|
+
Encapsulation.register_child_for_parent( ForInstance_C1, ForInstance_B1 )
|
131
|
+
ForInstance_C2 = ::Module.new do
|
132
|
+
include ForInstance_B1
|
133
|
+
end
|
134
|
+
Encapsulation.register_child_for_parent( ForInstance_C2, ForInstance_B1 )
|
135
|
+
ForInstance_D = ::Module.new do
|
136
|
+
include ForInstance_B2
|
137
|
+
include ForInstance_C1
|
138
|
+
include ForInstance_C2
|
139
|
+
end
|
140
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_B2 )
|
141
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C1 )
|
142
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C2 )
|
143
|
+
InstanceController_B2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B2 )
|
144
|
+
Module_B2 = InstanceController_B2.create_support( :some_type )
|
145
|
+
InstanceController_C1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C1 )
|
146
|
+
Module_C1 = InstanceController_C1.create_support( :some_type )
|
147
|
+
InstanceController_C2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C2 )
|
148
|
+
Module_C2 = InstanceController_C2.create_support( :some_type )
|
149
|
+
InstanceController_B1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B1 )
|
150
|
+
Module_B1 = InstanceController_B1.create_support( :some_type )
|
151
|
+
InstanceController_D = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_D )
|
152
|
+
Module_D = InstanceController_D.create_support( :some_type )
|
153
|
+
Module_A.child_modules.should == [ Module_B1, Module_B2 ]
|
154
|
+
Module_B1.child_modules.should == [ Module_C1, Module_C2 ]
|
155
|
+
Module_B2.child_modules.should == [ Module_D ]
|
156
|
+
Module_C1.child_modules.should == [ Module_D ]
|
157
|
+
Module_C2.child_modules.should == [ Module_D ]
|
158
|
+
Module_D.child_modules.empty?.should == true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
###########################################
|
163
|
+
# cascade_new_support_for_child_modules #
|
164
|
+
###########################################
|
165
|
+
|
166
|
+
it 'can return the first child module on each child tree' do
|
167
|
+
module ::CascadingConfiguration::Core::InstanceController::CascadeNewSupportForChildModulesMock
|
168
|
+
|
169
|
+
Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
|
170
|
+
|
171
|
+
# set up hierarchy
|
172
|
+
ForInstance_A = ::Module.new do
|
173
|
+
# we have to mock the method bc that's how the module determines if it has a configuration defined
|
174
|
+
# since we don't know whether a configuration value has been set yet
|
175
|
+
attr_accessor :some_configuration
|
176
|
+
end
|
177
|
+
InstanceController_A = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_A )
|
178
|
+
Module_A = InstanceController_A.create_support( :some_type )
|
179
|
+
ForInstance_B1 = ::Module.new do
|
180
|
+
# we have to mock the method bc that's how the module determines if it has a configuration defined
|
181
|
+
# since we don't know whether a configuration value has been set yet
|
182
|
+
attr_accessor :some_other_configuration
|
183
|
+
include ForInstance_A
|
184
|
+
end
|
185
|
+
Encapsulation.register_child_for_parent( ForInstance_B1, ForInstance_A )
|
186
|
+
ForInstance_B2 = ::Module.new do
|
187
|
+
include ForInstance_A
|
188
|
+
end
|
189
|
+
Encapsulation.register_child_for_parent( ForInstance_B2, ForInstance_A )
|
190
|
+
ForInstance_C1 = ::Module.new do
|
191
|
+
include ForInstance_B1
|
192
|
+
attr_accessor :yet_another_configuration
|
193
|
+
end
|
194
|
+
Encapsulation.register_child_for_parent( ForInstance_C1, ForInstance_B1 )
|
195
|
+
ForInstance_C2 = ::Module.new do
|
196
|
+
include ForInstance_B1
|
197
|
+
end
|
198
|
+
Encapsulation.register_child_for_parent( ForInstance_C2, ForInstance_B1 )
|
199
|
+
ForInstance_D = ::Module.new do
|
200
|
+
include ForInstance_B2
|
201
|
+
include ForInstance_C1
|
202
|
+
include ForInstance_C2
|
203
|
+
end
|
204
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_B2 )
|
205
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C1 )
|
206
|
+
Encapsulation.register_child_for_parent( ForInstance_D, ForInstance_C2 )
|
207
|
+
Module_A.child_modules.empty?.should == true
|
208
|
+
InstanceController_C2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C2 )
|
209
|
+
Module_C2 = InstanceController_C2.create_support( :some_type )
|
210
|
+
Module_A.child_modules.should == [ Module_C2 ]
|
211
|
+
Module_C2.child_modules.empty?.should == true
|
212
|
+
InstanceController_B2 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B2 )
|
213
|
+
Module_B2 = InstanceController_B2.create_support( :some_type )
|
214
|
+
Module_A.child_modules.should == [ Module_C2, Module_B2 ]
|
215
|
+
Module_B2.child_modules.empty?.should == true
|
216
|
+
Module_C2.child_modules.empty?.should == true
|
217
|
+
InstanceController_C1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_C1 )
|
218
|
+
Module_C1 = InstanceController_C1.create_support( :some_type )
|
219
|
+
Module_A.child_modules.should == [ Module_C1, Module_C2, Module_B2 ]
|
220
|
+
Module_B2.child_modules.empty?.should == true
|
221
|
+
Module_C1.child_modules.empty?.should == true
|
222
|
+
Module_C2.child_modules.empty?.should == true
|
223
|
+
InstanceController_D = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_D )
|
224
|
+
Module_D = InstanceController_D.create_support( :some_type )
|
225
|
+
Module_A.child_modules.should == [ Module_C1, Module_C2, Module_B2 ]
|
226
|
+
Module_B2.child_modules.should == [ Module_D ]
|
227
|
+
Module_C1.child_modules.should == [ Module_D ]
|
228
|
+
Module_C2.child_modules.should == [ Module_D ]
|
229
|
+
Module_D.child_modules.empty?.should == true
|
230
|
+
InstanceController_B1 = ::CascadingConfiguration::Core::InstanceController.new( ForInstance_B1 )
|
231
|
+
Module_B1 = InstanceController_B1.create_support( :some_type )
|
232
|
+
Module_A.child_modules.should == [ Module_B1, Module_B2 ]
|
233
|
+
Module_B1.child_modules.should == [ Module_C1, Module_C2 ]
|
234
|
+
Module_B2.child_modules.should == [ Module_D ]
|
235
|
+
Module_C1.child_modules.should == [ Module_D ]
|
236
|
+
Module_C2.child_modules.should == [ Module_D ]
|
237
|
+
Module_D.child_modules.empty?.should == true
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
###################
|
242
|
+
# define_method #
|
243
|
+
# alias_method #
|
244
|
+
# remove_method #
|
245
|
+
# undef_method #
|
246
|
+
###################
|
247
|
+
|
248
|
+
it 'can define a method in the configuration module, ensuring the module exists first' do
|
249
|
+
module ::CascadingConfiguration::Core::InstanceController::DefineAliasRemoveUndefMock
|
250
|
+
ForInstance = ::Module.new
|
251
|
+
InstanceController = ::CascadingConfiguration::Core::InstanceController.new( ForInstance )
|
252
|
+
Module_instance = InstanceController.create_support( :some_type )
|
253
|
+
Module_instance.define_method( :some_method ) do
|
254
|
+
return :some_method
|
255
|
+
end
|
256
|
+
Module_instance.method_defined?( :some_method ).should == true
|
257
|
+
Module_instance.alias_method( :some_alias, :some_method )
|
258
|
+
Module_instance.method_defined?( :some_method ).should == true
|
259
|
+
Module_instance.method_defined?( :some_alias ).should == true
|
260
|
+
Module_instance.remove_method( :some_alias ).should == true
|
261
|
+
Module_instance.method_defined?( :some_alias ).should == false
|
262
|
+
Module_instance.remove_method( :some_alias ).should == false
|
263
|
+
Module_instance.undef_method( :some_method ).should == true
|
264
|
+
Module_instance.method_defined?( :some_method ).should == false
|
265
|
+
Module_instance.undef_method( :some_method ).should == false
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|