cascading-configuration-hash 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,13 +14,9 @@ module CascadingConfiguration::Hash::Interface
14
14
 
15
15
  configuration_names.each do |this_configuration_name|
16
16
  if block_given?
17
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
18
- for_instance = false
19
- if ! is_a?( Module ) and ! module_configuration_support_module
20
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self.class )
21
- for_instance = true
22
- end
23
- module_configuration_support_module.set_compositing_proc( this_configuration_name, compositing_block, for_instance )
17
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_compositing_proc( self,
18
+ this_configuration_name,
19
+ compositing_block )
24
20
  end
25
21
  # define configuration setter
26
22
  define_cascading_hash_setter( this_configuration_name )
@@ -42,13 +38,9 @@ module CascadingConfiguration::Hash::Interface
42
38
 
43
39
  configuration_names.each do |this_configuration_name|
44
40
  if block_given?
45
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
46
- for_instance = false
47
- if ! is_a?( Module ) and ! module_configuration_support_module
48
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self.class )
49
- for_instance = true
50
- end
51
- module_configuration_support_module.set_compositing_proc( this_configuration_name, compositing_block, for_instance )
41
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_compositing_proc( self,
42
+ this_configuration_name,
43
+ compositing_block )
52
44
  end
53
45
  # define configuration setter
54
46
  define_class_configuration_hash_setter( this_configuration_name )
@@ -69,17 +61,13 @@ module CascadingConfiguration::Hash::Interface
69
61
  # configuration does not cascade
70
62
  def attr_local_configuration_hash( *configuration_names, & compositing_block )
71
63
 
72
- CascadingConfiguration::Variable.initialize_local_instance_configuration_module( self )
64
+ ::CascadingConfiguration::Variable::ConfigurationSupport.create_local_instance_configuration_support_module( self )
73
65
 
74
66
  configuration_names.each do |this_configuration_name|
75
67
  if block_given?
76
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
77
- for_instance = false
78
- if ! is_a?( Module ) and ! module_configuration_support_module
79
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self.class )
80
- for_instance = true
81
- end
82
- module_configuration_support_module.set_compositing_proc( this_configuration_name, compositing_block, for_instance )
68
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_compositing_proc( self,
69
+ this_configuration_name,
70
+ compositing_block )
83
71
  end
84
72
  # define configuration setter
85
73
  define_local_configuration_hash_setter( this_configuration_name )
@@ -99,17 +87,13 @@ module CascadingConfiguration::Hash::Interface
99
87
  # configuration does not cascade
100
88
  def attr_object_configuration_hash( *configuration_names, & compositing_block )
101
89
 
102
- CascadingConfiguration::Variable.initialize_local_instance_configuration_module( self )
90
+ ::CascadingConfiguration::Variable::ConfigurationSupport.create_local_instance_configuration_support_module( self )
103
91
 
104
92
  configuration_names.each do |this_configuration_name|
105
93
  if block_given?
106
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
107
- for_instance = false
108
- if ! is_a?( Module ) and ! module_configuration_support_module
109
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self.class )
110
- for_instance = true
111
- end
112
- module_configuration_support_module.set_compositing_proc( this_configuration_name, compositing_block, for_instance )
94
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_compositing_proc( self,
95
+ this_configuration_name,
96
+ compositing_block )
113
97
  end
114
98
  # define configuration setter
115
99
  define_object_configuration_hash_setter( this_configuration_name )
@@ -131,13 +115,9 @@ module CascadingConfiguration::Hash::Interface
131
115
 
132
116
  configuration_names.each do |this_configuration_name|
133
117
  if block_given?
134
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
135
- for_instance = false
136
- if ! is_a?( Module ) and ! module_configuration_support_module
137
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self.class )
138
- for_instance = true
139
- end
140
- module_configuration_support_module.set_compositing_proc( this_configuration_name, compositing_block, for_instance )
118
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_compositing_proc( self,
119
+ this_configuration_name,
120
+ compositing_block )
141
121
  end
142
122
  # define configuration setter
143
123
  define_instance_configuration_hash_setter( this_configuration_name )
@@ -1,5 +1,5 @@
1
1
 
2
- class CascadingConfiguration::Hash::CompositingHash < Hash
2
+ class CascadingConfiguration::Hash::CompositingHash < ::Hash
3
3
 
4
4
  attr_accessor :local_cascading_hash
5
5
 
@@ -9,34 +9,24 @@ class CascadingConfiguration::Hash::CompositingHash < Hash
9
9
 
10
10
  def initialize( configuration_instance, configuration_name )
11
11
 
12
- for_instance = false
13
-
14
12
  @configuration_instance = configuration_instance
15
13
 
16
- module_configuration_module = ::CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance )
17
- if ! module_configuration_module and ! configuration_instance.is_a?( Module )
18
- module_configuration_module = ::CascadingConfiguration::Variable.module_configuration_support_module( configuration_instance.class )
19
- for_instance = true
20
- end
21
-
22
14
  @configuration_name = configuration_name
23
15
 
24
16
  # store self for sub composites
25
- module_configuration_module.set_configuration_variable( configuration_name, self, for_instance )
26
-
17
+ ::CascadingConfiguration::Variable::ConfigurationSupport.set_configuration_variable( configuration_instance, configuration_name, self )
18
+
27
19
  # if first ancestor can have a composite hash, register self with it in case it gets updated in the future
28
- super_configuration_module = nil
29
- if for_instance
30
- super_configuration_module = module_configuration_module
31
- else
32
- super_configuration_module = module_configuration_module.super_configuration_module( configuration_name )
33
- end
34
-
35
- if super_configuration_module and
36
- @super_composite_hash = super_configuration_module.get_configuration_variable( configuration_name ) and
37
- @super_composite_hash.respond_to?( :register_sub_composite_hash )
20
+ if ancestor = ::CascadingConfiguration::Variable::ConfigurationSupport.ancestor( configuration_instance, configuration_name )
21
+
22
+ @super_composite_hash = ::CascadingConfiguration::Variable::ConfigurationSupport.get_configuration_variable( ancestor,
23
+ configuration_name )
38
24
 
39
- @super_composite_hash.register_sub_composite_hash( self )
25
+ if @super_composite_hash.respond_to?( :register_sub_composite_hash )
26
+ @super_composite_hash.register_sub_composite_hash( self )
27
+ else
28
+ @super_composite_hash = nil
29
+ end
40
30
 
41
31
  end
42
32
 
@@ -44,7 +34,7 @@ class CascadingConfiguration::Hash::CompositingHash < Hash
44
34
  @local_cascading_hash = ::CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash.new
45
35
 
46
36
  # we may later have our own child composites that register with us
47
- @sub_composite_hashes = ::Array.new
37
+ @sub_composite_hashes = [ ]
48
38
 
49
39
  # initialize self status for parent and local
50
40
  update_self_as_cascading_composite
@@ -198,19 +188,11 @@ class CascadingConfiguration::Hash::CompositingHash < Hash
198
188
 
199
189
  def update_composite_self_for_parent_hash( parent_hash, second_hash )
200
190
 
201
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( @configuration_instance )
202
- for_instance = false
203
-
204
- if ! module_configuration_support_module and ! is_a?( Module )
205
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( @configuration_instance.class )
206
- for_instance = true
207
- end
208
-
209
- if compositing_proc = module_configuration_support_module.get_compositing_proc( @configuration_name, for_instance )
191
+ if compositing_proc = ::CascadingConfiguration::Variable::ConfigurationSupport.get_compositing_proc_searching_upward( @configuration_instance, @configuration_name )
210
192
  # if we have a compositing proc defined, use its result to replace
211
- parent_hash_copy = Hash.new
193
+ parent_hash_copy = { }
212
194
  parent_hash_copy.merge!( parent_hash ) if parent_hash
213
- second_hash_copy = Hash.new
195
+ second_hash_copy = { }
214
196
  second_hash_copy.merge!( second_hash ) if second_hash
215
197
  composite_result = compositing_proc.call( parent_hash_copy, second_hash_copy )
216
198
  super_replace( composite_result )
@@ -8,7 +8,7 @@ class CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash < Ha
8
8
  ################
9
9
 
10
10
  def initialize()
11
- @exclude_array = ::Array.new
11
+ @exclude_array = [ ]
12
12
  end
13
13
 
14
14
  #########
@@ -89,7 +89,7 @@ class CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash < Ha
89
89
  ##########################
90
90
 
91
91
  def add_to_exclude_array( *elements )
92
- @exclude_array ||= ::Array.new
92
+ @exclude_array ||= [ ]
93
93
  @exclude_array += elements
94
94
  @exclude_array.sort!.uniq!
95
95
  end
@@ -103,7 +103,7 @@ class CascadingConfiguration::Hash::CompositingHash::LocalConfigurationHash < Ha
103
103
  @exclude_array -= elements
104
104
  @exclude_array.sort!.uniq!
105
105
  else
106
- @exclude_array ||= ::Array.new
106
+ @exclude_array ||= [ ]
107
107
  end
108
108
  end
109
109
 
@@ -9,8 +9,8 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
9
9
 
10
10
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
11
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 )
12
+ configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.configuration_support_module( self )
13
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
14
14
 
15
15
  array_setter_proc = Proc.new do |hash|
16
16
 
@@ -18,7 +18,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
18
18
 
19
19
  end
20
20
 
21
- module_configuration_support_module.module_eval do
21
+ configuration_support_module.module_eval do
22
22
  define_method( configuration_setter_name, & array_setter_proc )
23
23
  end
24
24
 
@@ -36,8 +36,8 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
36
36
 
37
37
  configuration_getter_name = configuration_name
38
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 )
39
+ configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.configuration_support_module( self )
40
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
41
41
 
42
42
  array_getter_proc = Proc.new do
43
43
 
@@ -45,7 +45,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
45
45
 
46
46
  end
47
47
 
48
- module_configuration_support_module.module_eval do
48
+ configuration_support_module.module_eval do
49
49
  define_method( configuration_getter_name, & array_getter_proc )
50
50
  end
51
51
 
@@ -63,9 +63,9 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
63
63
 
64
64
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
65
65
 
66
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
66
+ configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.configuration_support_module( self )
67
67
 
68
- module_configuration_support_module.module_eval do
68
+ configuration_support_module.module_eval do
69
69
  define_method( configuration_setter_name ) do |hash|
70
70
 
71
71
  return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name ).replace( hash )
@@ -83,9 +83,9 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
83
83
 
84
84
  configuration_getter_name = configuration_name
85
85
 
86
- module_configuration_support_module = CascadingConfiguration::Variable.module_configuration_support_module( self )
86
+ configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.configuration_support_module( self )
87
87
 
88
- module_configuration_support_module.module_eval do
88
+ configuration_support_module.module_eval do
89
89
  define_method( configuration_getter_name ) do
90
90
 
91
91
  return CascadingConfiguration::Hash.composite_hash_for_cascading_configuration( self, configuration_name )
@@ -103,8 +103,8 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
103
103
 
104
104
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
105
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 )
106
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
107
+ local_instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.local_instance_configuration_support_module( self )
108
108
 
109
109
  local_setter_proc = Proc.new do |hash|
110
110
 
@@ -130,9 +130,9 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
130
130
 
131
131
  configuration_getter_name = configuration_name
132
132
 
133
- instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
133
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
134
134
 
135
- local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
135
+ local_instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.local_instance_configuration_support_module( self )
136
136
 
137
137
  local_getter_proc = Proc.new do
138
138
 
@@ -158,7 +158,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
158
158
 
159
159
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
160
160
 
161
- instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
161
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
162
162
 
163
163
  instance_configuration_support_module.module_eval do
164
164
  define_method( configuration_setter_name ) do |hash|
@@ -178,7 +178,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
178
178
 
179
179
  configuration_getter_name = configuration_name
180
180
 
181
- instance_configuration_support_module = CascadingConfiguration::Variable.instance_configuration_support_module( self )
181
+ instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.instance_configuration_support_module( self )
182
182
 
183
183
  instance_configuration_support_module.module_eval do
184
184
  define_method( configuration_getter_name ) do
@@ -198,7 +198,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
198
198
 
199
199
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
200
200
 
201
- local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
201
+ local_instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.local_instance_configuration_support_module( self )
202
202
 
203
203
  local_instance_configuration_support_module.module_eval do
204
204
  define_method( configuration_setter_name ) do |hash|
@@ -218,7 +218,7 @@ module CascadingConfiguration::Hash::Interface::GettersSetters
218
218
 
219
219
  configuration_getter_name = configuration_name
220
220
 
221
- local_instance_configuration_support_module = CascadingConfiguration::Variable.local_instance_configuration_support_module( self )
221
+ local_instance_configuration_support_module = ::CascadingConfiguration::Variable::ConfigurationSupport.local_instance_configuration_support_module( self )
222
222
 
223
223
  local_instance_configuration_support_module.module_eval do
224
224
  define_method( configuration_getter_name ) do
@@ -8,16 +8,9 @@ module CascadingConfiguration::Hash::ModuleSupportMethods
8
8
  def composite_hash_for_cascading_configuration( configuration_instance, configuration_name )
9
9
 
10
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 )
11
+
12
+ if ::CascadingConfiguration::Variable::ConfigurationSupport.has_configuration_variable?( configuration_instance, configuration_name )
13
+ composite_hash = ::CascadingConfiguration::Variable::ConfigurationSupport.get_configuration_variable( configuration_instance, configuration_name )
21
14
  else
22
15
  composite_hash = ::CascadingConfiguration::Hash::CompositingHash.new( configuration_instance, configuration_name )
23
16
  end
@@ -15,6 +15,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
15
15
 
16
16
  module CascadingConfiguration::Hash::CompositingHash::CIMock01A
17
17
  include CascadingConfiguration::Hash::CompositingHash::CCHMock01
18
+ def self.some_configuration
19
+ end
18
20
  end
19
21
  module CascadingConfiguration::Hash::CompositingHash::CIMock01B
20
22
  include CascadingConfiguration::Hash::CompositingHash::CIMock01A
@@ -62,6 +64,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
62
64
 
63
65
  module CascadingConfiguration::Hash::CompositingHash::CIMock02A
64
66
  include CascadingConfiguration::Hash::CompositingHash::CCHMock02
67
+ def self.some_configuration
68
+ end
65
69
  end
66
70
  module CascadingConfiguration::Hash::CompositingHash::CIMock02B
67
71
  include CascadingConfiguration::Hash::CompositingHash::CIMock02A
@@ -109,6 +113,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
109
113
 
110
114
  module CascadingConfiguration::Hash::CompositingHash::CIMock03A
111
115
  include CascadingConfiguration::Hash::CompositingHash::CCHMock03
116
+ def self.some_configuration
117
+ end
112
118
  end
113
119
  module CascadingConfiguration::Hash::CompositingHash::CIMock03B
114
120
  include CascadingConfiguration::Hash::CompositingHash::CIMock03A
@@ -161,6 +167,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
161
167
 
162
168
  module CascadingConfiguration::Hash::CompositingHash::CIMock04A
163
169
  include CascadingConfiguration::Hash::CompositingHash::CCHMock04
170
+ def self.some_configuration
171
+ end
164
172
  end
165
173
  module CascadingConfiguration::Hash::CompositingHash::CIMock04B
166
174
  include CascadingConfiguration::Hash::CompositingHash::CIMock04A
@@ -208,6 +216,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
208
216
 
209
217
  module CascadingConfiguration::Hash::CompositingHash::CIMock05A
210
218
  include CascadingConfiguration::Hash::CompositingHash::CCHMock05
219
+ def self.some_configuration
220
+ end
211
221
  end
212
222
  module CascadingConfiguration::Hash::CompositingHash::CIMock05B
213
223
  include CascadingConfiguration::Hash::CompositingHash::CIMock05A
@@ -250,6 +260,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
250
260
 
251
261
  module CascadingConfiguration::Hash::CompositingHash::CIMock06A
252
262
  include CascadingConfiguration::Hash::CompositingHash::CCHMock06
263
+ def self.some_configuration
264
+ end
253
265
  end
254
266
  module CascadingConfiguration::Hash::CompositingHash::CIMock06B
255
267
  include CascadingConfiguration::Hash::CompositingHash::CIMock06A
@@ -302,6 +314,8 @@ describe CascadingConfiguration::Hash::CompositingHash do
302
314
 
303
315
  module CascadingConfiguration::Hash::CompositingHash::CIMock07A
304
316
  include CascadingConfiguration::Hash::CompositingHash::CCHMock07
317
+ def self.some_configuration
318
+ end
305
319
  end
306
320
  module CascadingConfiguration::Hash::CompositingHash::CIMock07B
307
321
  include CascadingConfiguration::Hash::CompositingHash::CIMock07A
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cascading-configuration-hash
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.1
5
+ version: 1.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Asher
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-18 00:00:00 Z
13
+ date: 2012-02-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: module-cluster