cascading-configuration-hash 2.0.3 → 2.1.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/README.md CHANGED
@@ -197,7 +197,7 @@ end
197
197
 
198
198
  (The MIT License)
199
199
 
200
- Copyright (c) 2011 Asher
200
+ Copyright (c) Asher
201
201
 
202
202
  Permission is hereby granted, free of charge, to any person obtaining
203
203
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -34,7 +34,7 @@ See README.md
34
34
 
35
35
  (The MIT License)
36
36
 
37
- Copyright (c) 2011 Asher
37
+ Copyright (c) Asher
38
38
 
39
39
  Permission is hereby granted, free of charge, to any person obtaining
40
40
  a copy of this software and associated documentation files (the
@@ -2,11 +2,52 @@
2
2
  module ::CascadingConfiguration::Hash
3
3
 
4
4
  # Configuration modules for storage of settings hashes
5
- include ::CascadingConfiguration::Variable
5
+ include ::CascadingConfiguration::Inheritance
6
6
 
7
- # Interface to declare configuration settings hashes
8
- include ::CascadingConfiguration::Hash::Interface
7
+ #############################################
8
+ # attr_configuration_unique_hash #
9
+ # attr_module_configuration_unique_hash #
10
+ # attr_local_configuration_unique_hash #
11
+ # attr_object_configuration_unique_hash #
12
+ # attr_instance_configuration_unique_hash #
13
+ #############################################
9
14
 
10
- extend ::CascadingConfiguration::Hash::ModuleSupportMethods
15
+ def attr_configuration_unique_hash( *configuration_names, & define_block ) ;; end
16
+ def attr_module_configuration_unique_hash( *configuration_names, & define_block ) ;; end
17
+ def attr_class_configuration_unique_hash( *configuration_names, & define_block ) ;; end
18
+ def attr_local_configuration_unique_hash( *configuration_names, & define_block ) ;; end
19
+ def attr_object_configuration_unique_hash( *configuration_names, & define_block ) ;; end
20
+ def attr_instance_configuration_unique_hash( *configuration_names, & define_block ) ;; end
21
+
22
+ cch = self
23
+ ccv = ::CascadingConfiguration::Variable
24
+ ccm = ::CascadingConfiguration::Methods
25
+
26
+ setter_proc = ::Proc.new do |instance, configuration_name, value|
27
+
28
+ return instance.__send__( configuration_name ).replace( value )
11
29
 
30
+ end
31
+
32
+ getter_proc = ::Proc.new do |instance, configuration_name|
33
+
34
+ composite_hash = nil
35
+
36
+ if ccv.has_configuration_variable?( instance, configuration_name )
37
+ composite_hash = ccv.get_configuration_variable( instance, configuration_name )
38
+ else
39
+ parent_composite_hash = nil
40
+ if ancestor = ::CascadingConfiguration::Variable.ancestor( instance, configuration_name )
41
+ parent_composite_hash = ancestor.__send__( configuration_name )
42
+ end
43
+ composite_hash = ::CompositingHash.new( parent_composite_hash )
44
+ ccv.set_configuration_variable( instance, configuration_name, composite_hash )
45
+ end
46
+
47
+ return composite_hash
48
+
49
+ end
50
+
51
+ ccm.declare_compositing_configuration_object( self, :hash, setter_proc, getter_proc )
52
+
12
53
  end
@@ -1,4 +1,6 @@
1
1
 
2
+ require 'compositing-hash'
3
+
2
4
  if $__cascading_configuration__spec__development
3
5
  require_relative '../../variable/lib/cascading-configuration-variable.rb'
4
6
  else
@@ -7,15 +9,7 @@ end
7
9
 
8
10
  module ::CascadingConfiguration
9
11
  module Hash
10
- class CompositingHash < ::Hash
11
- end
12
- module Interface
13
- end
14
12
  end
15
13
  end
16
14
 
17
- require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb'
18
- require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb'
19
-
20
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb'
21
15
  require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash.rb'
@@ -216,11 +216,15 @@ describe CascadingConfiguration::Hash do
216
216
 
217
217
  module ::CascadingConfiguration::Hash::ConfigurationMockModule
218
218
  include CascadingConfiguration::Hash
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
219
+ attr_configuration_hash :some_hash do
220
+ def merge!( other_hash )
221
+ other_hash.each do |key, foreign_value|
222
+ if existing_value = self[ key ]
223
+ self[ key ] = foreign_value - existing_value
224
+ else
225
+ self[ key ] = foreign_value
226
+ end
227
+ end
224
228
  end
225
229
  end
226
230
  self.some_hash = { :one => 1, :two => 2 }
@@ -423,11 +427,15 @@ describe CascadingConfiguration::Hash do
423
427
 
424
428
  module ::CascadingConfiguration::Hash::ClassConfigurationMockModule
425
429
  include CascadingConfiguration::Hash
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
430
+ attr_configuration_hash :some_hash do
431
+ def merge!( other_hash )
432
+ other_hash.each do |key, foreign_value|
433
+ if existing_value = self[ key ]
434
+ self[ key ] = foreign_value - existing_value
435
+ else
436
+ self[ key ] = foreign_value
437
+ end
438
+ end
431
439
  end
432
440
  end
433
441
  self.some_hash = { :one => 1, :two => 2 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cascading-configuration-hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-04 00:00:00.000000000 Z
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cascading-configuration-variable
16
- requirement: &70317490911220 !ruby/object:Gem::Requirement
16
+ requirement: &70142939829480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,19 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70317490911220
24
+ version_requirements: *70142939829480
25
25
  description: Provides :attr_configuration_hash.
26
26
  email: asher@ridiculouspower.com
27
27
  executables: []
28
28
  extensions: []
29
29
  extra_rdoc_files: []
30
30
  files:
31
- - lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb
32
- - lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb
33
- - lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb
34
31
  - lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb
35
32
  - lib/cascading-configuration-hash.rb
36
- - spec/_private_/CascadingConfiguration/Hash/CompositingHash_spec.rb
37
33
  - spec/CascadingConfiguration/Hash_spec.rb
38
34
  - README.md
39
35
  - README.rdoc
@@ -57,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
53
  version: '0'
58
54
  requirements: []
59
55
  rubyforge_project: cascading-configuration-hash
60
- rubygems_version: 1.8.10
56
+ rubygems_version: 1.8.11
61
57
  signing_key:
62
58
  specification_version: 3
63
59
  summary: Support package for cascading-configuration.
@@ -1,155 +0,0 @@
1
-
2
- module ::CascadingConfiguration::Hash::Interface
3
-
4
- ######################
5
- # self.setter_proc #
6
- ######################
7
-
8
- def self.setter_proc( configuration_name )
9
-
10
- return Proc.new do |hash|
11
-
12
- return ::CascadingConfiguration::Hash.
13
- composite_hash_for_cascading_configuration( self,
14
- configuration_name ).replace( hash )
15
-
16
- end
17
-
18
- end
19
-
20
- ######################
21
- # self.getter_proc #
22
- ######################
23
-
24
- def self.getter_proc( configuration_name )
25
-
26
- return Proc.new do
27
-
28
- return ::CascadingConfiguration::Hash.
29
- composite_hash_for_cascading_configuration( self, configuration_name )
30
-
31
- end
32
-
33
- end
34
-
35
- #############################
36
- # attr_configuration_hash #
37
- #############################
38
-
39
- # defines configuration in class or module
40
- # configuration cascades downward to instance including all classes or modules in-between
41
- def attr_configuration_hash( *configuration_names, & compositing_block )
42
-
43
- configuration_names.each do |this_configuration_name|
44
- if block_given?
45
- ::CascadingConfiguration::Variable.set_compositing_proc( self,
46
- this_configuration_name,
47
- compositing_block )
48
- end
49
- end
50
-
51
- return ::CascadingConfiguration::Variable.
52
- define_cascading_configuration( self,
53
- ::CascadingConfiguration::Hash::Interface,
54
- *configuration_names )
55
-
56
- end
57
-
58
- ####################################
59
- # attr_module_configuration_hash #
60
- ####################################
61
-
62
- # defines configuration in class or module
63
- # configuration cascades downward to last class or module
64
- def attr_module_configuration_hash( *configuration_names, & compositing_block )
65
-
66
- configuration_names.each do |this_configuration_name|
67
- if block_given?
68
- ::CascadingConfiguration::Variable.set_compositing_proc( self,
69
- this_configuration_name,
70
- compositing_block )
71
- end
72
- end
73
-
74
- return ::CascadingConfiguration::Variable.
75
- define_module_configuration( self,
76
- ::CascadingConfiguration::Hash::Interface,
77
- *configuration_names )
78
-
79
- end
80
- alias_method :attr_class_configuration_hash, :attr_module_configuration_hash
81
-
82
- ###################################
83
- # attr_local_configuration_hash #
84
- ###################################
85
-
86
- # defines configuration in present class or module context
87
- # configuration does not cascade
88
- def attr_local_configuration_hash( *configuration_names, & compositing_block )
89
-
90
- ::CascadingConfiguration::Variable.create_local_instance_configuration_support_module( self )
91
-
92
- configuration_names.each do |this_configuration_name|
93
- if block_given?
94
- ::CascadingConfiguration::Variable.set_compositing_proc( self,
95
- this_configuration_name,
96
- compositing_block )
97
- end
98
- end
99
-
100
- return ::CascadingConfiguration::Variable.
101
- define_local_configuration( self,
102
- ::CascadingConfiguration::Hash::Interface,
103
- *configuration_names )
104
-
105
- end
106
-
107
- ####################################
108
- # attr_object_configuration_hash #
109
- ####################################
110
-
111
- # defines configuration in present class or module context
112
- # configuration does not cascade
113
- def attr_object_configuration_hash( *configuration_names, & compositing_block )
114
-
115
- ::CascadingConfiguration::Variable.create_local_instance_configuration_support_module( self )
116
-
117
- configuration_names.each do |this_configuration_name|
118
- if block_given?
119
- ::CascadingConfiguration::Variable.set_compositing_proc( self,
120
- this_configuration_name,
121
- compositing_block )
122
- end
123
- end
124
-
125
- return ::CascadingConfiguration::Variable.
126
- define_object_configuration( self,
127
- ::CascadingConfiguration::Hash::Interface,
128
- *configuration_names )
129
-
130
- end
131
-
132
- ######################################
133
- # attr_instance_configuration_hash #
134
- ######################################
135
-
136
- # defines configuration in present class or module context
137
- # configuration does not cascade
138
- def attr_instance_configuration_hash( *configuration_names, & compositing_block )
139
-
140
- configuration_names.each do |this_configuration_name|
141
- if block_given?
142
- ::CascadingConfiguration::Variable.set_compositing_proc( self,
143
- this_configuration_name,
144
- compositing_block )
145
- end
146
- end
147
-
148
- return ::CascadingConfiguration::Variable.
149
- define_instance_configuration( self,
150
- ::CascadingConfiguration::Hash::Interface,
151
- *configuration_names )
152
-
153
- end
154
-
155
- end
@@ -1,340 +0,0 @@
1
-
2
- class ::CascadingConfiguration::Hash::CompositingHash < ::Hash
3
-
4
- ################
5
- # initialize #
6
- ################
7
-
8
- def initialize( configuration_instance, configuration_name )
9
-
10
- @configuration_instance = configuration_instance
11
- @configuration_name = configuration_name
12
-
13
- @replaced_parents = {}
14
-
15
- # store self for sub composites
16
- ::CascadingConfiguration::Variable.set_configuration_variable( configuration_instance,
17
- configuration_name,
18
- self )
19
-
20
- # get compositing proc if we have one
21
- @compositing_proc = ::CascadingConfiguration::Variable.
22
- get_compositing_proc_searching_upward( configuration_instance, @configuration_name )
23
-
24
- # we may later have our own child composites that register with us
25
- @sub_composite_hashes = [ ]
26
-
27
- # if first ancestor can have a composite hash,
28
- # register self with it in case it gets updated in the future
29
- if ancestor = ::CascadingConfiguration::Variable.ancestor( configuration_instance,
30
- configuration_name )
31
-
32
- @super_composite_hash = ::CascadingConfiguration::Variable.
33
- get_configuration_variable( ancestor,
34
- configuration_name )
35
-
36
- if @super_composite_hash.respond_to?( :register_sub_composite_hash )
37
- @super_composite_hash.register_sub_composite_hash( self )
38
- merge!( @super_composite_hash )
39
- else
40
- @super_composite_hash = nil
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- ################################### Sub-Hash Management #######################################
48
-
49
- #################################
50
- # register_sub_composite_hash #
51
- #################################
52
-
53
- def register_sub_composite_hash( sub_composite_hash )
54
-
55
- @sub_composite_hashes.push( sub_composite_hash )
56
-
57
- return self
58
-
59
- end
60
-
61
- ###################################
62
- # unregister_sub_composite_hash #
63
- ###################################
64
-
65
- def unregister_sub_composite_hash( sub_composite_hash )
66
-
67
- @sub_composite_hashes.delete( sub_composite_hash )
68
-
69
- return self
70
-
71
- end
72
-
73
- ##################################### Self Management ##########################################
74
-
75
- #########
76
- # []= #
77
- #########
78
-
79
- private
80
- alias_method :non_cascading_store, :store
81
- public
82
-
83
- def []=( key, object )
84
-
85
- @replaced_parents[ key ] = true
86
-
87
- non_cascading_store( key, object )
88
-
89
- @sub_composite_hashes.each do |this_sub_hash|
90
- this_sub_hash.instance_eval do
91
- update_as_sub_hash_for_parent_store( key, object )
92
- end
93
- end
94
-
95
- return object
96
-
97
- end
98
- alias_method :store, :[]=
99
-
100
- ############
101
- # delete #
102
- ############
103
-
104
- private
105
- alias_method :non_cascading_delete, :delete
106
- public
107
-
108
- def delete( key )
109
-
110
- @replaced_parents.delete( key )
111
-
112
- object = non_cascading_delete( key )
113
-
114
- @sub_composite_hashes.each do |this_sub_hash|
115
- this_sub_hash.instance_eval do
116
- update_as_sub_hash_for_parent_delete( key )
117
- end
118
- end
119
-
120
- return object
121
-
122
- end
123
-
124
- ###############
125
- # delete_if #
126
- ###############
127
-
128
- def delete_if
129
-
130
- return to_enum unless block_given?
131
-
132
- indexes = [ ]
133
-
134
- self.each do |this_key, this_object|
135
- if yield( this_key, this_object )
136
- delete( this_key )
137
- end
138
- end
139
-
140
- return self
141
-
142
- end
143
-
144
- #############
145
- # reject! #
146
- #############
147
-
148
- def reject!
149
-
150
- return to_enum unless block_given?
151
-
152
- return_value = nil
153
-
154
- self.each do |this_key, this_object|
155
- if yield( this_key, this_object )
156
- delete( this_key )
157
- return_value = self
158
- end
159
- end
160
-
161
- return return_value
162
-
163
- end
164
-
165
- #############
166
- # keep_if #
167
- #############
168
-
169
- def keep_if
170
-
171
- return to_enum unless block_given?
172
-
173
- indexes = [ ]
174
-
175
- self.each do |this_key, this_object|
176
- unless yield( this_key, this_object )
177
- delete( this_key )
178
- end
179
- end
180
-
181
- return self
182
-
183
-
184
- end
185
-
186
- #############
187
- # select! #
188
- #############
189
-
190
- def select!
191
-
192
- return to_enum unless block_given?
193
-
194
- return_value = nil
195
-
196
- self.each do |this_key, this_object|
197
- unless yield( this_key, this_object )
198
- delete( this_key )
199
- return_value = self
200
- end
201
- end
202
-
203
- return return_value
204
-
205
- end
206
-
207
- ############
208
- # merge! #
209
- # update #
210
- ############
211
-
212
- private
213
- alias_method :non_cascading_merge!, :merge!
214
- public
215
-
216
- def merge!( other_hash )
217
-
218
- other_hash.each do |this_key, this_object|
219
- if @compositing_proc
220
- self[ this_key ] = @compositing_proc.call( self, this_key, this_object )
221
- else
222
- self[ this_key ] = this_object
223
- end
224
- end
225
-
226
- return self
227
-
228
- end
229
- alias_method :update, :merge!
230
-
231
- #############
232
- # replace #
233
- #############
234
-
235
- def replace( other_hash )
236
-
237
- # clear current values
238
- clear
239
-
240
- # merge replacement settings
241
- merge!( other_hash )
242
-
243
- return self
244
-
245
- end
246
-
247
- ###########
248
- # shift #
249
- ###########
250
-
251
- def shift
252
-
253
- object = nil
254
-
255
- unless empty?
256
- last_key = first[ 0 ]
257
- object = delete( last_key )
258
- end
259
-
260
- return [ last_key, object ]
261
-
262
- end
263
-
264
- ###########
265
- # clear #
266
- ###########
267
-
268
- def clear
269
-
270
- keys.each do |this_key|
271
- delete( this_key )
272
- end
273
-
274
- return self
275
-
276
- end
277
-
278
- #############
279
- # freeze! #
280
- #############
281
-
282
- # freezes configuration and prevents ancestors from changing this configuration in the future
283
- def freeze!
284
-
285
- # unregister with parent composite so we don't get future updates from it
286
- if @super_composite_hash
287
- @super_composite_hash.unregister_sub_composite_hash( self )
288
- end
289
-
290
- return self
291
-
292
- end
293
-
294
- ##################################################################################################
295
- private ######################################################################################
296
- ##################################################################################################
297
-
298
- ######################### Self-as-Sub Management for Parent Updates ############################
299
-
300
- #########################################
301
- # update_as_sub_hash_for_parent_store #
302
- #########################################
303
-
304
- def update_as_sub_hash_for_parent_store( key, object )
305
-
306
- unless @replaced_parents[ key ]
307
-
308
- non_cascading_store( key, object )
309
-
310
- @sub_composite_hashes.each do |this_hash|
311
- this_hash.instance_eval do
312
- update_as_sub_hash_for_parent_store( key, object )
313
- end
314
- end
315
-
316
- end
317
-
318
- end
319
-
320
- ##########################################
321
- # update_as_sub_hash_for_parent_delete #
322
- ##########################################
323
-
324
- def update_as_sub_hash_for_parent_delete( key )
325
-
326
- unless @replaced_parents[ key ]
327
-
328
- non_cascading_delete( key )
329
-
330
- @sub_composite_hashes.each do |this_hash|
331
- this_hash.instance_eval do
332
- update_as_sub_hash_for_parent_delete( key )
333
- end
334
- end
335
-
336
- end
337
-
338
- end
339
-
340
- end
@@ -1,22 +0,0 @@
1
-
2
- module ::CascadingConfiguration::Hash::ModuleSupportMethods
3
-
4
- ################################################
5
- # composite_hash_for_cascading_configuration #
6
- ################################################
7
-
8
- def composite_hash_for_cascading_configuration( configuration_instance, configuration_name )
9
-
10
- composite_hash = nil
11
-
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
-
18
- return composite_hash
19
-
20
- end
21
-
22
- end
@@ -1,411 +0,0 @@
1
-
2
- if $__cascading_configuration__spec__development
3
- require_relative '../../../../lib/cascading-configuration-hash.rb'
4
- else
5
- require 'cascading-configuration-hash'
6
- end
7
-
8
- describe CascadingConfiguration::Hash::CompositingHash do
9
-
10
- before :all do
11
-
12
- module ::CascadingConfiguration::Hash::CompositingHash::MockA
13
- # needed for ccv ancestor determination
14
- def self.some_configuration
15
- end
16
- end
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 == { }
94
- end
95
-
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 )
110
-
111
- cascading_composite_hash[ :some_setting ] = :some_value
112
- cascading_composite_hash.should == { :some_setting => :some_value }
113
- sub_cascading_composite_hash.should == { :some_setting => :some_value }
114
-
115
- cascading_composite_hash[ :other_setting ] = :some_value
116
- cascading_composite_hash.should == { :some_setting => :some_value,
117
- :other_setting => :some_value }
118
- sub_cascading_composite_hash.should == { :some_setting => :some_value,
119
- :other_setting => :some_value }
120
-
121
- sub_cascading_composite_hash[ :yet_another_setting ] = :some_value
122
- cascading_composite_hash.should == { :some_setting => :some_value,
123
- :other_setting => :some_value }
124
- sub_cascading_composite_hash.should == { :some_setting => :some_value,
125
- :other_setting => :some_value,
126
- :yet_another_setting => :some_value }
127
-
128
- cascading_composite_hash.method( :[]= ).should == cascading_composite_hash.method( :store )
129
-
130
- end
131
-
132
- ############
133
- # delete #
134
- ############
135
-
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 )
140
-
141
- cascading_composite_hash.store( :some_setting, :some_value )
142
- cascading_composite_hash.should == { :some_setting => :some_value }
143
- sub_cascading_composite_hash.should == { :some_setting => :some_value }
144
-
145
- cascading_composite_hash.store( :other_setting, :some_value )
146
- cascading_composite_hash.should == { :some_setting => :some_value,
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 }
154
-
155
- sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
156
- cascading_composite_hash.should == { :other_setting => :some_value }
157
- sub_cascading_composite_hash.should == { :other_setting => :some_value,
158
- :yet_another_setting => :some_value }
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
-
164
- end
165
-
166
- ###############
167
- # delete_if #
168
- ###############
169
-
170
- it 'can delete elements with a block' do
171
-
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
186
- end
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
196
- end
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
-
211
- cascading_composite_hash.store( :some_setting, :some_value )
212
- cascading_composite_hash.should == { :some_setting => :some_value }
213
- sub_cascading_composite_hash.should == { :some_setting => :some_value }
214
-
215
- cascading_composite_hash.store( :other_setting, :some_value )
216
- cascading_composite_hash.should == { :some_setting => :some_value,
217
- :other_setting => :some_value }
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
223
- cascading_composite_hash.should == { :other_setting => :some_value }
224
- sub_cascading_composite_hash.should == { :other_setting => :some_value }
225
-
226
- sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
227
- cascading_composite_hash.should == { :other_setting => :some_value }
228
- sub_cascading_composite_hash.should == { :other_setting => :some_value,
229
- :yet_another_setting => :some_value }
230
- sub_cascading_composite_hash.reject! do |key, value|
231
- key == :other_setting
232
- end
233
- cascading_composite_hash.should == { :other_setting => :some_value }
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
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 }
271
-
272
- end
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
-
310
- ############
311
- # merge! #
312
- # update #
313
- ############
314
-
315
- it 'can merge from another hash' do
316
-
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
-
320
- cascading_composite_hash.merge!( :some_setting => :some_value )
321
- cascading_composite_hash.should == { :some_setting => :some_value }
322
- cascading_composite_hash.merge!( :other_setting => :some_value )
323
- cascading_composite_hash.should == { :some_setting => :some_value,
324
- :other_setting => :some_value }
325
-
326
- sub_cascading_composite_hash.should == { :some_setting => :some_value,
327
- :other_setting => :some_value }
328
- sub_cascading_composite_hash.merge!( :yet_another_setting => :some_value )
329
- sub_cascading_composite_hash.should == { :some_setting => :some_value,
330
- :other_setting => :some_value,
331
- :yet_another_setting => :some_value }
332
-
333
- end
334
-
335
- #############
336
- # replace #
337
- #############
338
-
339
- it 'can replace existing elements with others' do
340
-
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
-
344
- cascading_composite_hash.replace( :some_setting => :some_value )
345
- cascading_composite_hash.should == { :some_setting => :some_value }
346
- cascading_composite_hash.replace( :other_setting => :some_value )
347
- cascading_composite_hash.should == { :other_setting => :some_value }
348
-
349
- sub_cascading_composite_hash.should == { :other_setting => :some_value }
350
- sub_cascading_composite_hash.replace( :yet_another_setting => :some_value )
351
- sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
352
-
353
- end
354
-
355
- ###########
356
- # shift #
357
- ###########
358
-
359
- it 'can shift the first element' do
360
-
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
-
364
- cascading_composite_hash.store( :some_setting, :some_value )
365
- cascading_composite_hash.should == { :some_setting => :some_value }
366
- cascading_composite_hash.store( :other_setting, :some_value )
367
- cascading_composite_hash.should == { :some_setting => :some_value,
368
- :other_setting => :some_value }
369
- cascading_composite_hash.shift
370
- cascading_composite_hash.should == { :other_setting => :some_value }
371
-
372
- sub_cascading_composite_hash.should == { :other_setting => :some_value }
373
- sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
374
- sub_cascading_composite_hash.should == { :other_setting => :some_value,
375
- :yet_another_setting => :some_value }
376
- sub_cascading_composite_hash.shift
377
- sub_cascading_composite_hash.should == { :yet_another_setting => :some_value }
378
- cascading_composite_hash.should == { :other_setting => :some_value }
379
-
380
- end
381
-
382
- ###########
383
- # clear #
384
- ###########
385
-
386
- it 'can clear, causing present elements to be excluded' do
387
-
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
-
391
- cascading_composite_hash.store( :some_setting, :some_value )
392
- cascading_composite_hash.should == { :some_setting => :some_value }
393
- cascading_composite_hash.store( :other_setting, :some_value )
394
- cascading_composite_hash.should == { :some_setting => :some_value,
395
- :other_setting => :some_value }
396
- cascading_composite_hash.clear
397
- cascading_composite_hash.should == { }
398
- cascading_composite_hash.store( :other_setting, :some_value )
399
- cascading_composite_hash.should == { :other_setting => :some_value }
400
-
401
- sub_cascading_composite_hash.should == { :other_setting => :some_value }
402
- sub_cascading_composite_hash.store( :yet_another_setting, :some_value )
403
- sub_cascading_composite_hash.should == { :other_setting => :some_value,
404
- :yet_another_setting => :some_value }
405
- sub_cascading_composite_hash.clear
406
- sub_cascading_composite_hash.should == { }
407
- cascading_composite_hash.should == { :other_setting => :some_value }
408
-
409
- end
410
-
411
- end