cascading-configuration-hash 1.1.4 → 1.1.5
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 +308 -29
- data/README.rdoc +1 -27
- data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb +39 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb +136 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb +33 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/ClassInstance.rb +24 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInstance.rb +34 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +24 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb +83 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb +79 -0
- data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb +31 -0
- data/lib/cascading-configuration-hash.rb +35 -0
- data/spec/CascadingConfiguration/CascadingCompositeHash_spec.rb +402 -0
- data/spec/CascadingConfiguration/ConfigurationHash_spec.rb +95 -0
- data/spec/CascadingConfiguration/Hash/Accessors_spec.rb +28 -0
- data/spec/CascadingConfiguration/Hash_spec.rb +144 -0
- metadata +16 -5
- data/lib/cascading-configuration/CascadingConfiguration.rb +0 -16
- data/lib/cascading-configuration.rb +0 -15
- data/spec/CascadingConfiguration_spec.rb +0 -224
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
|
|
2
|
+
class CascadingConfiguration::LocalConfigurationHash < Hash
|
|
3
|
+
|
|
4
|
+
attr_accessor :exclude_array
|
|
5
|
+
|
|
6
|
+
################
|
|
7
|
+
# initialize #
|
|
8
|
+
################
|
|
9
|
+
|
|
10
|
+
def initialize()
|
|
11
|
+
@exclude_array = ::Array.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#########
|
|
15
|
+
# []= #
|
|
16
|
+
#########
|
|
17
|
+
|
|
18
|
+
def []=( key, value )
|
|
19
|
+
super
|
|
20
|
+
remove_from_exclude_array( key )
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
###########
|
|
24
|
+
# store #
|
|
25
|
+
###########
|
|
26
|
+
|
|
27
|
+
def store( key, value )
|
|
28
|
+
self[ key ] = value
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
############
|
|
32
|
+
# delete #
|
|
33
|
+
############
|
|
34
|
+
|
|
35
|
+
def delete( key )
|
|
36
|
+
value = super
|
|
37
|
+
add_to_exclude_array( key )
|
|
38
|
+
return value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
############
|
|
42
|
+
# merge! #
|
|
43
|
+
############
|
|
44
|
+
|
|
45
|
+
def merge!( other_hash )
|
|
46
|
+
super
|
|
47
|
+
remove_from_exclude_array( *other_hash.keys )
|
|
48
|
+
return self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#############
|
|
52
|
+
# replace #
|
|
53
|
+
#############
|
|
54
|
+
|
|
55
|
+
def replace( other_hash )
|
|
56
|
+
add_to_exclude_array( *self.keys )
|
|
57
|
+
super
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
###########
|
|
61
|
+
# shift #
|
|
62
|
+
###########
|
|
63
|
+
|
|
64
|
+
def shift
|
|
65
|
+
element = super
|
|
66
|
+
add_to_exclude_array( element )
|
|
67
|
+
return element
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
###########
|
|
71
|
+
# clear #
|
|
72
|
+
###########
|
|
73
|
+
|
|
74
|
+
def clear
|
|
75
|
+
# add all existing values to exclude array
|
|
76
|
+
self.each do |this_key, this_value|
|
|
77
|
+
delete( this_key )
|
|
78
|
+
end
|
|
79
|
+
# clear existing values
|
|
80
|
+
super
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
class CascadingConfiguration::CompositingHash < Hash
|
|
3
|
+
|
|
4
|
+
###########################################################################################################
|
|
5
|
+
private ###############################################################################################
|
|
6
|
+
###########################################################################################################
|
|
7
|
+
|
|
8
|
+
########################################
|
|
9
|
+
# update_self_as_cascading_composite #
|
|
10
|
+
########################################
|
|
11
|
+
|
|
12
|
+
def update_self_as_cascading_composite
|
|
13
|
+
# start fresh
|
|
14
|
+
super_clear
|
|
15
|
+
update_composite_self_for_parent_hash( @parent_composite_hash, @local_cascading_hash )
|
|
16
|
+
# remove local exclude
|
|
17
|
+
unless @local_cascading_hash.exclude_array.empty?
|
|
18
|
+
@local_cascading_hash.exclude_array.each do |this_excluded_element|
|
|
19
|
+
super_delete( this_excluded_element )
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
# notify children to update their composite status
|
|
23
|
+
update_child_composite_arrays
|
|
24
|
+
return self
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
######################################
|
|
28
|
+
# update_adding_composite_elements #
|
|
29
|
+
######################################
|
|
30
|
+
|
|
31
|
+
def update_adding_composite_elements( elements_to_cascade )
|
|
32
|
+
update_composite_self_for_parent_hash( self, elements_to_cascade )
|
|
33
|
+
update_child_composite_arrays
|
|
34
|
+
return self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
###########################################
|
|
38
|
+
# update_composite_self_for_parent_hash #
|
|
39
|
+
###########################################
|
|
40
|
+
|
|
41
|
+
def update_composite_self_for_parent_hash( parent_hash, second_hash )
|
|
42
|
+
if compositing_proc = @working_class::AccessorSupportModule.get_compositing_proc( @cascading_name )
|
|
43
|
+
# if we have a compositing proc defined, use its result to replace
|
|
44
|
+
parent_hash_copy = Hash.new
|
|
45
|
+
parent_hash_copy.merge!( parent_hash ) if parent_hash
|
|
46
|
+
second_hash_copy = Hash.new
|
|
47
|
+
second_hash_copy.merge!( second_hash ) if second_hash
|
|
48
|
+
composite_result = compositing_proc.call( parent_hash_copy, second_hash_copy )
|
|
49
|
+
super_replace( composite_result )
|
|
50
|
+
else
|
|
51
|
+
# otherwise we simply merge
|
|
52
|
+
super_merge!( parent_hash ) if parent_hash
|
|
53
|
+
super_merge!( second_hash ) if second_hash
|
|
54
|
+
end
|
|
55
|
+
return self
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
########################################
|
|
59
|
+
# update_removing_composite_elements #
|
|
60
|
+
########################################
|
|
61
|
+
|
|
62
|
+
def update_removing_composite_elements( *elements_to_exclude )
|
|
63
|
+
elements_to_exclude.each do |this_key|
|
|
64
|
+
super_delete( this_key )
|
|
65
|
+
end
|
|
66
|
+
update_child_composite_arrays
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
###################################
|
|
70
|
+
# update_child_composite_arrays #
|
|
71
|
+
###################################
|
|
72
|
+
|
|
73
|
+
def update_child_composite_arrays
|
|
74
|
+
@child_composite_hashes.each do |this_composite_hash|
|
|
75
|
+
this_composite_hash.instance_eval { update_self_as_cascading_composite }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
class CascadingConfiguration::LocalConfigurationHash < Hash
|
|
3
|
+
|
|
4
|
+
###########################################################################################################
|
|
5
|
+
private ###############################################################################################
|
|
6
|
+
###########################################################################################################
|
|
7
|
+
|
|
8
|
+
##########################
|
|
9
|
+
# add_to_exclude_array #
|
|
10
|
+
##########################
|
|
11
|
+
|
|
12
|
+
def add_to_exclude_array( *elements )
|
|
13
|
+
@exclude_array ||= ::Array.new
|
|
14
|
+
@exclude_array += elements
|
|
15
|
+
@exclude_array.sort!.uniq!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
###############################
|
|
19
|
+
# remove_from_exclude_array #
|
|
20
|
+
###############################
|
|
21
|
+
|
|
22
|
+
def remove_from_exclude_array( *elements )
|
|
23
|
+
if @exclude_array
|
|
24
|
+
@exclude_array -= elements
|
|
25
|
+
@exclude_array.sort!.uniq!
|
|
26
|
+
else
|
|
27
|
+
@exclude_array ||= ::Array.new
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
if $cascading_configuration_development
|
|
3
|
+
require_relative '../../variable/lib/cascading-configuration-variable.rb'
|
|
4
|
+
else
|
|
5
|
+
require 'cascading-configuration-variable'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module CascadingConfiguration
|
|
9
|
+
class CompositingHash < Hash
|
|
10
|
+
module Instance
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
class LocalConfigurationHash < Hash
|
|
14
|
+
end
|
|
15
|
+
module Hash
|
|
16
|
+
module Accessors
|
|
17
|
+
end
|
|
18
|
+
module ClassInstance
|
|
19
|
+
end
|
|
20
|
+
module ObjectInstance
|
|
21
|
+
end
|
|
22
|
+
module ModuleInstance
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb'
|
|
28
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb'
|
|
29
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb'
|
|
30
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb'
|
|
31
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb'
|
|
32
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash.rb'
|
|
33
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb'
|
|
34
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/ClassInstance.rb'
|
|
35
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInstance.rb'
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
|
|
2
|
+
require_relative '../../lib/cascading-configuration-hash.rb'
|
|
3
|
+
|
|
4
|
+
describe CascadingConfiguration::CompositingHash do
|
|
5
|
+
|
|
6
|
+
#########
|
|
7
|
+
# []= #
|
|
8
|
+
#########
|
|
9
|
+
|
|
10
|
+
it 'can add elements' do
|
|
11
|
+
# primary class
|
|
12
|
+
class CascadingConfiguration::CompositingHash::Mock01
|
|
13
|
+
include CascadingConfiguration::Variable
|
|
14
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
15
|
+
end
|
|
16
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock01
|
|
17
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
18
|
+
cascading_composite_hash[ :some_setting ] = :some_value
|
|
19
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
20
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
21
|
+
cascading_composite_hash[ :other_setting ] = :some_value
|
|
22
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
|
23
|
+
:other_setting => :some_value }
|
|
24
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
25
|
+
:other_setting => :some_value }
|
|
26
|
+
# instance
|
|
27
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock01.new
|
|
28
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
29
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
30
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
31
|
+
:other_setting => :some_value }
|
|
32
|
+
cascading_composite_hash[ :another_setting ] = :some_value
|
|
33
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
34
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
35
|
+
:other_setting => :some_value,
|
|
36
|
+
:another_setting => :some_value }
|
|
37
|
+
# inheriting class
|
|
38
|
+
class CascadingConfiguration::CompositingHash::Mock01sub1 < CascadingConfiguration::CompositingHash::Mock01
|
|
39
|
+
end
|
|
40
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock01sub1
|
|
41
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
42
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
43
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
44
|
+
:other_setting => :some_value }
|
|
45
|
+
cascading_composite_hash[ :yet_another_setting ] = :some_value
|
|
46
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
47
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
48
|
+
:other_setting => :some_value,
|
|
49
|
+
:yet_another_setting => :some_value }
|
|
50
|
+
# instance
|
|
51
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock01sub1.new
|
|
52
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
53
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
54
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
55
|
+
:other_setting => :some_value,
|
|
56
|
+
:yet_another_setting => :some_value }
|
|
57
|
+
cascading_composite_hash[ :and_still_another_setting ] = :some_value
|
|
58
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
59
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
60
|
+
:other_setting => :some_value,
|
|
61
|
+
:yet_another_setting => :some_value,
|
|
62
|
+
:and_still_another_setting => :some_value }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
###########
|
|
66
|
+
# store #
|
|
67
|
+
###########
|
|
68
|
+
|
|
69
|
+
it 'can add elements' do
|
|
70
|
+
# primary class
|
|
71
|
+
class CascadingConfiguration::CompositingHash::Mock02
|
|
72
|
+
include CascadingConfiguration::Variable
|
|
73
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
74
|
+
end
|
|
75
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock02
|
|
76
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
77
|
+
cascading_composite_hash.store( :some_setting, :some_value )
|
|
78
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
79
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
80
|
+
cascading_composite_hash.store( :other_setting, :some_value )
|
|
81
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
|
82
|
+
:other_setting => :some_value }
|
|
83
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
84
|
+
:other_setting => :some_value }
|
|
85
|
+
# instance
|
|
86
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock02.new
|
|
87
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
88
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
89
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
90
|
+
:other_setting => :some_value }
|
|
91
|
+
cascading_composite_hash.store( :another_setting, :some_value )
|
|
92
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
93
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
94
|
+
:other_setting => :some_value,
|
|
95
|
+
:another_setting => :some_value }
|
|
96
|
+
# inheriting class
|
|
97
|
+
class CascadingConfiguration::CompositingHash::Mock02sub1 < CascadingConfiguration::CompositingHash::Mock02
|
|
98
|
+
end
|
|
99
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock02sub1
|
|
100
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
101
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
102
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
103
|
+
:other_setting => :some_value }
|
|
104
|
+
cascading_composite_hash.store( :yet_another_setting, :some_value )
|
|
105
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
106
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
107
|
+
:other_setting => :some_value,
|
|
108
|
+
:yet_another_setting => :some_value }
|
|
109
|
+
# instance
|
|
110
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock02sub1.new
|
|
111
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
112
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
113
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
114
|
+
:other_setting => :some_value,
|
|
115
|
+
:yet_another_setting => :some_value }
|
|
116
|
+
cascading_composite_hash.store( :and_still_another_setting, :some_value )
|
|
117
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
118
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
119
|
+
:other_setting => :some_value,
|
|
120
|
+
:yet_another_setting => :some_value,
|
|
121
|
+
:and_still_another_setting => :some_value }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
############
|
|
125
|
+
# delete #
|
|
126
|
+
############
|
|
127
|
+
|
|
128
|
+
it 'can exclude elements' do
|
|
129
|
+
# primary class
|
|
130
|
+
class CascadingConfiguration::CompositingHash::Mock03
|
|
131
|
+
include CascadingConfiguration::Variable
|
|
132
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
133
|
+
end
|
|
134
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock03
|
|
135
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
136
|
+
cascading_composite_hash.store( :some_setting, :some_value )
|
|
137
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
138
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
139
|
+
cascading_composite_hash.delete( :some_setting ).should == :some_value
|
|
140
|
+
cascading_composite_hash.should == {}
|
|
141
|
+
cascading_composite_hash.store( :other_setting, :some_value )
|
|
142
|
+
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
|
143
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
144
|
+
# instance
|
|
145
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock03.new
|
|
146
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
147
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
148
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
149
|
+
cascading_composite_hash.delete( :other_setting ).should == :some_value
|
|
150
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
151
|
+
cascading_composite_hash.local_cascading_hash.exclude_array.should == [ :other_setting ]
|
|
152
|
+
cascading_composite_hash.should == {}
|
|
153
|
+
# inheriting class
|
|
154
|
+
class CascadingConfiguration::CompositingHash::Mock03sub1 < CascadingConfiguration::CompositingHash::Mock03
|
|
155
|
+
end
|
|
156
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock03sub1
|
|
157
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
158
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
159
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
160
|
+
cascading_composite_hash.delete( :other_setting ).should == :some_value
|
|
161
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
162
|
+
cascading_composite_hash.local_cascading_hash.exclude_array.should == [ :other_setting ]
|
|
163
|
+
cascading_composite_hash.should == {}
|
|
164
|
+
# instance
|
|
165
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock03sub1.new
|
|
166
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
167
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
168
|
+
cascading_composite_hash.should == {}
|
|
169
|
+
cascading_composite_hash.store( :and_still_another_setting, :some_value )
|
|
170
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
171
|
+
cascading_composite_hash.should == { :and_still_another_setting => :some_value }
|
|
172
|
+
cascading_composite_hash.delete( :and_still_another_setting ).should == :some_value
|
|
173
|
+
cascading_composite_hash.should == {}
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
############
|
|
177
|
+
# merge! #
|
|
178
|
+
############
|
|
179
|
+
|
|
180
|
+
it 'can merge from another hash' do
|
|
181
|
+
# primary class
|
|
182
|
+
class CascadingConfiguration::CompositingHash::Mock04
|
|
183
|
+
include CascadingConfiguration::Variable
|
|
184
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
185
|
+
end
|
|
186
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock04
|
|
187
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
188
|
+
cascading_composite_hash.merge!( :some_setting => :some_value )
|
|
189
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
190
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
191
|
+
cascading_composite_hash.merge!( :other_setting => :some_value )
|
|
192
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
|
|
193
|
+
:other_setting => :some_value }
|
|
194
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
195
|
+
:other_setting => :some_value }
|
|
196
|
+
# instance
|
|
197
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock04.new
|
|
198
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
199
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
200
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
201
|
+
:other_setting => :some_value }
|
|
202
|
+
cascading_composite_hash.merge!( :another_setting => :some_value )
|
|
203
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
204
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
205
|
+
:other_setting => :some_value,
|
|
206
|
+
:another_setting => :some_value }
|
|
207
|
+
# inheriting class
|
|
208
|
+
class CascadingConfiguration::CompositingHash::Mock04sub1 < CascadingConfiguration::CompositingHash::Mock04
|
|
209
|
+
end
|
|
210
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock04sub1
|
|
211
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
212
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
213
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
214
|
+
:other_setting => :some_value }
|
|
215
|
+
cascading_composite_hash.merge!( :yet_another_setting => :some_value )
|
|
216
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
217
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
218
|
+
:other_setting => :some_value,
|
|
219
|
+
:yet_another_setting => :some_value }
|
|
220
|
+
# instance
|
|
221
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock04sub1.new
|
|
222
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
223
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
224
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
225
|
+
:other_setting => :some_value,
|
|
226
|
+
:yet_another_setting => :some_value }
|
|
227
|
+
cascading_composite_hash.merge!( :and_still_another_setting => :some_value )
|
|
228
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
229
|
+
cascading_composite_hash.should == { :some_setting => :some_value,
|
|
230
|
+
:other_setting => :some_value,
|
|
231
|
+
:yet_another_setting => :some_value,
|
|
232
|
+
:and_still_another_setting => :some_value }
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
#############
|
|
236
|
+
# replace #
|
|
237
|
+
#############
|
|
238
|
+
|
|
239
|
+
it 'can replace existing elements with others' do
|
|
240
|
+
# primary class
|
|
241
|
+
class CascadingConfiguration::CompositingHash::Mock05
|
|
242
|
+
include CascadingConfiguration::Variable
|
|
243
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
244
|
+
end
|
|
245
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock05
|
|
246
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
247
|
+
cascading_composite_hash.replace( :some_setting => :some_value )
|
|
248
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
249
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
250
|
+
cascading_composite_hash.replace( :other_setting => :some_value )
|
|
251
|
+
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
|
252
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
253
|
+
# instance
|
|
254
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock05.new
|
|
255
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
256
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
257
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
258
|
+
cascading_composite_hash.replace( :another_setting => :some_value )
|
|
259
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
260
|
+
cascading_composite_hash.should == { :another_setting => :some_value }
|
|
261
|
+
# inheriting class
|
|
262
|
+
class CascadingConfiguration::CompositingHash::Mock05sub1 < CascadingConfiguration::CompositingHash::Mock05
|
|
263
|
+
end
|
|
264
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock05sub1
|
|
265
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
266
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
267
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
268
|
+
cascading_composite_hash.replace( :yet_another_setting => :some_value )
|
|
269
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
270
|
+
cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
|
271
|
+
# instance
|
|
272
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock05sub1.new
|
|
273
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
274
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
275
|
+
cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
|
276
|
+
cascading_composite_hash.replace( :and_still_another_setting => :some_value )
|
|
277
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
278
|
+
cascading_composite_hash.should == { :and_still_another_setting => :some_value }
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
###########
|
|
282
|
+
# shift #
|
|
283
|
+
###########
|
|
284
|
+
|
|
285
|
+
it 'can shift the first element' do
|
|
286
|
+
# primary class
|
|
287
|
+
class CascadingConfiguration::CompositingHash::Mock06
|
|
288
|
+
include CascadingConfiguration::Variable
|
|
289
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
290
|
+
end
|
|
291
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock06
|
|
292
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
293
|
+
cascading_composite_hash.replace( :some_setting => :some_value )
|
|
294
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
295
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
296
|
+
cascading_composite_hash.shift.should == [ :some_setting, :some_value ]
|
|
297
|
+
cascading_composite_hash.should == {}
|
|
298
|
+
cascading_composite_hash.replace( :other_setting => :some_value )
|
|
299
|
+
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
|
300
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
301
|
+
cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
|
|
302
|
+
cascading_composite_hash.should == {}
|
|
303
|
+
# instance
|
|
304
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock06.new
|
|
305
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
306
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
307
|
+
cascading_composite_hash.replace( :other_setting => :some_value )
|
|
308
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
309
|
+
cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
|
|
310
|
+
cascading_composite_hash.should == {}
|
|
311
|
+
cascading_composite_hash.replace( :another_setting => :some_value )
|
|
312
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
313
|
+
cascading_composite_hash.should == { :another_setting => :some_value }
|
|
314
|
+
cascading_composite_hash.shift.should == [ :another_setting, :some_value ]
|
|
315
|
+
cascading_composite_hash.should == {}
|
|
316
|
+
# inheriting class
|
|
317
|
+
class CascadingConfiguration::CompositingHash::Mock06sub1 < CascadingConfiguration::CompositingHash::Mock06
|
|
318
|
+
end
|
|
319
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock06sub1
|
|
320
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
321
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
322
|
+
cascading_composite_hash.replace( :other_setting => :some_value )
|
|
323
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
324
|
+
cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
|
|
325
|
+
cascading_composite_hash.should == {}
|
|
326
|
+
cascading_composite_hash.replace( :yet_another_setting => :some_value )
|
|
327
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
328
|
+
cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
|
329
|
+
cascading_composite_hash.shift.should == [ :yet_another_setting, :some_value ]
|
|
330
|
+
cascading_composite_hash.should == {}
|
|
331
|
+
# instance
|
|
332
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock06sub1.new
|
|
333
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
334
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
335
|
+
cascading_composite_hash.replace( :yet_another_setting => :some_value )
|
|
336
|
+
cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
|
337
|
+
cascading_composite_hash.shift.should == [ :yet_another_setting, :some_value ]
|
|
338
|
+
cascading_composite_hash.should == {}
|
|
339
|
+
cascading_composite_hash.replace( :and_still_another_setting => :some_value )
|
|
340
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
341
|
+
cascading_composite_hash.should == { :and_still_another_setting => :some_value }
|
|
342
|
+
cascading_composite_hash.shift.should == [ :and_still_another_setting, :some_value ]
|
|
343
|
+
cascading_composite_hash.should == {}
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
###########
|
|
347
|
+
# clear #
|
|
348
|
+
###########
|
|
349
|
+
|
|
350
|
+
it 'can clear, causing present elements to be excluded' do
|
|
351
|
+
# primary class
|
|
352
|
+
class CascadingConfiguration::CompositingHash::Mock07
|
|
353
|
+
include CascadingConfiguration::Variable
|
|
354
|
+
include CascadingConfiguration::CompositingHash::Instance
|
|
355
|
+
end
|
|
356
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock07
|
|
357
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
358
|
+
cascading_composite_hash.replace( :some_setting => :some_value )
|
|
359
|
+
cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
|
|
360
|
+
cascading_composite_hash.should == { :some_setting => :some_value }
|
|
361
|
+
cascading_composite_hash.clear
|
|
362
|
+
cascading_composite_hash.should == {}
|
|
363
|
+
cascading_composite_hash.replace( :other_setting => :some_value )
|
|
364
|
+
cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
|
|
365
|
+
cascading_composite_hash.should == { :other_setting => :some_value }
|
|
366
|
+
cascading_composite_hash.clear
|
|
367
|
+
cascading_composite_hash.should == {}
|
|
368
|
+
# instance
|
|
369
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock07.new
|
|
370
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
371
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
372
|
+
cascading_composite_hash.should == {}
|
|
373
|
+
cascading_composite_hash.replace( :another_setting => :some_value )
|
|
374
|
+
cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
|
|
375
|
+
cascading_composite_hash.should == { :another_setting => :some_value }
|
|
376
|
+
cascading_composite_hash.clear
|
|
377
|
+
cascading_composite_hash.should == {}
|
|
378
|
+
# inheriting class
|
|
379
|
+
class CascadingConfiguration::CompositingHash::Mock07sub1 < CascadingConfiguration::CompositingHash::Mock07
|
|
380
|
+
end
|
|
381
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock07sub1
|
|
382
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
383
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
384
|
+
cascading_composite_hash.should == {}
|
|
385
|
+
cascading_composite_hash.replace( :yet_another_setting => :some_value )
|
|
386
|
+
cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
|
|
387
|
+
cascading_composite_hash.should == { :yet_another_setting => :some_value }
|
|
388
|
+
cascading_composite_hash.clear
|
|
389
|
+
cascading_composite_hash.should == {}
|
|
390
|
+
# instance
|
|
391
|
+
working_instance = CascadingConfiguration::CompositingHash::Mock07sub1.new
|
|
392
|
+
cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
|
|
393
|
+
cascading_composite_hash.local_cascading_hash.should == {}
|
|
394
|
+
cascading_composite_hash.should == {}
|
|
395
|
+
cascading_composite_hash.replace( :and_still_another_setting => :some_value )
|
|
396
|
+
cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
|
|
397
|
+
cascading_composite_hash.should == { :and_still_another_setting => :some_value }
|
|
398
|
+
cascading_composite_hash.clear
|
|
399
|
+
cascading_composite_hash.should == {}
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
end
|