cascading-configuration-hash 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (19) hide show
  1. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb +86 -27
  2. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +5 -21
  3. data/lib/cascading-configuration-hash/{CascadingConfiguration → _private_/CascadingConfiguration/Hash/CompositingHash}/LocalConfigurationHash.rb +29 -2
  4. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb +246 -0
  5. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/Interface/GettersSetters.rb +233 -0
  6. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb +29 -0
  7. data/lib/cascading-configuration-hash.rb +12 -23
  8. data/spec/CascadingConfiguration/Hash_spec.rb +2 -3
  9. data/spec/{CascadingConfiguration → _private_/CascadingConfiguration/Hash/CompositingHash}/LocalConfigurationHash_spec.rb +9 -9
  10. data/spec/_private_/CascadingConfiguration/Hash/CompositingHash_spec.rb +347 -0
  11. metadata +10 -28
  12. data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb +0 -31
  13. data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb +0 -135
  14. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/AccessorDefinitionMethods.rb +0 -149
  15. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface/Instance.rb +0 -26
  16. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb +0 -79
  17. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb +0 -31
  18. data/spec/CascadingConfiguration/CascadingCompositeHash_spec.rb +0 -416
  19. data/spec/CascadingConfiguration/Hash/AccessorDefinitionMethods_spec.rb +0 -30
@@ -0,0 +1,233 @@
1
+
2
+ module CascadingConfiguration::Hash::Interface::GettersSetters
3
+
4
+ ##################################
5
+ # define_cascading_hash_setter #
6
+ ##################################
7
+
8
+ def define_cascading_hash_setter( configuration_name )
9
+
10
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
11
+
12
+ module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
13
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
14
+
15
+ array_setter_proc = Proc.new do |hash|
16
+
17
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
18
+
19
+ end
20
+
21
+ module_configuration_support_module.module_eval do
22
+ define_method( configuration_setter_name, & array_setter_proc )
23
+ end
24
+
25
+ instance_configuration_support_module.module_eval do
26
+ define_method( configuration_setter_name, & array_setter_proc )
27
+ end if instance_configuration_support_module
28
+
29
+ end
30
+
31
+ ##################################
32
+ # define_cascading_hash_getter #
33
+ ##################################
34
+
35
+ def define_cascading_hash_getter( configuration_name )
36
+
37
+ configuration_getter_name = configuration_name
38
+
39
+ module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
40
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
41
+
42
+ array_getter_proc = Proc.new do
43
+
44
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
45
+
46
+ end
47
+
48
+ module_configuration_support_module.module_eval do
49
+ define_method( configuration_getter_name, & array_getter_proc )
50
+ end
51
+
52
+ instance_configuration_support_module.module_eval do
53
+ define_method( configuration_getter_name, & array_getter_proc )
54
+ end if instance_configuration_support_module
55
+
56
+ end
57
+
58
+ ############################################
59
+ # define_class_configuration_hash_setter #
60
+ ############################################
61
+
62
+ def define_class_configuration_hash_setter( configuration_name )
63
+
64
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
65
+
66
+ module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
67
+
68
+ module_configuration_support_module.module_eval do
69
+ define_method( configuration_setter_name ) do |hash|
70
+
71
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
72
+
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ ############################################
79
+ # define_class_configuration_hash_getter #
80
+ ############################################
81
+
82
+ def define_class_configuration_hash_getter( configuration_name )
83
+
84
+ configuration_getter_name = configuration_name
85
+
86
+ module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
87
+
88
+ module_configuration_support_module.module_eval do
89
+ define_method( configuration_getter_name ) do
90
+
91
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
92
+
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ ############################################
99
+ # define_local_configuration_hash_setter #
100
+ ############################################
101
+
102
+ def define_local_configuration_hash_setter( configuration_name )
103
+
104
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
105
+
106
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
107
+ local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
108
+
109
+ local_setter_proc = Proc.new do |hash|
110
+
111
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
112
+
113
+ end
114
+
115
+ instance_configuration_support_module.module_eval do
116
+ define_method( configuration_setter_name, & local_setter_proc )
117
+ end if instance_configuration_support_module
118
+
119
+ local_instance_configuration_support_module.module_eval do
120
+ define_method( configuration_setter_name, & local_setter_proc )
121
+ end
122
+
123
+ end
124
+
125
+ ############################################
126
+ # define_local_configuration_hash_getter #
127
+ ############################################
128
+
129
+ def define_local_configuration_hash_getter( configuration_name )
130
+
131
+ configuration_getter_name = configuration_name
132
+
133
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
134
+
135
+ local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
136
+
137
+ local_getter_proc = Proc.new do
138
+
139
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
140
+
141
+ end
142
+
143
+ instance_configuration_support_module.module_eval do
144
+ define_method( configuration_getter_name, & local_getter_proc )
145
+ end if instance_configuration_support_module
146
+
147
+ local_instance_configuration_support_module.module_eval do
148
+ define_method( configuration_getter_name, & local_getter_proc )
149
+ end
150
+
151
+ end
152
+
153
+ ###############################################
154
+ # define_instance_configuration_hash_setter #
155
+ ###############################################
156
+
157
+ def define_instance_configuration_hash_setter( configuration_name )
158
+
159
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
160
+
161
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
162
+
163
+ instance_configuration_support_module.module_eval do
164
+ define_method( configuration_setter_name ) do |hash|
165
+
166
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
167
+
168
+ end
169
+ end
170
+
171
+ end
172
+
173
+ ###############################################
174
+ # define_instance_configuration_hash_getter #
175
+ ###############################################
176
+
177
+ def define_instance_configuration_hash_getter( configuration_name )
178
+
179
+ configuration_getter_name = configuration_name
180
+
181
+ instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
182
+
183
+ instance_configuration_support_module.module_eval do
184
+ define_method( configuration_getter_name ) do
185
+
186
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
187
+
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ #############################################
194
+ # define_object_configuration_hash_setter #
195
+ #############################################
196
+
197
+ def define_object_configuration_hash_setter( configuration_name )
198
+
199
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
200
+
201
+ local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
202
+
203
+ local_instance_configuration_support_module.module_eval do
204
+ define_method( configuration_setter_name ) do |hash|
205
+
206
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
207
+
208
+ end
209
+ end
210
+
211
+ end
212
+
213
+ #############################################
214
+ # define_object_configuration_hash_getter #
215
+ #############################################
216
+
217
+ def define_object_configuration_hash_getter( configuration_name )
218
+
219
+ configuration_getter_name = configuration_name
220
+
221
+ local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
222
+
223
+ local_instance_configuration_support_module.module_eval do
224
+ define_method( configuration_getter_name ) do
225
+
226
+ return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
227
+
228
+ end
229
+ end
230
+
231
+ end
232
+
233
+ end
@@ -0,0 +1,29 @@
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
+ for_instance = false
12
+
13
+ this_object_module_support = CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance )
14
+ if ! this_object_module_support and ! configuration_instance.is_a?( Module )
15
+ this_object_module_support = CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance.class )
16
+ for_instance = true
17
+ end
18
+
19
+ if this_object_module_support.has_configuration_variable?( configuration_name, for_instance )
20
+ composite_hash = this_object_module_support.get_configuration_variable( configuration_name, for_instance )
21
+ else
22
+ composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
23
+ end
24
+
25
+ return composite_hash
26
+
27
+ end
28
+
29
+ end
@@ -1,35 +1,24 @@
1
1
 
2
- if $cascading_configuration_development
3
- require_relative '../../variable/lib/cascading-configuration-variable.rb'
4
- else
5
- require 'cascading-configuration-variable'
6
- end
2
+ require 'cascading-configuration-variable'
3
+ #require_relative '../../variable/lib/cascading-configuration-variable.rb'
7
4
 
8
5
  module CascadingConfiguration
9
- class CompositingHash < Hash
10
- module Instance
11
- end
12
- end
13
- class LocalConfigurationHash < Hash
14
- end
15
6
  module Hash
16
- module AccessorDefinitionMethods
7
+ class CompositingHash < ::Hash
8
+ class LocalConfigurationHash < ::Hash
9
+ end
17
10
  end
18
11
  module Interface
19
- module Instance
12
+ module GettersSetters
20
13
  end
21
14
  end
22
- module ObjectInstance
23
- end
24
15
  end
25
16
  end
26
17
 
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/AccessorDefinitionMethods.rb'
18
+ require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash/LocalConfigurationHash.rb'
19
+ require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb'
20
+ require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/Interface/GettersSetters.rb'
21
+ require_relative 'cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb'
22
+
34
23
  require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb'
35
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Interface/Instance.rb'
24
+ require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash.rb'
@@ -519,7 +519,7 @@ describe CascadingConfiguration::Hash do
519
519
  module SubmoduleIncluding
520
520
  include CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
521
521
  instance_methods.include?( :configuration_setting ).should == true
522
- respond_to?( :configuration_setting ).should == true
522
+ respond_to?( :configuration_setting ).should == false
523
523
  instance_variables.empty?.should == true
524
524
  end
525
525
  # => extending modules and classes get attr_configuration and configurations
@@ -536,7 +536,7 @@ describe CascadingConfiguration::Hash do
536
536
  class ClassIncluding
537
537
  include CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
538
538
  instance_methods.include?( :configuration_setting ).should == true
539
- respond_to?( :configuration_setting ).should == true
539
+ respond_to?( :configuration_setting ).should == false
540
540
  instance_variables.empty?.should == true
541
541
  end
542
542
  setting_class_including_instance = ClassIncluding.new
@@ -597,7 +597,6 @@ describe CascadingConfiguration::Hash do
597
597
  module CascadingConfiguration::Hash::InstanceConfigurationMockModuleExtended
598
598
  extend CascadingConfiguration::Hash
599
599
  # => singleton gets attr_configuration and configurations
600
- respond_to?( :attr_instance_configuration_hash ).should == false
601
600
  instance_methods.include?( :configuration_setting ).should == false
602
601
  instance_variables.empty?.should == true
603
602
  # => including modules and classes get nothing
@@ -1,14 +1,14 @@
1
1
 
2
- require_relative '../../lib/cascading-configuration-hash.rb'
2
+ require_relative '../../../../../lib/cascading-configuration-hash.rb'
3
3
 
4
- describe CascadingConfiguration::LocalConfigurationHash do
4
+ describe CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash do
5
5
 
6
6
  #########
7
7
  # []= #
8
8
  #########
9
9
 
10
10
  it 'can add elements' do
11
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
11
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
12
12
  hash_instance[ :some_setting ] = :some_value
13
13
  hash_instance.should == { :some_setting => :some_value }
14
14
  hash_instance.exclude_array.include?( :some_setting ).should == false
@@ -23,7 +23,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
23
23
  ###########
24
24
 
25
25
  it 'can add elements' do
26
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
26
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
27
27
  hash_instance.store( :some_setting, :some_value )
28
28
  hash_instance.should == { :some_setting => :some_value }
29
29
  hash_instance.exclude_array.include?( :some_setting ).should == false
@@ -38,7 +38,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
38
38
  ############
39
39
 
40
40
  it 'can exclude elements' do
41
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
41
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
42
42
  hash_instance[ :some_setting ] = :some_value
43
43
  hash_instance.delete( :some_setting ).should == :some_value
44
44
  hash_instance.should == {}
@@ -50,7 +50,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
50
50
  ############
51
51
 
52
52
  it 'can merge from another hash' do
53
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
53
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
54
54
  hash_instance.merge!( { :some_setting => :some_value } )
55
55
  hash_instance.should == { :some_setting => :some_value }
56
56
  end
@@ -60,7 +60,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
60
60
  #############
61
61
 
62
62
  it 'can replace existing elements with others' do
63
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
63
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
64
64
  hash_instance.merge!( { :some_setting => :some_value } )
65
65
  hash_instance.should == { :some_setting => :some_value }
66
66
  hash_instance.replace( { :other_setting => :some_value } )
@@ -74,7 +74,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
74
74
  ###########
75
75
 
76
76
  it 'can shift the first element' do
77
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
77
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
78
78
  hash_instance.merge!( { :some_setting => :some_value } )
79
79
  hash_instance.shift.should == [ :some_setting, :some_value ]
80
80
  hash_instance.should == {}
@@ -85,7 +85,7 @@ describe CascadingConfiguration::LocalConfigurationHash do
85
85
  ###########
86
86
 
87
87
  it 'can clear, causing present elements to be excluded' do
88
- hash_instance = ::CascadingConfiguration::LocalConfigurationHash.new
88
+ hash_instance = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
89
89
  hash_instance.merge!( { :some_setting => :some_value } )
90
90
  hash_instance.clear
91
91
  hash_instance.should == {}