cascading-configuration-setting 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Cascading Configuration #
1
+ # Cascading Configuration Setting #
2
2
 
3
3
  http://rubygems.org/gems/cascading-configuration-setting
4
4
 
@@ -7,341 +7,258 @@ http://rubygems.org/gems/cascading-configuration-setting
7
7
  Adds methods for cascading configuration settings. Support package for cascading-configuration.
8
8
 
9
9
  # Summary #
10
-
11
- ## :attr_configuration ##
12
-
13
- :attr_configuration provides inheritable configuration that cascades downward.
14
10
 
15
- Configuration inheritance can cascade through modules, classes, and instances.
11
+ Cascading configuration methods for settings, which returns the appropriate lowest accumulated value. Configuration inheritance can cascade through modules, classes, and to instances.
16
12
 
17
- :attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
13
+ This means that we can create configuration modules, optionally setting configuration defaults, and include those configuration modules in other modules or classes.
18
14
 
19
15
  # Install #
20
16
 
21
- * sudo gem install cascading-configuration-setting
17
+ * sudo gem install cascading-configuration
22
18
 
23
19
  # Usage #
24
20
 
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.
21
+ Including the module will enable support for singleton and for instances.
36
22
 
37
23
  ```ruby
38
-
39
- module CascadingConfiguration::MockModule
40
- include CascadingConfiguration::Setting
41
- end
42
-
24
+ module AnyModuleOrClass
25
+ include CascadingConfiguration::Setting
26
+ end
43
27
  ```
44
28
 
45
- * Declare attr_configuration_setting.
29
+ Extending the module will enable support for singleton only.
46
30
 
47
31
  ```ruby
48
-
49
- module CascadingConfiguration::MockModule
50
- attr_configuration :some_configuration
51
- end
52
-
32
+ module AnyModuleOrClass
33
+ extend CascadingConfiguration::Setting
34
+ end
53
35
  ```
54
36
 
55
- * Set initial value.
37
+ Including or extending CascadingConfiguration includes or extends:
56
38
 
57
- ```ruby
39
+ * CascadingConfiguration::Variable
58
40
 
59
- module CascadingConfiguration::MockModule
60
- self.some_configuration = :some_value
61
- end
41
+ ## :attr_configuration ##
62
42
 
63
- ```
43
+ :attr_configuration provides inheritable single-object configurations that cascades downward. The value lowest in the ancestor hierarchy will be returned.
64
44
 
65
- * Verify initial configuration value
45
+ Define initial configuration in a module or class:
66
46
 
67
47
  ```ruby
48
+ module SomeModule
68
49
 
69
- module CascadingConfiguration::MockModule
70
- # => some_configuration.should == :some_value
71
- end
72
-
73
- ```
74
-
75
- ## Including Module 1 ##
50
+ include CascadingConfiguration::Setting
76
51
 
77
- 2. Include initial module in another module.
52
+ attr_configuration :some_setting
78
53
 
79
- Including the module that has included a CascadingConfiguration module is the same as including a CascadingConfiguration module.
54
+ some_setting # => nil
80
55
 
81
- ```ruby
56
+ # note: if we don't specify the receiver here (self) assignment creates local variable instead
57
+ self.some_setting = :some_value
82
58
 
83
- module CascadingConfiguration::MockModule2
84
- include CascadingConfiguration::MockModule
85
- end
59
+ some_setting # => :some_value
86
60
 
61
+ end
87
62
  ```
88
63
 
89
- * Verify inherited value
64
+ Include initial module in a module or class:
90
65
 
91
66
  ```ruby
67
+ class SomeClass
92
68
 
93
- module CascadingConfiguration::MockModule2
94
- # => some_configuration.should == :some_value
95
- end
69
+ include SomeModule
96
70
 
97
- ```
71
+ some_setting # => :some_value
98
72
 
99
- * Override inherited value
73
+ self.some_setting = :some_other_value
100
74
 
101
- ```ruby
75
+ some_setting # => :some_other_value
102
76
 
103
- module CascadingConfiguration::MockModule2
104
- self.some_configuration = :module_value
105
- end
77
+ SomeModule.some_setting # => :some_value
106
78
 
79
+ end
107
80
  ```
108
81
 
109
- * Verify local override value
82
+ And it cascades to instances:
110
83
 
111
84
  ```ruby
85
+ instance = SomeClass.new
112
86
 
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
87
+ instance.some_setting.should == :some_value
124
88
 
125
- module CascadingConfiguration::MockModule3
126
- include CascadingConfiguration::MockModule2
127
- end
89
+ instance.some_setting = :another_value
128
90
 
91
+ instance.some_setting.should == :another_value
129
92
  ```
130
93
 
131
- * Verify inherited value
94
+ ### :attr_module_configuration, :attr_class_configuration ###
132
95
 
133
- ```ruby
96
+ :attr_class_configuration works like :attr_configuration but does not cascade to instances.
134
97
 
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.
98
+ Define initial configuration in a module or class:
144
99
 
145
100
  ```ruby
101
+ module SomeModule
146
102
 
147
- class CascadingConfiguration::MockClass
148
- include CascadingConfiguration::MockModule3
149
- end
103
+ include CascadingConfiguration::Setting
150
104
 
151
- ```
105
+ attr_class_configuration :some_setting
152
106
 
153
- * Verify inherited value
107
+ some_setting # => nil
154
108
 
155
- ```ruby
109
+ self.some_setting = :some_value
156
110
 
157
- class CascadingConfiguration::MockClass
158
- # => some_configuration.should == :module_value
159
- end
111
+ some_setting # => :some_value
160
112
 
113
+ end
161
114
  ```
162
115
 
163
- * Override inherited value
116
+ Include initial module in a module or class:
164
117
 
165
118
  ```ruby
119
+ class SomeClass
166
120
 
167
- class CascadingConfiguration::MockClass
168
- self.some_configuration = :another_value
169
- end
121
+ include SomeModule
170
122
 
171
- ```
123
+ some_setting # => :some_value
172
124
 
173
- * Verify local override value
125
+ self.some_setting = :some_other_value
174
126
 
175
- ```ruby
127
+ some_setting # => :some_other_value
176
128
 
177
- class CascadingConfiguration::MockClass
178
- # => some_configuration.should == :another_value
179
- end
129
+ SomeModule.some_setting # => :some_value
180
130
 
131
+ end
181
132
  ```
182
133
 
183
- ## Instance of Top Class ##
184
-
185
- 5. Instantiate class.
134
+ And it does not cascade to instances:
186
135
 
187
136
  ```ruby
137
+ instance = SomeClass.new
188
138
 
189
- object_instance_one = CascadingConfiguration::MockClass.new
190
-
139
+ instance.respond_to?( :some_setting ).should == false
191
140
  ```
192
141
 
193
- * Verify inherited value
194
-
195
- ```ruby
196
-
197
- # => object_instance_one.some_configuration.should == :another_value
142
+ ### :attr_local_configuration ###
198
143
 
199
- ```
144
+ :attr_local_configuration works like :attr_configuration but does not cascade. This is primarily useful for creating local configurations maintained in parallel with cascading configurations (for instance, with the same variable prefixes), for overriding the local configuration method, and for hiding the configuration variable (coming soon).
200
145
 
201
- * Override inherited value
146
+ Define initial configuration in a module or class:
202
147
 
203
148
  ```ruby
149
+ module SomeModule
204
150
 
205
- object_instance_one.some_configuration = :yet_another_value
151
+ include CascadingConfiguration::Setting
206
152
 
207
- ```
153
+ attr_local_configuration :some_setting
208
154
 
209
- * Verify local override value
155
+ some_setting # => nil
210
156
 
211
- ```ruby
157
+ self.some_setting = :some_value
212
158
 
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
159
+ some_setting # => :some_value
216
160
 
161
+ end
217
162
  ```
218
163
 
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
164
+ Include initial module in a module or class:
226
165
 
227
166
  ```ruby
167
+ class SomeClass
228
168
 
229
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
230
- # => some_configuration.should == :another_value
231
- end
232
-
233
- ```
234
-
235
- * Override inherited value
236
-
237
- ```ruby
169
+ include SomeModule
238
170
 
239
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
240
- self.some_configuration = :a_value_not_yet_used
241
- end
171
+ respond_to?( :some_setting ).should == false
242
172
 
173
+ end
243
174
  ```
244
175
 
245
- * Verify local override value
246
-
247
- ```ruby
176
+ ## Additional Functionality ##
248
177
 
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
178
+ Cascading-configuration also provides several other convenience functions.
254
179
 
255
- ```
180
+ ### Variable Name Prefixing ###
256
181
 
257
- ## Instance of First Inheriting Class ##
182
+ Configuration prefix can be set so that variables use property name with the configuration prefix prepended.
258
183
 
259
- 7. Instantiate first inheriting class.
184
+ This can be done in order defined (current configuration prefix is stored for configuration), or it can be specified on a per-property basis.
260
185
 
261
186
  ```ruby
187
+ module SomeModule
262
188
 
263
- object_instance_two = CascadingConfiguration::MockClassSub1.new
189
+ include CascadingConfiguration
264
190
 
265
- ```
191
+ attr_configuration :some_setting
266
192
 
267
- * Verify inherited value
193
+ self.some_setting = :a_value
268
194
 
269
- ```ruby
195
+ instance_variables.include?( :@some_setting ) # => true
270
196
 
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
197
+ # we can declare a prefix for specific properties
198
+ attr_configuration_prefix '__configuration_prefix__', :some_other_setting
275
199
 
276
- ```
200
+ attr_configuration :some_other_setting, :yet_another_setting
277
201
 
278
- ## Second Inheriting Class ##
202
+ self.some_setting = :some_value
203
+ self.yet_another_setting = :another_value
279
204
 
280
- 8. Second inheriting class.
205
+ instance_variables.include?( :@some_other_setting ) # => false
206
+ instance_variables.include?( :@__configuration_prefix__some_other_setting ) # => true
207
+ instance_variables.include?( :@yet_another_setting ) # => true
281
208
 
282
- * Verify inherited value
209
+ # or we can declare a prefix for all properties defined after prefix is declared
210
+ attr_configuration_prefix '__another_configuration_prefix__'
283
211
 
284
- ```ruby
212
+ attr_configuration :still_another_prefix
285
213
 
286
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
287
- # => some_configuration.should == :a_value_not_yet_used
288
- end
214
+ instance_variables.include?( :@still_another_prefix ) # => false
215
+ instance_variables.include?( :@__another_configuration_prefix__still_another_prefix ) # => true
289
216
 
217
+ end
290
218
  ```
291
219
 
292
- * Override inherited value
293
-
294
- ```ruby
220
+ ### Method Redefinition ###
295
221
 
296
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
297
- self.some_configuration = :another_value_not_yet_used
298
- end
222
+ Any declared configuration is defined in order to support locally redefining the method and accessing the original by calling super.
299
223
 
300
- ```
224
+ ```ruby
225
+ module SomeModule
301
226
 
302
- * Verify local override value
227
+ include CascadingConfiguration
303
228
 
304
- ```ruby
229
+ attr_configuration :some_array_setting
305
230
 
306
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
307
- # => some_configuration.should == :another_value_not_yet_used
231
+ def some_array_setting=( value )
232
+ puts 'Replacing configuration array!'
233
+ super
308
234
  end
309
235
 
236
+ end
310
237
  ```
311
238
 
312
- ## Instance of Second Inheriting Class ##
239
+ ### Hidden Configuration ###
313
240
 
314
- 9. Instantiate Second Inheriting Class.
241
+ #### :attr_hide ####
315
242
 
316
- ```ruby
317
-
318
- object_instance_three = CascadingConfiguration::MockClassSub2.new
319
-
320
- ```
321
-
322
- * Verify inherited value
243
+ Coming soon.
323
244
 
324
245
  ```ruby
246
+ module SomeModule
325
247
 
326
- # => object_instance_three.some_configuration.should == :another_value_not_yet_used
248
+ include CascadingConfiguration
327
249
 
328
- ```
250
+ attr_configuration :some_array_setting
329
251
 
330
- * Override inherited value
252
+ instance_variables.include?( :@some_array_setting ) # => true
331
253
 
332
- ```ruby
254
+ attr_hide :some_array_setting
333
255
 
334
- object_instance_three.some_configuration = :one_more_unused_value
256
+ instance_variables.include?( :@some_array_setting ) # => false
335
257
 
258
+ end
336
259
  ```
337
260
 
338
- * Verify local override value
339
-
340
- ```ruby
341
-
342
- # => object_instance_three.some_configuration.should == :one_more_unused_value
343
-
344
- ```
261
+ Causes configuration variable to be stored in external context so that it is not included in instance variables.
345
262
 
346
263
  # License #
347
264
 
@@ -366,4 +283,4 @@ Inheriting class should not get any settings from instance of superclass.
366
283
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
367
284
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
368
285
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
369
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
286
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,22 +1,24 @@
1
1
  == Cascading Configuration
2
2
 
3
- http://rubygems.org/gems/cascading-configuration
3
+ http://rubygems.org/gems/cascading-configuration-setting
4
4
 
5
5
  == Description
6
6
 
7
- Adds methods for cascading configurations.
7
+ Adds methods for cascading configuration settings. Support package for cascading-configuration.
8
8
 
9
9
  == Summary
10
10
 
11
- Cascading configuration methods for single settings, arrays, hashes.
11
+ Cascading configuration methods for settings, which returns the appropriate lowest accumulated value. Configuration inheritance can cascade through modules, classes, and to instances.
12
+
13
+ This means that we can create configuration modules, optionally setting configuration defaults, and include those configuration modules in other modules or classes.
12
14
 
13
15
  == :attr_configuration
14
16
 
15
- :attr_configuration provides inheritable configuration that cascades downward.
17
+ :attr_configuration provides inheritable single-object configurations that cascades downward. The value lowest in the ancestor hierarchy will be returned.
16
18
 
17
- Configuration inheritance can cascade through modules, classes, and instances.
19
+ :attr_class_configuration works like :attr_configuration but does not cascade to instances.
18
20
 
19
- :attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
21
+ :attr_local_configuration works like :attr_configuration but does not cascade. This is primarily useful for creating local configurations maintained in parallel with cascading configurations (for instance, with the same variable prefixes), for overriding the local configuration method, and for hiding the configuration variable (coming soon).
20
22
 
21
23
  == Install
22
24
 
@@ -24,7 +26,7 @@ Configuration inheritance can cascade through modules, classes, and instances.
24
26
 
25
27
  == Usage
26
28
 
27
- See supporting package README markdown files (README.md) for examples.
29
+ See README.md
28
30
 
29
31
  == License
30
32
 
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  module CascadingConfiguration
9
9
  module Setting
10
- module ConfigurationAccessors
10
+ module AccessorDefinitionMethods
11
11
  end
12
12
  module Interface
13
13
  end
@@ -19,6 +19,6 @@ module CascadingConfiguration
19
19
  end
20
20
 
21
21
  require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting.rb'
22
- require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/ConfigurationAccessors.rb'
22
+ require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb'
23
23
  require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/Interface.rb'
24
24
  require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/ModuleInclusionExtensionSupport.rb'
@@ -33,7 +33,7 @@ module CascadingConfiguration::Setting
33
33
  class_or_module.instance_eval do
34
34
  extend module_self
35
35
  extend module_self::Interface
36
- extend module_self::ConfigurationAccessors
36
+ extend module_self::AccessorDefinitionMethods
37
37
  extend module_self::ModuleInclusionExtensionSupport unless is_a?( Class )
38
38
  end
39
39
  end
@@ -46,7 +46,7 @@ module CascadingConfiguration::Setting
46
46
  module_self = self
47
47
  class_or_module.instance_eval do
48
48
  extend module_self::Interface
49
- extend module_self::ConfigurationAccessors
49
+ extend module_self::AccessorDefinitionMethods
50
50
  end
51
51
  end
52
52
 
@@ -1,5 +1,5 @@
1
1
 
2
- module CascadingConfiguration::Setting::ConfigurationAccessors
2
+ module CascadingConfiguration::Setting::AccessorDefinitionMethods
3
3
 
4
4
  extend CascadingConfiguration::InternalModuleStub
5
5
 
@@ -9,11 +9,11 @@ module CascadingConfiguration::Setting::ConfigurationAccessors
9
9
 
10
10
  def define_cascading_setter( configuration_name )
11
11
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
12
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_support_module|
13
- accessor_support_module.module_eval do
12
+ [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
13
+ accessor_module_support.module_eval do
14
14
  define_method( configuration_setter_name ) do |value|
15
15
  # configuration setter returns setting variable (variable from self), which is now the ID of value
16
- return instance_variable_set( accessor_support_module.cascading_variable_name( configuration_name ), value )
16
+ return instance_variable_set( accessor_module_support.cascading_variable_name( configuration_name ), value )
17
17
  end
18
18
  end
19
19
  end
@@ -26,8 +26,8 @@ module CascadingConfiguration::Setting::ConfigurationAccessors
26
26
  def define_cascading_getter( configuration_name )
27
27
  configuration_getter_name = configuration_name
28
28
  module_self = self
29
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_support_module|
30
- accessor_support_module.module_eval do
29
+ [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
30
+ accessor_module_support.module_eval do
31
31
  define_method( configuration_getter_name ) do
32
32
  # configuration getter returns current setting value (taken from first superclass with setting)
33
33
  # that means first variable that has been set
@@ -46,7 +46,7 @@ module CascadingConfiguration::Setting::ConfigurationAccessors
46
46
  accessor_module_support.module_eval do
47
47
  define_method( configuration_setter_name ) do |value|
48
48
  # configuration setter returns setting variable (variable from self), which is now the ID of value
49
- return instance_variable_set( accessor_support_module.cascading_variable_name( configuration_name ), value )
49
+ return instance_variable_set( accessor_module_support.cascading_variable_name( configuration_name ), value )
50
50
  end
51
51
  end
52
52
  end
@@ -72,10 +72,10 @@ module CascadingConfiguration::Setting::ConfigurationAccessors
72
72
 
73
73
  def define_local_configuration_setter( configuration_name )
74
74
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
75
- accessor_instance_support.module_eval do
75
+ accessor_local_instance_support.module_eval do
76
76
  define_method( configuration_setter_name ) do |value|
77
77
  # configuration setter returns setting variable (variable from self), which is now the ID of value
78
- return instance_variable_set( accessor_support_module.cascading_variable_name( configuration_name ), value )
78
+ return instance_variable_set( accessor_module_support.cascading_variable_name( configuration_name ), value )
79
79
  end
80
80
  end
81
81
  end
@@ -86,11 +86,11 @@ module CascadingConfiguration::Setting::ConfigurationAccessors
86
86
 
87
87
  def define_local_configuration_getter( configuration_name )
88
88
  configuration_getter_name = configuration_name
89
- accessor_instance_support.module_eval do
89
+ accessor_local_instance_support.module_eval do
90
90
  define_method( configuration_getter_name ) do
91
91
  # configuration getter returns current setting value (taken from first superclass with setting)
92
92
  # that means first variable that has been set
93
- return get_configuration_searching_upward( configuration_name )
93
+ return instance_variable_get( accessor_module_support.cascading_variable_name( configuration_name ) )
94
94
  end
95
95
  end
96
96
  end
@@ -18,13 +18,13 @@ module CascadingConfiguration::Setting::Interface
18
18
  end
19
19
  end
20
20
 
21
- ##############################
22
- # attr_class_configuration #
23
- ##############################
21
+ ###############################
22
+ # attr_module_configuration #
23
+ ###############################
24
24
 
25
25
  # defines configuration in class or module
26
26
  # configuration cascades downward to last class or module
27
- def attr_class_configuration( *property_names )
27
+ def attr_module_configuration( *property_names )
28
28
  property_names.each do |this_property_name|
29
29
  # define configuration setter
30
30
  define_class_configuration_setter( this_property_name )
@@ -32,6 +32,7 @@ module CascadingConfiguration::Setting::Interface
32
32
  define_class_configuration_getter( this_property_name )
33
33
  end
34
34
  end
35
+ alias_method :attr_class_configuration, :attr_module_configuration
35
36
 
36
37
  ##############################
37
38
  # attr_local_configuration #
@@ -40,6 +41,7 @@ module CascadingConfiguration::Setting::Interface
40
41
  # defines configuration in present class or module context
41
42
  # configuration does not cascade
42
43
  def attr_local_configuration( *property_names )
44
+ CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
43
45
  property_names.each do |this_property_name|
44
46
  # define configuration setter
45
47
  define_local_configuration_setter( this_property_name )
@@ -1,7 +1,7 @@
1
1
 
2
2
  require_relative '../../../lib/cascading-configuration-setting.rb'
3
3
 
4
- describe CascadingConfiguration::Setting::ConfigurationAccessors do
4
+ describe CascadingConfiguration::Setting::AccessorDefinitionMethods do
5
5
 
6
6
  #############################
7
7
  # define_cascading_setter #
@@ -17,7 +17,7 @@ describe CascadingConfiguration::Setting do
17
17
 
18
18
  # possibilities:
19
19
  # * module extended with setting
20
- module CascadingConfiguration::Setting::MockModuleExtended
20
+ module CascadingConfiguration::Setting::ConfigurationMockExtended
21
21
  extend CascadingConfiguration::Setting
22
22
  # => singleton gets attr_configuration and configurations
23
23
  respond_to?( :attr_configuration ).should == true
@@ -28,31 +28,31 @@ describe CascadingConfiguration::Setting do
28
28
  instance_methods.include?( :some_configuration ).should == false
29
29
  # => including modules and classes get nothing
30
30
  module SubmoduleIncluding
31
- include CascadingConfiguration::Setting::MockModuleExtended
31
+ include CascadingConfiguration::Setting::ConfigurationMockExtended
32
32
  instance_methods.include?( :some_configuration ).should == false
33
33
  respond_to?( :some_configuration ).should == false
34
34
  end
35
35
  # => extending modules and classes get nothing
36
36
  module SubmoduleExtending
37
- extend CascadingConfiguration::Setting::MockModuleExtended
37
+ extend CascadingConfiguration::Setting::ConfigurationMockExtended
38
38
  instance_methods.include?( :some_configuration ).should == false
39
39
  respond_to?( :some_configuration ).should == false
40
40
  end
41
41
  # => instances of including and extending classes get nothing
42
42
  class ClassIncluding
43
- include CascadingConfiguration::Setting::MockModuleExtended
43
+ include CascadingConfiguration::Setting::ConfigurationMockExtended
44
44
  instance_methods.include?( :some_configuration ).should == false
45
45
  respond_to?( :some_configuration ).should == false
46
46
  end
47
47
  class ClassExtending
48
- extend CascadingConfiguration::Setting::MockModuleExtended
48
+ extend CascadingConfiguration::Setting::ConfigurationMockExtended
49
49
  instance_methods.include?( :some_configuration ).should == false
50
50
  respond_to?( :some_configuration ).should == false
51
51
  end
52
52
  end
53
53
 
54
54
  # * module included with setting
55
- module CascadingConfiguration::Setting::MockModuleIncluded
55
+ module CascadingConfiguration::Setting::ConfigurationMockIncluded
56
56
  include CascadingConfiguration::Setting
57
57
  # => singleton gets attr_configuration and configurations
58
58
  respond_to?( :attr_configuration ).should == true
@@ -63,7 +63,7 @@ describe CascadingConfiguration::Setting do
63
63
  instance_methods.include?( :some_configuration ).should == true
64
64
  # => including modules and classes get attr_configuration and configurations
65
65
  module SubmoduleIncluding
66
- include CascadingConfiguration::Setting::MockModuleIncluded
66
+ include CascadingConfiguration::Setting::ConfigurationMockIncluded
67
67
  instance_methods.include?( :some_configuration ).should == true
68
68
  respond_to?( :some_configuration ).should == true
69
69
  some_configuration.should == :our_setting_value
@@ -72,7 +72,7 @@ describe CascadingConfiguration::Setting do
72
72
  end
73
73
  # => extending modules and classes get attr_configuration and configurations
74
74
  module SubmoduleExtending
75
- extend CascadingConfiguration::Setting::MockModuleIncluded
75
+ extend CascadingConfiguration::Setting::ConfigurationMockIncluded
76
76
  # if we're extended then we want to use the eigenclass ancestor chain
77
77
  # - the first ancestor will be the extending module
78
78
  # - the rest of the ancestors will be the extending module's include chain
@@ -84,7 +84,7 @@ describe CascadingConfiguration::Setting do
84
84
  end
85
85
  # => instances of including classes get configurations
86
86
  class ClassIncluding
87
- include CascadingConfiguration::Setting::MockModuleIncluded
87
+ include CascadingConfiguration::Setting::ConfigurationMockIncluded
88
88
  instance_methods.include?( :some_configuration ).should == true
89
89
  respond_to?( :some_configuration ).should == true
90
90
  some_configuration.should == :our_setting_value
@@ -98,7 +98,7 @@ describe CascadingConfiguration::Setting do
98
98
  some_configuration.should == :our_setting_value
99
99
  # => instances of extending classes get nothing
100
100
  class ClassExtending
101
- extend CascadingConfiguration::Setting::MockModuleIncluded
101
+ extend CascadingConfiguration::Setting::ConfigurationMockIncluded
102
102
  respond_to?( :some_configuration ).should == true
103
103
  some_configuration.should == :our_setting_value
104
104
  self.some_configuration = :some_other_configuration
@@ -109,22 +109,248 @@ describe CascadingConfiguration::Setting do
109
109
  setting_class_including_instance.respond_to?( :some_configuration ).should == false
110
110
  end
111
111
 
112
- class CascadingConfiguration::Setting::MockClass
113
- include CascadingConfiguration::Setting::MockModuleIncluded::SubmoduleIncluding
112
+ class CascadingConfiguration::Setting::ConfigurationMockClass
113
+ include CascadingConfiguration::Setting::ConfigurationMockIncluded::SubmoduleIncluding
114
114
  some_configuration.should == :another_configuration
115
115
  self.some_configuration = :our_setting_value
116
116
  some_configuration.should == :our_setting_value
117
117
  end
118
- class CascadingConfiguration::Setting::MockClassSub1 < CascadingConfiguration::Setting::MockClass
118
+ class CascadingConfiguration::Setting::ConfigurationMockClassSub1 < CascadingConfiguration::Setting::ConfigurationMockClass
119
119
  some_configuration.should == :our_setting_value
120
120
  self.some_configuration = :our_other_setting_value
121
121
  some_configuration.should == :our_other_setting_value
122
122
  end
123
- class CascadingConfiguration::Setting::MockClassSub2 < CascadingConfiguration::Setting::MockClassSub1
123
+ class CascadingConfiguration::Setting::ConfigurationMockClassSub2 < CascadingConfiguration::Setting::ConfigurationMockClassSub1
124
124
  some_configuration.should == :our_other_setting_value
125
125
  self.some_configuration = :a_third_setting_value
126
126
  some_configuration.should == :a_third_setting_value
127
127
  end
128
128
  end
129
129
 
130
+ ###############################
131
+ # attr_module_configuration #
132
+ # attr_class_configuration #
133
+ ###############################
134
+
135
+ it 'can define a class configuration setting, which will not cascade to instances' do
136
+
137
+ # extending a module or class works like a finalizer for the cascading configuration
138
+ # if the configuration is re-opened at a later point (including or extending a lower ancestor)
139
+ # then the configuration will still cascade upward
140
+ # this permits ancestors in the heirarchy to skip out on configurations
141
+ # upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
142
+
143
+ # possibilities:
144
+ # * module extended with setting
145
+ module CascadingConfiguration::Setting::ClassConfigurationMockExtended
146
+ extend CascadingConfiguration::Setting
147
+ # => singleton gets attr_module_configuration and configurations
148
+ respond_to?( :attr_module_configuration ).should == true
149
+ method( :attr_module_configuration ).should == method( :attr_class_configuration )
150
+ attr_module_configuration :some_configuration
151
+ respond_to?( :attr_module_configuration ).should == true
152
+ self.some_configuration = :our_setting_value
153
+ some_configuration.should == :our_setting_value
154
+ instance_methods.include?( :some_configuration ).should == false
155
+ # => including modules and classes get nothing
156
+ module SubmoduleIncluding
157
+ include CascadingConfiguration::Setting::ClassConfigurationMockExtended
158
+ instance_methods.include?( :some_configuration ).should == false
159
+ respond_to?( :some_configuration ).should == false
160
+ end
161
+ # => extending modules and classes get nothing
162
+ module SubmoduleExtending
163
+ extend CascadingConfiguration::Setting::ClassConfigurationMockExtended
164
+ instance_methods.include?( :some_configuration ).should == false
165
+ respond_to?( :some_configuration ).should == false
166
+ end
167
+ # => instances of including and extending classes get nothing
168
+ class ClassIncluding
169
+ include CascadingConfiguration::Setting::ClassConfigurationMockExtended
170
+ instance_methods.include?( :some_configuration ).should == false
171
+ respond_to?( :some_configuration ).should == false
172
+ end
173
+ class ClassExtending
174
+ extend CascadingConfiguration::Setting::ClassConfigurationMockExtended
175
+ instance_methods.include?( :some_configuration ).should == false
176
+ respond_to?( :some_configuration ).should == false
177
+ end
178
+ end
179
+
180
+ # * module included with setting
181
+ module CascadingConfiguration::Setting::ClassConfigurationMockIncluded
182
+ include CascadingConfiguration::Setting
183
+ # => singleton gets attr_module_configuration and configurations
184
+ respond_to?( :attr_module_configuration ).should == true
185
+ attr_module_configuration :some_configuration
186
+ respond_to?( :some_configuration ).should == true
187
+ self.some_configuration = :our_setting_value
188
+ some_configuration.should == :our_setting_value
189
+ instance_methods.include?( :some_configuration ).should == false
190
+ # => including modules and classes get attr_module_configuration and configurations
191
+ module SubmoduleIncluding
192
+ include CascadingConfiguration::Setting::ClassConfigurationMockIncluded
193
+ instance_methods.include?( :some_configuration ).should == false
194
+ respond_to?( :some_configuration ).should == true
195
+ some_configuration.should == :our_setting_value
196
+ self.some_configuration = :another_configuration
197
+ some_configuration.should == :another_configuration
198
+ end
199
+ # => extending modules and classes get attr_module_configuration and configurations
200
+ module SubmoduleExtending
201
+ extend CascadingConfiguration::Setting::ClassConfigurationMockIncluded
202
+ # if we're extended then we want to use the eigenclass ancestor chain
203
+ # - the first ancestor will be the extending module
204
+ # - the rest of the ancestors will be the extending module's include chain
205
+ respond_to?( :some_configuration ).should == true
206
+ some_configuration.should == :our_setting_value
207
+ self.some_configuration = :some_other_configuration
208
+ some_configuration.should == :some_other_configuration
209
+ instance_methods.include?( :some_configuration ).should == false
210
+ end
211
+ # => instances of including classes get configurations
212
+ class ClassIncluding
213
+ include CascadingConfiguration::Setting::ClassConfigurationMockIncluded
214
+ instance_methods.include?( :some_configuration ).should == false
215
+ respond_to?( :some_configuration ).should == true
216
+ some_configuration.should == :our_setting_value
217
+ self.some_configuration = :another_configuration
218
+ some_configuration.should == :another_configuration
219
+ end
220
+ setting_class_including_instance = ClassIncluding.new
221
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
222
+ # => instances of extending classes get nothing
223
+ class ClassExtending
224
+ extend CascadingConfiguration::Setting::ClassConfigurationMockIncluded
225
+ respond_to?( :some_configuration ).should == true
226
+ some_configuration.should == :our_setting_value
227
+ self.some_configuration = :some_other_configuration
228
+ some_configuration.should == :some_other_configuration
229
+ instance_methods.include?( :some_configuration ).should == false
230
+ end
231
+ setting_class_including_instance = ClassExtending.new
232
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
233
+ end
234
+
235
+ class CascadingConfiguration::Setting::ClassConfigurationMockClass
236
+ include CascadingConfiguration::Setting::ClassConfigurationMockIncluded::SubmoduleIncluding
237
+ some_configuration.should == :another_configuration
238
+ self.some_configuration = :our_setting_value
239
+ some_configuration.should == :our_setting_value
240
+ end
241
+ class CascadingConfiguration::Setting::ClassConfigurationMockClassSub1 < CascadingConfiguration::Setting::ClassConfigurationMockClass
242
+ some_configuration.should == :our_setting_value
243
+ self.some_configuration = :our_other_setting_value
244
+ some_configuration.should == :our_other_setting_value
245
+ end
246
+ class CascadingConfiguration::Setting::ClassConfigurationMockClassSub2 < CascadingConfiguration::Setting::ClassConfigurationMockClassSub1
247
+ some_configuration.should == :our_other_setting_value
248
+ self.some_configuration = :a_third_setting_value
249
+ some_configuration.should == :a_third_setting_value
250
+ end
251
+ end
252
+
253
+ ##############################
254
+ # attr_local_configuration #
255
+ ##############################
256
+
257
+ it 'can define a local configuration setting, which will not cascade' do
258
+
259
+ # extending a module or class works like a finalizer for the cascading configuration
260
+ # if the configuration is re-opened at a later point (including or extending a lower ancestor)
261
+ # then the configuration will still cascade upward
262
+ # this permits ancestors in the heirarchy to skip out on configurations
263
+ # upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
264
+
265
+ # possibilities:
266
+ # * module extended with setting
267
+ module CascadingConfiguration::Setting::LocalConfigurationMockExtended
268
+ extend CascadingConfiguration::Setting
269
+ # => singleton gets attr_configuration and configurations
270
+ respond_to?( :attr_local_configuration ).should == true
271
+ attr_local_configuration :some_configuration
272
+ respond_to?( :some_configuration ).should == true
273
+ self.some_configuration = :our_setting_value
274
+ some_configuration.should == :our_setting_value
275
+ instance_methods.include?( :some_configuration ).should == false
276
+ # => including modules and classes get nothing
277
+ module SubmoduleIncluding
278
+ include CascadingConfiguration::Setting::LocalConfigurationMockExtended
279
+ instance_methods.include?( :some_configuration ).should == false
280
+ respond_to?( :some_configuration ).should == false
281
+ end
282
+ # => extending modules and classes get nothing
283
+ module SubmoduleExtending
284
+ extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
285
+ instance_methods.include?( :some_configuration ).should == false
286
+ respond_to?( :some_configuration ).should == false
287
+ end
288
+ # => instances of including and extending classes get nothing
289
+ class ClassIncluding
290
+ include CascadingConfiguration::Setting::LocalConfigurationMockExtended
291
+ instance_methods.include?( :some_configuration ).should == false
292
+ respond_to?( :some_configuration ).should == false
293
+ end
294
+ class ClassExtending
295
+ extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
296
+ instance_methods.include?( :some_configuration ).should == false
297
+ respond_to?( :some_configuration ).should == false
298
+ end
299
+ end
300
+
301
+ # * module included with setting
302
+ module CascadingConfiguration::Setting::LocalConfigurationMockIncluded
303
+ include CascadingConfiguration::Setting
304
+ # => singleton gets attr_configuration and configurations
305
+ respond_to?( :attr_local_configuration ).should == true
306
+ attr_local_configuration :some_configuration
307
+ respond_to?( :some_configuration ).should == true
308
+ self.some_configuration = :our_setting_value
309
+ some_configuration.should == :our_setting_value
310
+ instance_methods.include?( :some_configuration ).should == false
311
+ # => including modules and classes get attr_configuration and configurations
312
+ module SubmoduleIncluding
313
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
314
+ instance_methods.include?( :some_configuration ).should == false
315
+ respond_to?( :some_configuration ).should == false
316
+ end
317
+ # => extending modules and classes get attr_configuration and configurations
318
+ module SubmoduleExtending
319
+ extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded
320
+ # if we're extended then we want to use the eigenclass ancestor chain
321
+ # - the first ancestor will be the extending module
322
+ # - the rest of the ancestors will be the extending module's include chain
323
+ respond_to?( :some_configuration ).should == false
324
+ instance_methods.include?( :some_configuration ).should == false
325
+ end
326
+ # => instances of including classes get configurations
327
+ class ClassIncluding
328
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
329
+ instance_methods.include?( :some_configuration ).should == false
330
+ respond_to?( :some_configuration ).should == false
331
+ end
332
+ setting_class_including_instance = ClassIncluding.new
333
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
334
+ # => instances of extending classes get nothing
335
+ class ClassExtending
336
+ extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded
337
+ respond_to?( :some_configuration ).should == false
338
+ instance_methods.include?( :some_configuration ).should == false
339
+ end
340
+ setting_class_including_instance = ClassExtending.new
341
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
342
+ end
343
+
344
+ class CascadingConfiguration::Setting::LocalConfigurationMockClass
345
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleIncluding
346
+ respond_to?( :some_configuration ).should == false
347
+ end
348
+ class CascadingConfiguration::Setting::LocalConfigurationMockClassSub1 < CascadingConfiguration::Setting::LocalConfigurationMockClass
349
+ respond_to?( :some_configuration ).should == false
350
+ end
351
+ class CascadingConfiguration::Setting::LocalConfigurationMockClassSub2 < CascadingConfiguration::Setting::LocalConfigurationMockClassSub1
352
+ respond_to?( :some_configuration ).should == false
353
+ end
354
+ end
355
+
130
356
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- - 6
9
- version: 1.1.6
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Asher
@@ -39,12 +39,12 @@ extensions: []
39
39
  extra_rdoc_files: []
40
40
 
41
41
  files:
42
- - lib/cascading-configuration-setting/CascadingConfiguration/Setting/ConfigurationAccessors.rb
42
+ - lib/cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb
43
43
  - lib/cascading-configuration-setting/CascadingConfiguration/Setting/Interface.rb
44
44
  - lib/cascading-configuration-setting/CascadingConfiguration/Setting/ModuleInclusionExtensionSupport.rb
45
45
  - lib/cascading-configuration-setting/CascadingConfiguration/Setting.rb
46
46
  - lib/cascading-configuration-setting.rb
47
- - spec/CascadingConfiguration/Setting/ConfigurationAccessors_spec.rb
47
+ - spec/CascadingConfiguration/Setting/AccessorDefinitionMethods_spec.rb
48
48
  - spec/CascadingConfiguration/Setting_spec.rb
49
49
  - README.md
50
50
  - README.rdoc