cascading-configuration-setting 1.0.0 → 1.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 +369 -0
- data/README.rdoc +27 -116
- data/lib/cascading-configuration-setting.rb +10 -7
- data/lib/cascading-configuration-setting/CascadingConfiguration/{ConfigurationSetting.rb → Setting.rb} +18 -10
- data/lib/cascading-configuration-setting/CascadingConfiguration/Setting/Accessors.rb +51 -0
- data/lib/cascading-configuration-setting/CascadingConfiguration/{ConfigurationSetting → Setting}/ClassInstance.rb +5 -3
- data/lib/cascading-configuration-setting/CascadingConfiguration/{ConfigurationSetting → Setting}/ModuleInstance.rb +7 -4
- data/spec/CascadingConfiguration/ConfigurationSetting/Accessors_spec.rb +16 -15
- data/spec/CascadingConfiguration/ConfigurationSetting_spec.rb +13 -13
- metadata +8 -7
- data/lib/cascading-configuration-setting/CascadingConfiguration/ConfigurationSetting/Accessors.rb +0 -37
data/README.md
ADDED
@@ -0,0 +1,369 @@
|
|
1
|
+
# Cascading Configuration #
|
2
|
+
|
3
|
+
http://rubygems.org/gems/cascading-configuration-setting
|
4
|
+
|
5
|
+
# Description #
|
6
|
+
|
7
|
+
Adds methods for cascading configuration settings. Support package for cascading-configuration.
|
8
|
+
|
9
|
+
# Summary #
|
10
|
+
|
11
|
+
## :attr_configuration ##
|
12
|
+
|
13
|
+
:attr_configuration provides inheritable configuration that cascades downward.
|
14
|
+
|
15
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
16
|
+
|
17
|
+
:attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
|
18
|
+
|
19
|
+
# Install #
|
20
|
+
|
21
|
+
* sudo gem install cascading-configuration-setting
|
22
|
+
|
23
|
+
# Usage #
|
24
|
+
|
25
|
+
Attributes are defined with :attr_configuration.
|
26
|
+
|
27
|
+
Settings are set and acquired by the attribute name declared in :attr_configuration.
|
28
|
+
|
29
|
+
## First Module ##
|
30
|
+
|
31
|
+
1. Define initial configuration in a module.
|
32
|
+
|
33
|
+
A class works just as well, but we can't use a module in the same chain if we start with a class.
|
34
|
+
|
35
|
+
* Include module to enable attr_configuration_setting.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
|
39
|
+
module CascadingConfiguration::MockModule
|
40
|
+
include CascadingConfiguration::Setting
|
41
|
+
end
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
* Declare attr_configuration_setting.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
|
49
|
+
module CascadingConfiguration::MockModule
|
50
|
+
attr_configuration :some_configuration
|
51
|
+
end
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
* Set initial value.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
module CascadingConfiguration::MockModule
|
60
|
+
self.some_configuration = :some_value
|
61
|
+
end
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
* Verify initial configuration value
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
|
69
|
+
module CascadingConfiguration::MockModule
|
70
|
+
# => some_configuration.should == :some_value
|
71
|
+
end
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
## Including Module 1 ##
|
76
|
+
|
77
|
+
2. Include initial module in another module.
|
78
|
+
|
79
|
+
Including the module that has included a CascadingConfiguration module is the same as including a CascadingConfiguration module.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
|
83
|
+
module CascadingConfiguration::MockModule2
|
84
|
+
include CascadingConfiguration::MockModule
|
85
|
+
end
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
* Verify inherited value
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
|
93
|
+
module CascadingConfiguration::MockModule2
|
94
|
+
# => some_configuration.should == :some_value
|
95
|
+
end
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
* Override inherited value
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
|
103
|
+
module CascadingConfiguration::MockModule2
|
104
|
+
self.some_configuration = :module_value
|
105
|
+
end
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
* Verify local override value
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
|
113
|
+
module CascadingConfiguration::MockModule2
|
114
|
+
# => some_configuration.should == :module_value
|
115
|
+
end
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
## Including Module 2 ##
|
120
|
+
|
121
|
+
3. Include second module in another module.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
|
125
|
+
module CascadingConfiguration::MockModule3
|
126
|
+
include CascadingConfiguration::MockModule2
|
127
|
+
end
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
* Verify inherited value
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
|
135
|
+
module CascadingConfiguration::MockModule3
|
136
|
+
# => some_configuration.should == :module_value
|
137
|
+
end
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
## Top Class ##
|
142
|
+
|
143
|
+
4. Include third module in a class.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
|
147
|
+
class CascadingConfiguration::MockClass
|
148
|
+
include CascadingConfiguration::MockModule3
|
149
|
+
end
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
* Verify inherited value
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
|
157
|
+
class CascadingConfiguration::MockClass
|
158
|
+
# => some_configuration.should == :module_value
|
159
|
+
end
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
* Override inherited value
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
|
167
|
+
class CascadingConfiguration::MockClass
|
168
|
+
self.some_configuration = :another_value
|
169
|
+
end
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
* Verify local override value
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
|
177
|
+
class CascadingConfiguration::MockClass
|
178
|
+
# => some_configuration.should == :another_value
|
179
|
+
end
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
## Instance of Top Class ##
|
184
|
+
|
185
|
+
5. Instantiate class.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
|
189
|
+
object_instance_one = CascadingConfiguration::MockClass.new
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
* Verify inherited value
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
|
197
|
+
# => object_instance_one.some_configuration.should == :another_value
|
198
|
+
|
199
|
+
```
|
200
|
+
|
201
|
+
* Override inherited value
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
|
205
|
+
object_instance_one.some_configuration = :yet_another_value
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
* Verify local override value
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
|
213
|
+
# => object_instance_one.some_configuration.should == :yet_another_value
|
214
|
+
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
215
|
+
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
# First Inheriting Class #
|
220
|
+
|
221
|
+
6. Inheriting class.
|
222
|
+
|
223
|
+
Inheriting class should not get any settings from instance of superclass.
|
224
|
+
|
225
|
+
* Verify inherited value
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
|
229
|
+
class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
|
230
|
+
# => some_configuration.should == :another_value
|
231
|
+
end
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
* Override inherited value
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
|
239
|
+
class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
|
240
|
+
self.some_configuration = :a_value_not_yet_used
|
241
|
+
end
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
* Verify local override value
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
|
249
|
+
class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
|
250
|
+
# => some_configuration.should == :a_value_not_yet_used
|
251
|
+
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
252
|
+
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
253
|
+
end
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
## Instance of First Inheriting Class ##
|
258
|
+
|
259
|
+
7. Instantiate first inheriting class.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
|
263
|
+
object_instance_two = CascadingConfiguration::MockClassSub1.new
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
* Verify inherited value
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
|
271
|
+
# => object_instance_two.some_configuration.should == :a_value_not_yet_used
|
272
|
+
# => object_instance_one.some_configuration.should == :yet_another_value
|
273
|
+
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
274
|
+
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
275
|
+
|
276
|
+
```
|
277
|
+
|
278
|
+
## Second Inheriting Class ##
|
279
|
+
|
280
|
+
8. Second inheriting class.
|
281
|
+
|
282
|
+
* Verify inherited value
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
|
286
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
287
|
+
# => some_configuration.should == :a_value_not_yet_used
|
288
|
+
end
|
289
|
+
|
290
|
+
```
|
291
|
+
|
292
|
+
* Override inherited value
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
|
296
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
297
|
+
self.some_configuration = :another_value_not_yet_used
|
298
|
+
end
|
299
|
+
|
300
|
+
```
|
301
|
+
|
302
|
+
* Verify local override value
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
|
306
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
307
|
+
# => some_configuration.should == :another_value_not_yet_used
|
308
|
+
end
|
309
|
+
|
310
|
+
```
|
311
|
+
|
312
|
+
## Instance of Second Inheriting Class ##
|
313
|
+
|
314
|
+
9. Instantiate Second Inheriting Class.
|
315
|
+
|
316
|
+
```ruby
|
317
|
+
|
318
|
+
object_instance_three = CascadingConfiguration::MockClassSub2.new
|
319
|
+
|
320
|
+
```
|
321
|
+
|
322
|
+
* Verify inherited value
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
|
326
|
+
# => object_instance_three.some_configuration.should == :another_value_not_yet_used
|
327
|
+
|
328
|
+
```
|
329
|
+
|
330
|
+
* Override inherited value
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
|
334
|
+
object_instance_three.some_configuration = :one_more_unused_value
|
335
|
+
|
336
|
+
```
|
337
|
+
|
338
|
+
* Verify local override value
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
|
342
|
+
# => object_instance_three.some_configuration.should == :one_more_unused_value
|
343
|
+
|
344
|
+
```
|
345
|
+
|
346
|
+
# License #
|
347
|
+
|
348
|
+
(The MIT License)
|
349
|
+
|
350
|
+
Copyright (c) 2011 Asher
|
351
|
+
|
352
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
353
|
+
a copy of this software and associated documentation files (the
|
354
|
+
'Software'), to deal in the Software without restriction, including
|
355
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
356
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
357
|
+
permit persons to whom the Software is furnished to do so, subject to
|
358
|
+
the following conditions:
|
359
|
+
|
360
|
+
The above copyright notice and this permission notice shall be
|
361
|
+
included in all copies or substantial portions of the Software.
|
362
|
+
|
363
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
364
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
365
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
366
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
367
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
368
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
369
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,121 +1,32 @@
|
|
1
1
|
== Cascading Configuration
|
2
2
|
|
3
|
-
http://rubygems.org/gems/cascading-configuration
|
4
|
-
|
5
|
-
==
|
6
|
-
|
7
|
-
Adds methods for cascading
|
8
|
-
|
9
|
-
==
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
==
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
self.some_configuration = :some_value
|
31
|
-
# => some_configuration.should == :some_value
|
32
|
-
end
|
33
|
-
|
34
|
-
########################
|
35
|
-
# including module 1 #
|
36
|
-
########################
|
37
|
-
|
38
|
-
module CascadingConfiguration::MockModule2
|
39
|
-
include CascadingConfiguration::MockModule
|
40
|
-
# => some_configuration.should == :some_value
|
41
|
-
self.some_configuration = :module_value
|
42
|
-
# => some_configuration.should == :module_value
|
43
|
-
end
|
44
|
-
|
45
|
-
########################
|
46
|
-
# including module 2 #
|
47
|
-
########################
|
48
|
-
|
49
|
-
module CascadingConfiguration::MockModule3
|
50
|
-
include CascadingConfiguration::MockModule2
|
51
|
-
end
|
52
|
-
|
53
|
-
###############
|
54
|
-
# top class #
|
55
|
-
###############
|
56
|
-
|
57
|
-
class CascadingConfiguration::MockClass
|
58
|
-
include CascadingConfiguration::MockModule3
|
59
|
-
# => some_configuration.should == :module_value
|
60
|
-
self.some_configuration = :another_value
|
61
|
-
# => some_configuration.should == :another_value
|
62
|
-
end
|
63
|
-
|
64
|
-
###########################
|
65
|
-
# instance of top class #
|
66
|
-
###########################
|
67
|
-
|
68
|
-
object_instance_one = CascadingConfiguration::MockClass.new
|
69
|
-
# => object_instance_one.some_configuration.should == :another_value
|
70
|
-
object_instance_one.some_configuration = :yet_another_value
|
71
|
-
# => object_instance_one.some_configuration.should == :yet_another_value
|
72
|
-
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
73
|
-
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
74
|
-
|
75
|
-
############################
|
76
|
-
# first inheriting class #
|
77
|
-
############################
|
78
|
-
|
79
|
-
class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
|
80
|
-
# => some_configuration.should == :another_value
|
81
|
-
self.some_configuration = :a_value_not_yet_used
|
82
|
-
# => some_configuration.should == :a_value_not_yet_used
|
83
|
-
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
84
|
-
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
85
|
-
end
|
86
|
-
|
87
|
-
########################################
|
88
|
-
# instance of first inheriting class #
|
89
|
-
########################################
|
90
|
-
|
91
|
-
object_instance_two = CascadingConfiguration::MockClassSub1.new
|
92
|
-
# => object_instance_two.some_configuration.should == :a_value_not_yet_used
|
93
|
-
# => object_instance_one.some_configuration.should == :yet_another_value
|
94
|
-
# => CascadingConfiguration::MockClass.some_configuration.should == :another_value
|
95
|
-
# => CascadingConfiguration::MockModule.some_configuration.should == :some_value
|
96
|
-
|
97
|
-
#############################
|
98
|
-
# second inheriting class #
|
99
|
-
#############################
|
100
|
-
|
101
|
-
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
102
|
-
# => some_configuration.should == :a_value_not_yet_used
|
103
|
-
self.some_configuration = :another_value_not_yet_used
|
104
|
-
# => some_configuration.should == :another_value_not_yet_used
|
105
|
-
end
|
106
|
-
|
107
|
-
#########################################
|
108
|
-
# instance of second inheriting class #
|
109
|
-
#########################################
|
110
|
-
|
111
|
-
object_instance_three = CascadingConfiguration::MockClassSub2.new
|
112
|
-
# => object_instance_three.some_configuration.should == :another_value_not_yet_used
|
113
|
-
object_instance_three.some_configuration = :one_more_unused_value
|
114
|
-
# => object_instance_three.some_configuration.should == :one_more_unused_value
|
115
|
-
|
116
|
-
#############################################################################
|
117
|
-
|
118
|
-
== LICENSE:
|
3
|
+
http://rubygems.org/gems/cascading-configuration
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Adds methods for cascading configurations.
|
8
|
+
|
9
|
+
== Summary
|
10
|
+
|
11
|
+
Cascading configuration methods for single settings, arrays, hashes.
|
12
|
+
|
13
|
+
== :attr_configuration
|
14
|
+
|
15
|
+
:attr_configuration provides inheritable configuration that cascades downward.
|
16
|
+
|
17
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
18
|
+
|
19
|
+
:attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
|
20
|
+
|
21
|
+
== Install
|
22
|
+
|
23
|
+
* sudo gem install cascading-configuration
|
24
|
+
|
25
|
+
== Usage
|
26
|
+
|
27
|
+
See supporting package README markdown files (README.md) for examples.
|
28
|
+
|
29
|
+
== License
|
119
30
|
|
120
31
|
(The MIT License)
|
121
32
|
|
@@ -1,9 +1,12 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
2
|
+
if $cascading_configuration_development
|
3
|
+
require_relative '../../variable/lib/cascading-configuration-variable.rb'
|
4
|
+
else
|
5
|
+
require 'cascading-configuration-variable'
|
6
|
+
end
|
4
7
|
|
5
8
|
module CascadingConfiguration
|
6
|
-
module
|
9
|
+
module Setting
|
7
10
|
module Accessors
|
8
11
|
end
|
9
12
|
module ClassInstance
|
@@ -15,7 +18,7 @@ module CascadingConfiguration
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
require_relative 'cascading-configuration-setting/CascadingConfiguration/
|
19
|
-
require_relative 'cascading-configuration-setting/CascadingConfiguration/
|
20
|
-
require_relative 'cascading-configuration-setting/CascadingConfiguration/
|
21
|
-
require_relative 'cascading-configuration-setting/CascadingConfiguration/
|
21
|
+
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting.rb'
|
22
|
+
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/Accessors.rb'
|
23
|
+
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/ClassInstance.rb'
|
24
|
+
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/ModuleInstance.rb'
|
@@ -1,27 +1,35 @@
|
|
1
1
|
|
2
|
-
module CascadingConfiguration::
|
2
|
+
module CascadingConfiguration::Setting
|
3
3
|
|
4
|
-
|
5
|
-
###################################### Singleton Implementation #########################################
|
6
|
-
###########################################################################################################
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
7
5
|
|
8
6
|
###################
|
9
7
|
# self.included #
|
10
8
|
###################
|
11
9
|
|
12
10
|
def self.included( class_or_module )
|
11
|
+
module_self = self
|
13
12
|
class_or_module.instance_eval do
|
14
|
-
include CascadingConfiguration::
|
15
|
-
extend
|
16
|
-
include CascadingConfiguration::
|
17
|
-
extend CascadingConfiguration::
|
18
|
-
extend CascadingConfiguration::
|
13
|
+
include CascadingConfiguration::Variable
|
14
|
+
extend module_self
|
15
|
+
include CascadingConfiguration::Setting::ObjectInstance
|
16
|
+
extend CascadingConfiguration::Setting::ClassInstance
|
17
|
+
extend CascadingConfiguration::Setting::Accessors
|
18
|
+
# module support
|
19
19
|
unless is_a?( Class )
|
20
|
-
extend CascadingConfiguration::
|
20
|
+
extend CascadingConfiguration::Setting::ModuleInstance
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
#########################
|
26
|
+
# ancestors_to_Object #
|
27
|
+
#########################
|
28
|
+
|
29
|
+
def ancestors_to_Object
|
30
|
+
return ancestors_to_class_or_module_interpolating_module_branches( Object, CascadingConfiguration::Setting::ModuleInstance )
|
31
|
+
end
|
32
|
+
|
25
33
|
########################################
|
26
34
|
# get_configuration_searching_upward #
|
27
35
|
########################################
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Setting::Accessors
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
###################
|
7
|
+
# self.extended #
|
8
|
+
###################
|
9
|
+
|
10
|
+
def self.extended( class_or_module )
|
11
|
+
class_or_module.instance_eval do
|
12
|
+
# accessor support in module to permit method overriding with super
|
13
|
+
unless const_defined?( :AccessorSupportModule )
|
14
|
+
accessor_support_module = Module.new { extend CascadingConfiguration::InternalModuleStub }
|
15
|
+
const_set( :AccessorSupportModule, accessor_support_module )
|
16
|
+
include class_or_module::AccessorSupportModule
|
17
|
+
extend class_or_module::AccessorSupportModule
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#############################
|
23
|
+
# define_cascading_setter #
|
24
|
+
#############################
|
25
|
+
|
26
|
+
def define_cascading_setter( configuration_name )
|
27
|
+
configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
|
28
|
+
self::AccessorSupportModule.module_eval do
|
29
|
+
define_method( configuration_setter_name ) do |value|
|
30
|
+
# configuration setter returns setting variable (variable from self), which is now the ID of value
|
31
|
+
return instance_variable_set( cascading_variable_name( configuration_name ), value )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#############################
|
37
|
+
# define_cascading_getter #
|
38
|
+
#############################
|
39
|
+
|
40
|
+
def define_cascading_getter( configuration_name )
|
41
|
+
configuration_getter_name = configuration_name
|
42
|
+
self::AccessorSupportModule.module_eval do
|
43
|
+
define_method( configuration_getter_name ) do
|
44
|
+
# configuration getter returns current setting value (taken from first superclass with setting)
|
45
|
+
# that means first variable that has been set
|
46
|
+
return get_configuration_searching_upward( configuration_name )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
|
2
|
-
module CascadingConfiguration::
|
2
|
+
module CascadingConfiguration::Setting::ClassInstance
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
3
5
|
|
4
6
|
########################
|
5
7
|
# attr_configuration #
|
@@ -8,9 +10,9 @@ module CascadingConfiguration::ConfigurationSetting::ClassInstance
|
|
8
10
|
def attr_configuration( *property_names )
|
9
11
|
property_names.each do |this_property_name|
|
10
12
|
# define configuration setter
|
11
|
-
|
13
|
+
define_cascading_setter( this_property_name )
|
12
14
|
# define configuration getter
|
13
|
-
|
15
|
+
define_cascading_getter( this_property_name )
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -1,19 +1,22 @@
|
|
1
1
|
|
2
|
-
module CascadingConfiguration::
|
2
|
+
module CascadingConfiguration::Setting::ModuleInstance
|
3
3
|
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
4
6
|
##############
|
5
7
|
# included #
|
6
8
|
##############
|
7
9
|
|
8
10
|
def included( class_or_module )
|
9
|
-
|
11
|
+
super if method_defined?( :super )
|
12
|
+
module_self = self
|
10
13
|
class_or_module.instance_eval do
|
11
|
-
include CascadingConfiguration::
|
14
|
+
include CascadingConfiguration::Setting
|
12
15
|
# when we extend a module (which has happened if we got here)
|
13
16
|
# then we need to make sure when the module we are extending is included
|
14
17
|
# * CascadingConfiguration is included
|
15
18
|
# * the module we extended is used to extend the class/module that included
|
16
|
-
extend
|
19
|
+
extend module_self
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -1,28 +1,29 @@
|
|
1
1
|
|
2
2
|
require_relative '../../../lib/cascading-configuration-setting.rb'
|
3
3
|
|
4
|
-
describe CascadingConfiguration::
|
4
|
+
describe CascadingConfiguration::Setting::Accessors do
|
5
5
|
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
6
|
+
#############################
|
7
|
+
# define_cascading_setter #
|
8
|
+
# define_cascading_getter #
|
9
|
+
#############################
|
10
10
|
|
11
11
|
it 'can define a method to get and set configuration value' do
|
12
|
-
class CascadingConfiguration::
|
13
|
-
include CascadingConfiguration::
|
12
|
+
class CascadingConfiguration::Setting::Mock
|
13
|
+
include CascadingConfiguration::Setting
|
14
14
|
end
|
15
15
|
# setter
|
16
16
|
setter_method_name = ( :some_configuration.to_s + '=' ).to_sym
|
17
|
-
CascadingConfiguration::
|
18
|
-
CascadingConfiguration::
|
19
|
-
CascadingConfiguration::
|
20
|
-
CascadingConfiguration::
|
17
|
+
CascadingConfiguration::Setting::Mock.define_cascading_setter( :some_configuration )
|
18
|
+
CascadingConfiguration::Setting::Mock.methods.include?( setter_method_name ).should == true
|
19
|
+
CascadingConfiguration::Setting::Mock.instance_methods.include?( setter_method_name ).should == true
|
20
|
+
CascadingConfiguration::Setting::Mock.some_configuration = :a_setting_not_yet_used
|
21
|
+
CascadingConfiguration::Setting::Mock.instance_variable_get( :@some_configuration ).should == :a_setting_not_yet_used
|
21
22
|
# getter
|
22
|
-
CascadingConfiguration::
|
23
|
-
CascadingConfiguration::
|
24
|
-
CascadingConfiguration::
|
25
|
-
CascadingConfiguration::
|
23
|
+
CascadingConfiguration::Setting::Mock.define_cascading_getter( :some_configuration )
|
24
|
+
CascadingConfiguration::Setting::Mock.methods.include?( :some_configuration ).should == true
|
25
|
+
CascadingConfiguration::Setting::Mock.instance_methods.include?( :some_configuration ).should == true
|
26
|
+
CascadingConfiguration::Setting::Mock.some_configuration.should == :a_setting_not_yet_used
|
26
27
|
end
|
27
28
|
|
28
29
|
end
|
@@ -1,39 +1,39 @@
|
|
1
1
|
|
2
2
|
require_relative '../../lib/cascading-configuration-setting.rb'
|
3
3
|
|
4
|
-
describe CascadingConfiguration::
|
4
|
+
describe CascadingConfiguration::Setting do
|
5
5
|
|
6
|
-
|
6
|
+
########################
|
7
7
|
# attr_configuration #
|
8
|
-
|
8
|
+
########################
|
9
9
|
|
10
10
|
it 'can define a configuration setting, which is the primary interface' do
|
11
|
-
module CascadingConfiguration::
|
12
|
-
include CascadingConfiguration::
|
11
|
+
module CascadingConfiguration::Setting::MockModule
|
12
|
+
include CascadingConfiguration::Setting
|
13
13
|
attr_configuration :some_other_configuration
|
14
14
|
self.some_other_configuration = :our_setting_value
|
15
15
|
some_other_configuration.should == :our_setting_value
|
16
16
|
end
|
17
|
-
module CascadingConfiguration::
|
18
|
-
include CascadingConfiguration::
|
17
|
+
module CascadingConfiguration::Setting::MockModule2
|
18
|
+
include CascadingConfiguration::Setting::MockModule
|
19
19
|
self.some_other_configuration = :another_value
|
20
20
|
some_other_configuration.should == :another_value
|
21
21
|
end
|
22
|
-
module CascadingConfiguration::
|
23
|
-
include CascadingConfiguration::
|
22
|
+
module CascadingConfiguration::Setting::MockModule3
|
23
|
+
include CascadingConfiguration::Setting::MockModule2
|
24
24
|
some_other_configuration.should == :another_value
|
25
25
|
end
|
26
|
-
class CascadingConfiguration::
|
27
|
-
include CascadingConfiguration::
|
26
|
+
class CascadingConfiguration::Setting::MockClass
|
27
|
+
include CascadingConfiguration::Setting::MockModule3
|
28
28
|
some_other_configuration.should == :another_value
|
29
29
|
self.some_other_configuration = :our_setting_value
|
30
30
|
end
|
31
|
-
class CascadingConfiguration::
|
31
|
+
class CascadingConfiguration::Setting::MockClassSub1 < CascadingConfiguration::Setting::MockClass
|
32
32
|
some_other_configuration.should == :our_setting_value
|
33
33
|
self.some_other_configuration = :our_other_setting_value
|
34
34
|
some_other_configuration.should == :our_other_setting_value
|
35
35
|
end
|
36
|
-
class CascadingConfiguration::
|
36
|
+
class CascadingConfiguration::Setting::MockClassSub2 < CascadingConfiguration::Setting::MockClassSub1
|
37
37
|
some_other_configuration.should == :our_other_setting_value
|
38
38
|
self.some_other_configuration = :a_third_setting_value
|
39
39
|
some_other_configuration.should == :a_third_setting_value
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Asher
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-14 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -39,13 +39,14 @@ extensions: []
|
|
39
39
|
extra_rdoc_files: []
|
40
40
|
|
41
41
|
files:
|
42
|
-
- lib/cascading-configuration-setting/CascadingConfiguration/
|
43
|
-
- lib/cascading-configuration-setting/CascadingConfiguration/
|
44
|
-
- lib/cascading-configuration-setting/CascadingConfiguration/
|
45
|
-
- lib/cascading-configuration-setting/CascadingConfiguration/
|
42
|
+
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/Accessors.rb
|
43
|
+
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/ClassInstance.rb
|
44
|
+
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/ModuleInstance.rb
|
45
|
+
- lib/cascading-configuration-setting/CascadingConfiguration/Setting.rb
|
46
46
|
- lib/cascading-configuration-setting.rb
|
47
47
|
- spec/CascadingConfiguration/ConfigurationSetting/Accessors_spec.rb
|
48
48
|
- spec/CascadingConfiguration/ConfigurationSetting_spec.rb
|
49
|
+
- README.md
|
49
50
|
- README.rdoc
|
50
51
|
has_rdoc: true
|
51
52
|
homepage: http://rubygems.org/gems/cascading-configuration-setting
|
data/lib/cascading-configuration-setting/CascadingConfiguration/ConfigurationSetting/Accessors.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
module CascadingConfiguration::ConfigurationSetting::Accessors
|
3
|
-
|
4
|
-
#################################
|
5
|
-
# define_configuration_setter #
|
6
|
-
#################################
|
7
|
-
|
8
|
-
def define_configuration_setter( configuration_name )
|
9
|
-
configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
|
10
|
-
[ self, eigenclass ].each do |klass_or_eigenclass|
|
11
|
-
klass_or_eigenclass.class_eval do
|
12
|
-
define_method( configuration_setter_name ) do |value|
|
13
|
-
# configuration setter returns setting variable (variable from self), which is now the ID of value
|
14
|
-
return instance_variable_set( cascading_variable_name( configuration_name ), value )
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
#################################
|
21
|
-
# define_configuration_getter #
|
22
|
-
#################################
|
23
|
-
|
24
|
-
def define_configuration_getter( configuration_name )
|
25
|
-
configuration_getter_name = configuration_name
|
26
|
-
[ self, eigenclass ].each do |klass_or_eigenclass|
|
27
|
-
klass_or_eigenclass.class_eval do
|
28
|
-
define_method( configuration_getter_name ) do
|
29
|
-
# configuration getter returns current setting value (taken from first superclass with setting)
|
30
|
-
# that means first variable that has been set
|
31
|
-
return get_configuration_searching_upward( configuration_name )
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|