cascading-configuration-setting 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,6 +70,39 @@ module CascadingConfiguration::Setting::AccessorDefinitionMethods
70
70
  #######################################
71
71
 
72
72
  def define_local_configuration_setter( configuration_name )
73
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
74
+ [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
75
+ module_support.module_eval do
76
+ define_method( configuration_setter_name ) do |value|
77
+ # configuration setter returns setting variable (variable from self), which is now the ID of value
78
+ return accessor_module_support.set_configuration_variable( self, configuration_name, value )
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ #######################################
85
+ # define_local_configuration_getter #
86
+ #######################################
87
+
88
+ def define_local_configuration_getter( configuration_name )
89
+ configuration_getter_name = configuration_name
90
+ [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
91
+ module_support.module_eval do
92
+ define_method( configuration_getter_name ) do
93
+ # configuration getter returns current setting value (taken from first superclass with setting)
94
+ # that means first variable that has been set
95
+ return accessor_module_support.get_configuration_variable( self, configuration_name )
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ ##########################################
102
+ # define_existant_configuration_setter #
103
+ ##########################################
104
+
105
+ def define_existant_configuration_setter( configuration_name )
73
106
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
74
107
  accessor_local_instance_support.module_eval do
75
108
  define_method( configuration_setter_name ) do |value|
@@ -79,11 +112,11 @@ module CascadingConfiguration::Setting::AccessorDefinitionMethods
79
112
  end
80
113
  end
81
114
 
82
- #######################################
83
- # define_local_configuration_getter #
84
- #######################################
115
+ ##########################################
116
+ # define_existant_configuration_getter #
117
+ ##########################################
85
118
 
86
- def define_local_configuration_getter( configuration_name )
119
+ def define_existant_configuration_getter( configuration_name )
87
120
  configuration_getter_name = configuration_name
88
121
  accessor_local_instance_support.module_eval do
89
122
  define_method( configuration_getter_name ) do
@@ -93,5 +126,5 @@ module CascadingConfiguration::Setting::AccessorDefinitionMethods
93
126
  end
94
127
  end
95
128
  end
96
-
129
+
97
130
  end
@@ -38,8 +38,10 @@ module CascadingConfiguration::Setting::Interface
38
38
  # attr_local_configuration #
39
39
  ##############################
40
40
 
41
- # defines configuration in present class or module context
42
- # configuration does not cascade
41
+ # local to class or module that declares it
42
+ # also local to instances of class or module
43
+ # * any instances of class
44
+ # * first class to include module (inherited)
43
45
  def attr_local_configuration( *property_names )
44
46
  CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
45
47
  property_names.each do |this_property_name|
@@ -48,6 +50,23 @@ module CascadingConfiguration::Setting::Interface
48
50
  # define configuration getter
49
51
  define_local_configuration_getter( this_property_name )
50
52
  end
53
+ CascadingConfiguration::Variable.cascade_local_instance( self )
54
+ end
55
+
56
+ #################################
57
+ # attr_existant_configuration #
58
+ #################################
59
+
60
+ # local to class or module or instance that declares it
61
+ # * only in the instance that declares it
62
+ def attr_existant_configuration( *property_names )
63
+ CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
64
+ property_names.each do |this_property_name|
65
+ # define configuration setter
66
+ define_existant_configuration_setter( this_property_name )
67
+ # define configuration getter
68
+ define_existant_configuration_getter( this_property_name )
69
+ end
51
70
  end
52
71
 
53
72
  end
@@ -284,7 +284,7 @@ describe CascadingConfiguration::Setting do
284
284
  # attr_local_configuration #
285
285
  ##############################
286
286
 
287
- it 'can define a local configuration setting, which will not cascade' do
287
+ it 'can define a local configuration setting, which cascades to the first class and instances' do
288
288
 
289
289
  # extending a module or class works like a finalizer for the cascading configuration
290
290
  # if the configuration is re-opened at a later point (including or extending a lower ancestor)
@@ -342,13 +342,19 @@ describe CascadingConfiguration::Setting do
342
342
  respond_to?( :some_configuration ).should == true
343
343
  self.some_configuration = :our_setting_value
344
344
  some_configuration.should == :our_setting_value
345
- instance_methods.include?( :some_configuration ).should == false
345
+ instance_methods.include?( :some_configuration ).should == true
346
346
  instance_variables.empty?.should == true
347
347
  # => including modules and classes get attr_configuration and configurations
348
348
  module SubmoduleIncluding
349
349
  include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
350
- instance_methods.include?( :some_configuration ).should == false
351
- respond_to?( :some_configuration ).should == false
350
+ instance_methods.include?( :some_configuration ).should == true
351
+ respond_to?( :some_configuration ).should == true
352
+ instance_variables.empty?.should == true
353
+ end
354
+ module SubSubmoduleIncluding
355
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleIncluding
356
+ instance_methods.include?( :some_configuration ).should == true
357
+ respond_to?( :some_configuration ).should == true
352
358
  instance_variables.empty?.should == true
353
359
  end
354
360
  # => extending modules and classes get attr_configuration and configurations
@@ -357,6 +363,15 @@ describe CascadingConfiguration::Setting do
357
363
  # if we're extended then we want to use the eigenclass ancestor chain
358
364
  # - the first ancestor will be the extending module
359
365
  # - the rest of the ancestors will be the extending module's include chain
366
+ respond_to?( :some_configuration ).should == true
367
+ instance_methods.include?( :some_configuration ).should == false
368
+ instance_variables.empty?.should == true
369
+ end
370
+ module SubSubmoduleExtending
371
+ extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleExtending
372
+ # if we're extended then we want to use the eigenclass ancestor chain
373
+ # - the first ancestor will be the extending module
374
+ # - the rest of the ancestors will be the extending module's include chain
360
375
  respond_to?( :some_configuration ).should == false
361
376
  instance_methods.include?( :some_configuration ).should == false
362
377
  instance_variables.empty?.should == true
@@ -364,23 +379,51 @@ describe CascadingConfiguration::Setting do
364
379
  # => instances of including classes get configurations
365
380
  class ClassIncluding
366
381
  include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
367
- instance_methods.include?( :some_configuration ).should == false
368
- respond_to?( :some_configuration ).should == false
382
+ instance_methods.include?( :some_configuration ).should == true
383
+ respond_to?( :some_configuration ).should == true
369
384
  instance_variables.empty?.should == true
370
385
  end
371
386
  setting_class_including_instance = ClassIncluding.new
372
- setting_class_including_instance.respond_to?( :some_configuration ).should == false
387
+ setting_class_including_instance.respond_to?( :some_configuration ).should == true
373
388
  setting_class_including_instance.instance_variables.empty?.should == true
374
389
  # => instances of extending classes get nothing
375
390
  class ClassExtending
376
391
  extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded
377
- respond_to?( :some_configuration ).should == false
392
+ respond_to?( :some_configuration ).should == true
378
393
  instance_methods.include?( :some_configuration ).should == false
379
394
  instance_variables.empty?.should == true
380
395
  end
381
396
  setting_class_including_instance = ClassExtending.new
382
397
  setting_class_including_instance.respond_to?( :some_configuration ).should == false
383
398
  setting_class_including_instance.instance_variables.empty?.should == true
399
+ class ClassSubSubmoduleIncludingIncluding
400
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
401
+ respond_to?( :some_configuration ).should == false
402
+ instance_methods.include?( :some_configuration ).should == true
403
+ instance_variables.empty?.should == true
404
+ end
405
+ setting_class_including_instance = ClassSubSubmoduleIncludingIncluding.new
406
+ setting_class_including_instance.respond_to?( :some_configuration ).should == true
407
+ setting_class_including_instance.instance_variables.empty?.should == true
408
+ class ClassSubSubmoduleIncludingExtending
409
+ extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
410
+ respond_to?( :some_configuration ).should == true
411
+ instance_methods.include?( :some_configuration ).should == false
412
+ instance_variables.empty?.should == true
413
+ end
414
+ setting_class_including_instance = ClassSubSubmoduleIncludingExtending.new
415
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
416
+ setting_class_including_instance.instance_variables.empty?.should == true
417
+ class ClassSubSubmoduleIncludingIncludingAndExtending
418
+ include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
419
+ extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
420
+ respond_to?( :some_configuration ).should == true
421
+ instance_methods.include?( :some_configuration ).should == true
422
+ instance_variables.empty?.should == true
423
+ end
424
+ setting_class_including_instance = ClassSubSubmoduleIncludingIncludingAndExtending.new
425
+ setting_class_including_instance.respond_to?( :some_configuration ).should == true
426
+ setting_class_including_instance.instance_variables.empty?.should == true
384
427
  end
385
428
 
386
429
  class CascadingConfiguration::Setting::LocalConfigurationMockClass
@@ -397,5 +440,123 @@ describe CascadingConfiguration::Setting do
397
440
  instance_variables.empty?.should == true
398
441
  end
399
442
  end
443
+
444
+ #################################
445
+ # attr_existant_configuration #
446
+ #################################
400
447
 
448
+ it 'can define a configuration setting for the present instance, which will not cascade' do
449
+
450
+ # extending a module or class works like a finalizer for the cascading configuration
451
+ # if the configuration is re-opened at a later point (including or extending a lower ancestor)
452
+ # then the configuration will still cascade upward
453
+ # this permits ancestors in the heirarchy to skip out on configurations
454
+ # upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
455
+
456
+ # possibilities:
457
+ # * module extended with setting
458
+ module CascadingConfiguration::Setting::LocalConfigurationMockExtended
459
+ extend CascadingConfiguration::Setting
460
+ # => singleton gets attr_configuration and configurations
461
+ respond_to?( :attr_existant_configuration ).should == true
462
+ attr_existant_configuration :some_configuration
463
+ respond_to?( :some_configuration ).should == true
464
+ self.some_configuration = :our_setting_value
465
+ some_configuration.should == :our_setting_value
466
+ instance_methods.include?( :some_configuration ).should == false
467
+ instance_variables.empty?.should == true
468
+ # => including modules and classes get nothing
469
+ module SubmoduleIncluding
470
+ include CascadingConfiguration::Setting::LocalConfigurationMockExtended
471
+ instance_methods.include?( :some_configuration ).should == false
472
+ respond_to?( :some_configuration ).should == false
473
+ instance_variables.empty?.should == true
474
+ end
475
+ # => extending modules and classes get nothing
476
+ module SubmoduleExtending
477
+ extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
478
+ instance_methods.include?( :some_configuration ).should == false
479
+ respond_to?( :some_configuration ).should == false
480
+ instance_variables.empty?.should == true
481
+ end
482
+ # => instances of including and extending classes get nothing
483
+ class ClassIncluding
484
+ include CascadingConfiguration::Setting::LocalConfigurationMockExtended
485
+ instance_methods.include?( :some_configuration ).should == false
486
+ respond_to?( :some_configuration ).should == false
487
+ instance_variables.empty?.should == true
488
+ end
489
+ class ClassExtending
490
+ extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
491
+ instance_methods.include?( :some_configuration ).should == false
492
+ respond_to?( :some_configuration ).should == false
493
+ instance_variables.empty?.should == true
494
+ end
495
+ end
496
+
497
+ # * module included with setting
498
+ module CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
499
+ include CascadingConfiguration::Setting
500
+ # => singleton gets attr_configuration and configurations
501
+ respond_to?( :attr_existant_configuration ).should == true
502
+ attr_existant_configuration :some_configuration
503
+ respond_to?( :some_configuration ).should == true
504
+ self.some_configuration = :our_setting_value
505
+ some_configuration.should == :our_setting_value
506
+ instance_methods.include?( :some_configuration ).should == false
507
+ instance_variables.empty?.should == true
508
+ # => including modules and classes get attr_configuration and configurations
509
+ module SubmoduleIncluding
510
+ include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
511
+ instance_methods.include?( :some_configuration ).should == false
512
+ respond_to?( :some_configuration ).should == false
513
+ instance_variables.empty?.should == true
514
+ end
515
+ # => extending modules and classes get attr_configuration and configurations
516
+ module SubmoduleExtending
517
+ extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
518
+ # if we're extended then we want to use the eigenclass ancestor chain
519
+ # - the first ancestor will be the extending module
520
+ # - the rest of the ancestors will be the extending module's include chain
521
+ respond_to?( :some_configuration ).should == false
522
+ instance_methods.include?( :some_configuration ).should == false
523
+ instance_variables.empty?.should == true
524
+ end
525
+ # => instances of including classes get configurations
526
+ class ClassIncluding
527
+ include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
528
+ instance_methods.include?( :some_configuration ).should == false
529
+ respond_to?( :some_configuration ).should == false
530
+ instance_variables.empty?.should == true
531
+ end
532
+ setting_class_including_instance = ClassIncluding.new
533
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
534
+ setting_class_including_instance.instance_variables.empty?.should == true
535
+ # => instances of extending classes get nothing
536
+ class ClassExtending
537
+ extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
538
+ respond_to?( :some_configuration ).should == false
539
+ instance_methods.include?( :some_configuration ).should == false
540
+ instance_variables.empty?.should == true
541
+ end
542
+ setting_class_including_instance = ClassExtending.new
543
+ setting_class_including_instance.respond_to?( :some_configuration ).should == false
544
+ setting_class_including_instance.instance_variables.empty?.should == true
545
+ end
546
+
547
+ class CascadingConfiguration::Setting::InstanceConfigurationMockClass
548
+ include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded::SubmoduleIncluding
549
+ respond_to?( :some_configuration ).should == false
550
+ instance_variables.empty?.should == true
551
+ end
552
+ class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1 < CascadingConfiguration::Setting::InstanceConfigurationMockClass
553
+ respond_to?( :some_configuration ).should == false
554
+ instance_variables.empty?.should == true
555
+ end
556
+ class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub2 < CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1
557
+ respond_to?( :some_configuration ).should == false
558
+ instance_variables.empty?.should == true
559
+ end
560
+ end
561
+
401
562
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 1
9
- version: 1.3.1
8
+ - 2
9
+ version: 1.3.2
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-08-01 00:00:00 -04:00
17
+ date: 2011-08-03 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency