cascading-configuration-hash 1.6.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cascading-configuration-hash.rb +5 -5
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb +28 -28
- data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb +223 -111
- data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/Interface/GettersSetters.rb +16 -16
- data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb +5 -5
- data/spec/CascadingConfiguration/Hash_spec.rb +17 -19
- data/spec/_private_/CascadingConfiguration/Hash/CompositingHash_spec.rb +266 -216
- metadata +6 -8
- data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash/LocalConfigurationHash.rb +0 -110
- data/spec/_private_/CascadingConfiguration/Hash/CompositingHash/LocalConfigurationHash_spec.rb +0 -95
@@ -11,12 +11,12 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
11
11
|
|
12
12
|
hash_setter_proc = Proc.new do |hash|
|
13
13
|
|
14
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
14
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
::CascadingConfiguration::Variable.define_module_method( self, configuration_setter_name, & hash_setter_proc )
|
19
|
+
::CascadingConfiguration::Variable.define_instance_method_if_support_exists( self, configuration_setter_name, & hash_setter_proc )
|
20
20
|
|
21
21
|
end
|
22
22
|
|
@@ -30,12 +30,12 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
30
30
|
|
31
31
|
hash_getter_proc = Proc.new do
|
32
32
|
|
33
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
33
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
::CascadingConfiguration::Variable.define_module_method( self, configuration_getter_name, & hash_getter_proc )
|
38
|
+
::CascadingConfiguration::Variable.define_instance_method_if_support_exists( self, configuration_getter_name, & hash_getter_proc )
|
39
39
|
|
40
40
|
end
|
41
41
|
|
@@ -49,7 +49,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
49
49
|
|
50
50
|
::CascadingConfiguration::Variable.define_module_method( self, configuration_setter_name ) do |hash|
|
51
51
|
|
52
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
52
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
53
53
|
|
54
54
|
end
|
55
55
|
|
@@ -65,7 +65,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
65
65
|
|
66
66
|
::CascadingConfiguration::Variable.define_module_method( self, configuration_getter_name ) do
|
67
67
|
|
68
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
68
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
69
69
|
|
70
70
|
end
|
71
71
|
|
@@ -81,12 +81,12 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
81
81
|
|
82
82
|
local_setter_proc = Proc.new do |hash|
|
83
83
|
|
84
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
84
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
85
85
|
|
86
86
|
end
|
87
87
|
|
88
88
|
::CascadingConfiguration::Variable.define_local_instance_method( self, configuration_setter_name, & local_setter_proc )
|
89
|
-
|
89
|
+
::CascadingConfiguration::Variable.define_instance_method_if_support_exists( self, configuration_setter_name, & local_setter_proc )
|
90
90
|
|
91
91
|
end
|
92
92
|
|
@@ -100,12 +100,12 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
100
100
|
|
101
101
|
local_getter_proc = Proc.new do
|
102
102
|
|
103
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
103
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
104
104
|
|
105
105
|
end
|
106
106
|
|
107
107
|
::CascadingConfiguration::Variable.define_local_instance_method( self, configuration_getter_name, & local_getter_proc )
|
108
|
-
|
108
|
+
::CascadingConfiguration::Variable.define_instance_method_if_support_exists( self, configuration_getter_name, & local_getter_proc )
|
109
109
|
|
110
110
|
end
|
111
111
|
|
@@ -119,7 +119,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
119
119
|
|
120
120
|
::CascadingConfiguration::Variable.define_instance_method( self, configuration_setter_name ) do |hash|
|
121
121
|
|
122
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
122
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
123
123
|
|
124
124
|
end
|
125
125
|
|
@@ -135,7 +135,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
135
135
|
|
136
136
|
::CascadingConfiguration::Variable.define_instance_method( self, configuration_getter_name ) do
|
137
137
|
|
138
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
138
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
139
139
|
|
140
140
|
end
|
141
141
|
|
@@ -151,7 +151,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
151
151
|
|
152
152
|
::CascadingConfiguration::Variable.define_local_instance_method( self, configuration_setter_name ) do |hash|
|
153
153
|
|
154
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
154
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
|
155
155
|
|
156
156
|
end
|
157
157
|
|
@@ -167,7 +167,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
|
|
167
167
|
|
168
168
|
::CascadingConfiguration::Variable.define_local_instance_method( self, configuration_getter_name ) do
|
169
169
|
|
170
|
-
return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
170
|
+
return ::CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
|
171
171
|
|
172
172
|
end
|
173
173
|
|
data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb
CHANGED
@@ -9,11 +9,11 @@ module CascadingConfiguration::Hash::ModuleSupportMethods
|
|
9
9
|
|
10
10
|
composite_hash = nil
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
if ::CascadingConfiguration::Variable.has_configuration_variable?( configuration_instance, configuration_name )
|
13
|
+
composite_hash = ::CascadingConfiguration::Variable.get_configuration_variable( configuration_instance, configuration_name )
|
14
|
+
else
|
15
|
+
composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
16
|
+
end
|
17
17
|
|
18
18
|
return composite_hash
|
19
19
|
|
@@ -1,5 +1,9 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
if $__cascading_configuration__spec__development
|
3
|
+
require_relative '../../lib/cascading-configuration-hash.rb'
|
4
|
+
else
|
5
|
+
require 'cascading-configuration-hash'
|
6
|
+
end
|
3
7
|
|
4
8
|
describe CascadingConfiguration::Hash do
|
5
9
|
|
@@ -212,15 +216,12 @@ describe CascadingConfiguration::Hash do
|
|
212
216
|
|
213
217
|
module CascadingConfiguration::Hash::ConfigurationMockModule
|
214
218
|
include CascadingConfiguration::Hash
|
215
|
-
attr_configuration_hash :some_hash do |
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
composite_hash[ this_key ] = this_data
|
221
|
-
end
|
219
|
+
attr_configuration_hash :some_hash do |hash, key, foreign_value|
|
220
|
+
if existing_value = hash[ key ]
|
221
|
+
hash[ key ] = foreign_value - existing_value
|
222
|
+
else
|
223
|
+
hash[ key ] = foreign_value
|
222
224
|
end
|
223
|
-
composite_hash
|
224
225
|
end
|
225
226
|
self.some_hash = { :one => 1, :two => 2 }
|
226
227
|
self.some_hash.should == { :one => 1, :two => 2 }
|
@@ -229,7 +230,7 @@ describe CascadingConfiguration::Hash do
|
|
229
230
|
module CascadingConfiguration::Hash::ConfigurationMockModule2
|
230
231
|
include CascadingConfiguration::Hash::ConfigurationMockModule
|
231
232
|
self.some_hash.should == { :one => 1, :two => 2 }
|
232
|
-
self.some_hash.
|
233
|
+
self.some_hash.merge!( { :one => 1, :two => 2 } )
|
233
234
|
self.some_hash.should == { :one => 0, :two => 0 }
|
234
235
|
end
|
235
236
|
|
@@ -422,15 +423,12 @@ describe CascadingConfiguration::Hash do
|
|
422
423
|
|
423
424
|
module CascadingConfiguration::Hash::ClassConfigurationMockModule
|
424
425
|
include CascadingConfiguration::Hash
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
composite_hash[ this_key ] = this_data
|
431
|
-
end
|
426
|
+
attr_configuration_hash :some_hash do |hash, key, foreign_value|
|
427
|
+
if existing_value = hash[ key ]
|
428
|
+
hash[ key ] = foreign_value - existing_value
|
429
|
+
else
|
430
|
+
hash[ key ] = foreign_value
|
432
431
|
end
|
433
|
-
composite_hash
|
434
432
|
end
|
435
433
|
self.some_hash = { :one => 1, :two => 2 }
|
436
434
|
self.some_hash.should == { :one => 1, :two => 2 }
|
@@ -439,7 +437,7 @@ describe CascadingConfiguration::Hash do
|
|
439
437
|
module CascadingConfiguration::Hash::ClassConfigurationMockModule2
|
440
438
|
include CascadingConfiguration::Hash::ClassConfigurationMockModule
|
441
439
|
self.some_hash.should == { :one => 1, :two => 2 }
|
442
|
-
self.some_hash.
|
440
|
+
self.some_hash.merge!( { :one => 1, :two => 2 } )
|
443
441
|
self.some_hash.should == { :one => 0, :two => 0 }
|
444
442
|
end
|
445
443
|
|
@@ -1,203 +1,331 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
if $__cascading_configuration__spec__development
|
3
|
+
require_relative '../../../../lib/cascading-configuration-hash.rb'
|
4
|
+
else
|
5
|
+
require 'cascading-configuration-hash'
|
6
|
+
end
|
3
7
|
|
4
8
|
describe CascadingConfiguration::Hash::CompositingHash do
|
5
9
|
|
6
|
-
|
7
|
-
# []= #
|
8
|
-
#########
|
10
|
+
before :all do
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
module CascadingConfiguration::Hash::CompositingHash::CCHMock01
|
13
|
-
include CascadingConfiguration::Variable
|
14
|
-
end
|
15
|
-
|
16
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock01A
|
17
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock01
|
12
|
+
module CascadingConfiguration::Hash::CompositingHash::MockA
|
13
|
+
# needed for ccv ancestor determination
|
18
14
|
def self.some_configuration
|
19
15
|
end
|
20
16
|
end
|
21
|
-
module CascadingConfiguration::Hash::CompositingHash::
|
22
|
-
|
17
|
+
module CascadingConfiguration::Hash::CompositingHash::MockB
|
18
|
+
end
|
19
|
+
|
20
|
+
@configuration_instance = CascadingConfiguration::Hash::CompositingHash::MockA
|
21
|
+
@sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::MockB
|
22
|
+
|
23
|
+
@configuration_name = :some_configuration
|
24
|
+
|
25
|
+
CascadingConfiguration::Variable.register_child_for_parent( @sub_configuration_instance,
|
26
|
+
@configuration_instance )
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
################
|
31
|
+
# initialize #
|
32
|
+
################
|
33
|
+
|
34
|
+
it 'can add initialize with an ancestor, inheriting its values and linking to it as a child' do
|
35
|
+
|
36
|
+
cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
37
|
+
|
38
|
+
cascading_composite_hash.instance_variable_get( :@super_composite_hash ).should == nil
|
39
|
+
cascading_composite_hash.should == {}
|
40
|
+
cascading_composite_hash[ :A ] = 1
|
41
|
+
cascading_composite_hash[ :B ] = 2
|
42
|
+
cascading_composite_hash[ :C ] = 3
|
43
|
+
cascading_composite_hash[ :D ] = 4
|
44
|
+
cascading_composite_hash.should == { :A => 1,
|
45
|
+
:B => 2,
|
46
|
+
:C => 3,
|
47
|
+
:D => 4 }
|
48
|
+
|
49
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
50
|
+
sub_cascading_composite_hash.instance_variable_get( :@super_composite_hash ).should == cascading_composite_hash
|
51
|
+
sub_cascading_composite_hash.should == { :A => 1,
|
52
|
+
:B => 2,
|
53
|
+
:C => 3,
|
54
|
+
:D => 4 }
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
##################################################################################################
|
59
|
+
# private #####################################################################################
|
60
|
+
##################################################################################################
|
61
|
+
|
62
|
+
#########################################
|
63
|
+
# update_as_sub_hash_for_parent_store #
|
64
|
+
#########################################
|
65
|
+
|
66
|
+
it 'can update for a parent store' do
|
67
|
+
|
68
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
69
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
70
|
+
|
71
|
+
sub_cascading_composite_hash.instance_eval do
|
72
|
+
update_as_sub_hash_for_parent_store( :A, 1 )
|
73
|
+
self.should == { :A => 1 }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
##########################################
|
79
|
+
# update_as_sub_hash_for_parent_delete #
|
80
|
+
##########################################
|
81
|
+
|
82
|
+
it 'can update for a parent delete' do
|
83
|
+
|
84
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
85
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
86
|
+
|
87
|
+
cascading_composite_hash[ :A ] = 1
|
88
|
+
cascading_composite_hash.should == { :A => 1 }
|
89
|
+
sub_cascading_composite_hash.should == { :A => 1 }
|
90
|
+
|
91
|
+
sub_cascading_composite_hash.instance_eval do
|
92
|
+
update_as_sub_hash_for_parent_delete( :A )
|
93
|
+
self.should == { }
|
23
94
|
end
|
24
95
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
96
|
+
end
|
97
|
+
|
98
|
+
##################################################################################################
|
99
|
+
# public ######################################################################################
|
100
|
+
##################################################################################################
|
101
|
+
|
102
|
+
#########
|
103
|
+
# []= #
|
104
|
+
#########
|
105
|
+
|
106
|
+
it 'can add elements' do
|
107
|
+
|
108
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
109
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
30
110
|
|
31
|
-
# Without super or sub composites
|
32
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
33
111
|
cascading_composite_hash[ :some_setting ] = :some_value
|
34
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
35
112
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
113
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
114
|
+
|
36
115
|
cascading_composite_hash[ :other_setting ] = :some_value
|
37
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
38
|
-
:other_setting => :some_value }
|
39
116
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
40
117
|
:other_setting => :some_value }
|
118
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
119
|
+
:other_setting => :some_value }
|
41
120
|
|
42
|
-
# Super with a sub composite
|
43
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
44
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
45
|
-
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
46
|
-
:other_setting => :some_value }
|
47
121
|
sub_cascading_composite_hash[ :yet_another_setting ] = :some_value
|
48
|
-
|
122
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
123
|
+
:other_setting => :some_value }
|
49
124
|
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
50
125
|
:other_setting => :some_value,
|
51
126
|
:yet_another_setting => :some_value }
|
52
127
|
|
128
|
+
cascading_composite_hash.method( :[]= ).should == cascading_composite_hash.method( :store )
|
129
|
+
|
53
130
|
end
|
54
131
|
|
55
|
-
|
56
|
-
#
|
57
|
-
|
132
|
+
############
|
133
|
+
# delete #
|
134
|
+
############
|
58
135
|
|
59
|
-
it 'can
|
136
|
+
it 'can delete elements' do
|
137
|
+
|
138
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
139
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
60
140
|
|
61
|
-
module CascadingConfiguration::Hash::CompositingHash::CCHMock02
|
62
|
-
include CascadingConfiguration::Variable
|
63
|
-
end
|
64
|
-
|
65
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock02A
|
66
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock02
|
67
|
-
def self.some_configuration
|
68
|
-
end
|
69
|
-
end
|
70
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock02B
|
71
|
-
include CascadingConfiguration::Hash::CompositingHash::CIMock02A
|
72
|
-
end
|
73
|
-
|
74
|
-
ccv = CascadingConfiguration::Variable
|
75
|
-
ccm_hash = CascadingConfiguration::Hash::CompositingHash::CCHMock02
|
76
|
-
configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock02A
|
77
|
-
sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock02B
|
78
|
-
configuration_name = :some_configuration
|
79
|
-
|
80
|
-
# Without super or sub composites
|
81
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
82
141
|
cascading_composite_hash.store( :some_setting, :some_value )
|
83
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
84
142
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
143
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
144
|
+
|
85
145
|
cascading_composite_hash.store( :other_setting, :some_value )
|
86
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
87
|
-
:other_setting => :some_value }
|
88
146
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
89
147
|
:other_setting => :some_value }
|
148
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
149
|
+
:other_setting => :some_value }
|
150
|
+
|
151
|
+
cascading_composite_hash.delete( :some_setting )
|
152
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
153
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
90
154
|
|
91
|
-
# Super with a sub composite
|
92
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
93
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
94
|
-
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
95
|
-
:other_setting => :some_value }
|
96
155
|
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
97
|
-
|
98
|
-
sub_cascading_composite_hash.should == { :
|
99
|
-
:other_setting => :some_value,
|
156
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
157
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
100
158
|
:yet_another_setting => :some_value }
|
101
159
|
|
160
|
+
sub_cascading_composite_hash.delete( :other_setting )
|
161
|
+
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
162
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
163
|
+
|
102
164
|
end
|
103
165
|
|
104
|
-
|
105
|
-
#
|
106
|
-
|
166
|
+
###############
|
167
|
+
# delete_if #
|
168
|
+
###############
|
107
169
|
|
108
|
-
it 'can
|
170
|
+
it 'can delete elements with a block' do
|
109
171
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
172
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
173
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
174
|
+
|
175
|
+
cascading_composite_hash.store( :some_setting, :some_value )
|
176
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
177
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
178
|
+
|
179
|
+
cascading_composite_hash.store( :other_setting, :some_value )
|
180
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
181
|
+
:other_setting => :some_value }
|
182
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
183
|
+
:other_setting => :some_value }
|
184
|
+
cascading_composite_hash.delete_if do |key, value|
|
185
|
+
key == :some_setting
|
118
186
|
end
|
119
|
-
|
120
|
-
|
187
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
188
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
189
|
+
|
190
|
+
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
191
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
192
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
193
|
+
:yet_another_setting => :some_value }
|
194
|
+
sub_cascading_composite_hash.delete_if do |key, value|
|
195
|
+
key == :other_setting
|
121
196
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
197
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
198
|
+
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
#############
|
203
|
+
# reject! #
|
204
|
+
#############
|
205
|
+
|
206
|
+
it 'can delete elements with a block' do
|
207
|
+
|
208
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
209
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
210
|
+
|
131
211
|
cascading_composite_hash.store( :some_setting, :some_value )
|
132
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
133
212
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
213
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
214
|
+
|
134
215
|
cascading_composite_hash.store( :other_setting, :some_value )
|
135
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
136
|
-
:other_setting => :some_value }
|
137
216
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
138
217
|
:other_setting => :some_value }
|
139
|
-
|
140
|
-
|
218
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
219
|
+
:other_setting => :some_value }
|
220
|
+
cascading_composite_hash.reject! do |key, value|
|
221
|
+
key == :some_setting
|
222
|
+
end
|
141
223
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
224
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
142
225
|
|
143
|
-
# Super with a sub composite
|
144
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
145
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
146
|
-
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
147
226
|
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
148
|
-
|
227
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
149
228
|
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
150
229
|
:yet_another_setting => :some_value }
|
151
|
-
sub_cascading_composite_hash.
|
152
|
-
|
230
|
+
sub_cascading_composite_hash.reject! do |key, value|
|
231
|
+
key == :other_setting
|
232
|
+
end
|
233
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
153
234
|
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
#############
|
239
|
+
# keep_if #
|
240
|
+
#############
|
241
|
+
|
242
|
+
it 'can keep elements with a block' do
|
243
|
+
|
244
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
245
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
246
|
+
|
247
|
+
cascading_composite_hash.store( :some_setting, :some_value )
|
248
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
249
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
250
|
+
|
251
|
+
cascading_composite_hash.store( :other_setting, :some_value )
|
252
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
253
|
+
:other_setting => :some_value }
|
254
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
255
|
+
:other_setting => :some_value }
|
256
|
+
cascading_composite_hash.keep_if do |key, value|
|
257
|
+
key != :some_setting
|
258
|
+
end
|
154
259
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
260
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
261
|
+
|
262
|
+
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
263
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
264
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
265
|
+
:yet_another_setting => :some_value }
|
266
|
+
sub_cascading_composite_hash.keep_if do |key, value|
|
267
|
+
key != :other_setting
|
268
|
+
end
|
269
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
270
|
+
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
155
271
|
|
156
272
|
end
|
157
273
|
|
274
|
+
#############
|
275
|
+
# select! #
|
276
|
+
#############
|
277
|
+
|
278
|
+
it 'can keep elements with a block' do
|
279
|
+
|
280
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
281
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
282
|
+
|
283
|
+
cascading_composite_hash.store( :some_setting, :some_value )
|
284
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
285
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value }
|
286
|
+
|
287
|
+
cascading_composite_hash.store( :other_setting, :some_value )
|
288
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
289
|
+
:other_setting => :some_value }
|
290
|
+
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
291
|
+
:other_setting => :some_value }
|
292
|
+
cascading_composite_hash.select! do |key, value|
|
293
|
+
key != :some_setting
|
294
|
+
end
|
295
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
296
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
297
|
+
|
298
|
+
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
299
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
300
|
+
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
301
|
+
:yet_another_setting => :some_value }
|
302
|
+
sub_cascading_composite_hash.select! do |key, value|
|
303
|
+
key != :other_setting
|
304
|
+
end
|
305
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
306
|
+
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
307
|
+
|
308
|
+
end
|
309
|
+
|
158
310
|
############
|
159
311
|
# merge! #
|
312
|
+
# update #
|
160
313
|
############
|
161
314
|
|
162
315
|
it 'can merge from another hash' do
|
163
316
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock04A
|
169
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock04
|
170
|
-
def self.some_configuration
|
171
|
-
end
|
172
|
-
end
|
173
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock04B
|
174
|
-
include CascadingConfiguration::Hash::CompositingHash::CIMock04A
|
175
|
-
end
|
176
|
-
|
177
|
-
ccv = CascadingConfiguration::Variable
|
178
|
-
ccm_hash = CascadingConfiguration::Hash::CompositingHash::CCHMock04
|
179
|
-
configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock04A
|
180
|
-
sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock04B
|
181
|
-
configuration_name = :some_configuration
|
182
|
-
|
183
|
-
# Without super or sub composites
|
184
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
317
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
318
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
319
|
+
|
185
320
|
cascading_composite_hash.merge!( :some_setting => :some_value )
|
186
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
187
321
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
188
322
|
cascading_composite_hash.merge!( :other_setting => :some_value )
|
189
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
190
|
-
:other_setting => :some_value }
|
191
323
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
192
324
|
:other_setting => :some_value }
|
193
325
|
|
194
|
-
# Super with a sub composite
|
195
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
196
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
197
326
|
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
198
327
|
:other_setting => :some_value }
|
199
328
|
sub_cascading_composite_hash.merge!( :yet_another_setting => :some_value )
|
200
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
201
329
|
sub_cascading_composite_hash.should == { :some_setting => :some_value,
|
202
330
|
:other_setting => :some_value,
|
203
331
|
:yet_another_setting => :some_value }
|
@@ -210,40 +338,16 @@ describe CascadingConfiguration::Hash::CompositingHash do
|
|
210
338
|
|
211
339
|
it 'can replace existing elements with others' do
|
212
340
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock05A
|
218
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock05
|
219
|
-
def self.some_configuration
|
220
|
-
end
|
221
|
-
end
|
222
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock05B
|
223
|
-
include CascadingConfiguration::Hash::CompositingHash::CIMock05A
|
224
|
-
end
|
225
|
-
|
226
|
-
ccv = CascadingConfiguration::Variable
|
227
|
-
ccm_hash = CascadingConfiguration::Hash::CompositingHash::CCHMock05
|
228
|
-
configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock05A
|
229
|
-
sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock05B
|
230
|
-
configuration_name = :some_configuration
|
231
|
-
|
232
|
-
# Without super or sub composites
|
233
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
341
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
342
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
343
|
+
|
234
344
|
cascading_composite_hash.replace( :some_setting => :some_value )
|
235
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
236
345
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
237
346
|
cascading_composite_hash.replace( :other_setting => :some_value )
|
238
|
-
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
239
347
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
240
348
|
|
241
|
-
# Super with a sub composite
|
242
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
243
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
244
349
|
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
245
350
|
sub_cascading_composite_hash.replace( :yet_another_setting => :some_value )
|
246
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
247
351
|
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
248
352
|
|
249
353
|
end
|
@@ -254,49 +358,22 @@ describe CascadingConfiguration::Hash::CompositingHash do
|
|
254
358
|
|
255
359
|
it 'can shift the first element' do
|
256
360
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock06A
|
262
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock06
|
263
|
-
def self.some_configuration
|
264
|
-
end
|
265
|
-
end
|
266
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock06B
|
267
|
-
include CascadingConfiguration::Hash::CompositingHash::CIMock06A
|
268
|
-
end
|
269
|
-
|
270
|
-
ccv = CascadingConfiguration::Variable
|
271
|
-
ccm_hash = CascadingConfiguration::Hash::CompositingHash::CCHMock06
|
272
|
-
configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock06A
|
273
|
-
sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock06B
|
274
|
-
configuration_name = :some_configuration
|
275
|
-
|
276
|
-
# Without super or sub composites
|
277
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
361
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
362
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
363
|
+
|
278
364
|
cascading_composite_hash.store( :some_setting, :some_value )
|
279
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
280
365
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
281
366
|
cascading_composite_hash.store( :other_setting, :some_value )
|
282
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
283
|
-
:other_setting => :some_value }
|
284
367
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
285
368
|
:other_setting => :some_value }
|
286
369
|
cascading_composite_hash.shift
|
287
|
-
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
288
370
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
289
371
|
|
290
|
-
# Super with a sub composite
|
291
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
292
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
293
372
|
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
294
373
|
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
295
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
296
374
|
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
297
375
|
:yet_another_setting => :some_value }
|
298
376
|
sub_cascading_composite_hash.shift
|
299
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
300
377
|
sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
301
378
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
302
379
|
|
@@ -308,51 +385,24 @@ describe CascadingConfiguration::Hash::CompositingHash do
|
|
308
385
|
|
309
386
|
it 'can clear, causing present elements to be excluded' do
|
310
387
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock07A
|
316
|
-
include CascadingConfiguration::Hash::CompositingHash::CCHMock07
|
317
|
-
def self.some_configuration
|
318
|
-
end
|
319
|
-
end
|
320
|
-
module CascadingConfiguration::Hash::CompositingHash::CIMock07B
|
321
|
-
include CascadingConfiguration::Hash::CompositingHash::CIMock07A
|
322
|
-
end
|
323
|
-
|
324
|
-
ccv = CascadingConfiguration::Variable
|
325
|
-
ccm_hash = CascadingConfiguration::Hash::CompositingHash::CCHMock07
|
326
|
-
configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock07A
|
327
|
-
sub_configuration_instance = CascadingConfiguration::Hash::CompositingHash::CIMock07B
|
328
|
-
configuration_name = :some_configuration
|
329
|
-
|
330
|
-
# Without super or sub composites
|
331
|
-
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
|
388
|
+
cascading_composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( @configuration_instance, @configuration_name )
|
389
|
+
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( @sub_configuration_instance, @configuration_name )
|
390
|
+
|
332
391
|
cascading_composite_hash.store( :some_setting, :some_value )
|
333
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
334
392
|
cascading_composite_hash.should == { :some_setting => :some_value }
|
335
393
|
cascading_composite_hash.store( :other_setting, :some_value )
|
336
|
-
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
337
|
-
:other_setting => :some_value }
|
338
394
|
cascading_composite_hash.should == { :some_setting => :some_value,
|
339
395
|
:other_setting => :some_value }
|
340
396
|
cascading_composite_hash.clear
|
341
|
-
cascading_composite_hash.local_cascading_hash.should == { }
|
342
397
|
cascading_composite_hash.should == { }
|
343
398
|
cascading_composite_hash.store( :other_setting, :some_value )
|
344
399
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
345
400
|
|
346
|
-
# Super with a sub composite
|
347
|
-
sub_cascading_composite_hash = CascadingConfiguration::Hash::CompositingHash.new( sub_configuration_instance, configuration_name )
|
348
|
-
sub_cascading_composite_hash.local_cascading_hash.should == {}
|
349
401
|
sub_cascading_composite_hash.should == { :other_setting => :some_value }
|
350
402
|
sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
|
351
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
352
403
|
sub_cascading_composite_hash.should == { :other_setting => :some_value,
|
353
404
|
:yet_another_setting => :some_value }
|
354
405
|
sub_cascading_composite_hash.clear
|
355
|
-
sub_cascading_composite_hash.local_cascading_hash.should == { }
|
356
406
|
sub_cascading_composite_hash.should == { }
|
357
407
|
cascading_composite_hash.should == { :other_setting => :some_value }
|
358
408
|
|