cascading-configuration-setting 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cascading-configuration-setting.rb +3 -0
- data/lib/cascading-configuration-setting/CascadingConfiguration/Setting.rb +3 -1
- data/lib/cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb +30 -1
- data/lib/cascading-configuration-setting/CascadingConfiguration/Setting/Interface.rb +6 -6
- data/lib/cascading-configuration-setting/CascadingConfiguration/Setting/Interface/Instance.rb +23 -0
- data/spec/CascadingConfiguration/Setting_spec.rb +126 -23
- metadata +3 -2
@@ -10,6 +10,8 @@ module CascadingConfiguration
|
|
10
10
|
module AccessorDefinitionMethods
|
11
11
|
end
|
12
12
|
module Interface
|
13
|
+
module Instance
|
14
|
+
end
|
13
15
|
end
|
14
16
|
module ObjectInstance
|
15
17
|
end
|
@@ -19,3 +21,4 @@ end
|
|
19
21
|
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting.rb'
|
20
22
|
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb'
|
21
23
|
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/Interface.rb'
|
24
|
+
require_relative 'cascading-configuration-setting/CascadingConfiguration/Setting/Interface/Instance.rb'
|
@@ -13,7 +13,9 @@ module CascadingConfiguration::Setting
|
|
13
13
|
class_or_module.extend_also_extends( CascadingConfiguration::Variable::EigenclassConfigurationChain )
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
include_cascades_extends( CascadingConfiguration::Setting::Interface::Instance )
|
17
|
+
|
18
|
+
include_cascades_extends( CascadingConfiguration::Setting )
|
17
19
|
|
18
20
|
prepend_module_include do |class_or_module|
|
19
21
|
class_or_module.include_or_extend_cascades_prepending_extends do
|
data/lib/cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb
CHANGED
@@ -104,7 +104,7 @@ module CascadingConfiguration::Setting::AccessorDefinitionMethods
|
|
104
104
|
|
105
105
|
def define_instance_configuration_setter( configuration_name )
|
106
106
|
configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
|
107
|
-
|
107
|
+
accessor_instance_support.module_eval do
|
108
108
|
define_method( configuration_setter_name ) do |value|
|
109
109
|
# configuration setter returns setting variable (variable from self), which is now the ID of value
|
110
110
|
return accessor_module_support.set_configuration_variable( self, configuration_name, value )
|
@@ -117,6 +117,35 @@ module CascadingConfiguration::Setting::AccessorDefinitionMethods
|
|
117
117
|
##########################################
|
118
118
|
|
119
119
|
def define_instance_configuration_getter( configuration_name )
|
120
|
+
configuration_getter_name = configuration_name
|
121
|
+
accessor_instance_support.module_eval do
|
122
|
+
define_method( configuration_getter_name ) do
|
123
|
+
# configuration getter returns current setting value (taken from first superclass with setting)
|
124
|
+
# that means first variable that has been set
|
125
|
+
return accessor_module_support.get_configuration_variable( self, configuration_name )
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
########################################
|
131
|
+
# define_object_configuration_setter #
|
132
|
+
########################################
|
133
|
+
|
134
|
+
def define_object_configuration_setter( configuration_name )
|
135
|
+
configuration_setter_name = ( configuration_name.to_s + '=' ).to_s
|
136
|
+
accessor_local_instance_support.module_eval do
|
137
|
+
define_method( configuration_setter_name ) do |value|
|
138
|
+
# configuration setter returns setting variable (variable from self), which is now the ID of value
|
139
|
+
return accessor_module_support.set_configuration_variable( self, configuration_name, value )
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
########################################
|
145
|
+
# define_object_configuration_getter #
|
146
|
+
########################################
|
147
|
+
|
148
|
+
def define_object_configuration_getter( configuration_name )
|
120
149
|
configuration_getter_name = configuration_name
|
121
150
|
accessor_local_instance_support.module_eval do
|
122
151
|
define_method( configuration_getter_name ) do
|
@@ -53,19 +53,19 @@ module CascadingConfiguration::Setting::Interface
|
|
53
53
|
CascadingConfiguration::Variable.cascade_local_instance( self )
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
#
|
58
|
-
|
56
|
+
###############################
|
57
|
+
# attr_object_configuration #
|
58
|
+
###############################
|
59
59
|
|
60
60
|
# local to class or module or instance that declares it
|
61
61
|
# * only in the instance that declares it
|
62
|
-
def
|
62
|
+
def attr_object_configuration( *property_names )
|
63
63
|
CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
|
64
64
|
property_names.each do |this_property_name|
|
65
65
|
# define configuration setter
|
66
|
-
|
66
|
+
define_object_configuration_setter( this_property_name )
|
67
67
|
# define configuration getter
|
68
|
-
|
68
|
+
define_object_configuration_getter( this_property_name )
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Setting::Interface::Instance
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
#################################
|
7
|
+
# attr_instance_configuration #
|
8
|
+
#################################
|
9
|
+
|
10
|
+
# local to class or module or instance that declares it
|
11
|
+
# * in instances of the class or module that declares it
|
12
|
+
# * in instance if declared on non-class/non-module object instance
|
13
|
+
def attr_instance_configuration( *property_names )
|
14
|
+
property_names.each do |this_property_name|
|
15
|
+
# define configuration setter
|
16
|
+
define_instance_configuration_setter( this_property_name )
|
17
|
+
# define configuration getter
|
18
|
+
define_instance_configuration_getter( this_property_name )
|
19
|
+
end
|
20
|
+
return self
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -449,19 +449,122 @@ describe CascadingConfiguration::Setting do
|
|
449
449
|
|
450
450
|
it 'can define a configuration setting for the present instance, which will not cascade' do
|
451
451
|
|
452
|
-
# extending a module or class works like a finalizer for the cascading configuration
|
453
|
-
# if the configuration is re-opened at a later point (including or extending a lower ancestor)
|
454
|
-
# then the configuration will still cascade upward
|
455
|
-
# this permits ancestors in the heirarchy to skip out on configurations
|
456
|
-
# upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
|
457
|
-
|
458
452
|
# possibilities:
|
459
453
|
# * module extended with setting
|
460
|
-
module CascadingConfiguration::Setting::
|
454
|
+
module CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
461
455
|
extend CascadingConfiguration::Setting
|
462
456
|
# => singleton gets attr_configuration and configurations
|
457
|
+
respond_to?( :attr_instance_configuration ).should == false
|
458
|
+
instance_methods.include?( :some_configuration ).should == false
|
459
|
+
instance_variables.empty?.should == true
|
460
|
+
# => including modules and classes get nothing
|
461
|
+
module SubmoduleIncluding
|
462
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
463
|
+
instance_methods.include?( :some_configuration ).should == false
|
464
|
+
respond_to?( :some_configuration ).should == false
|
465
|
+
instance_variables.empty?.should == true
|
466
|
+
end
|
467
|
+
# => extending modules and classes get nothing
|
468
|
+
module SubmoduleExtending
|
469
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
470
|
+
instance_methods.include?( :some_configuration ).should == false
|
471
|
+
respond_to?( :some_configuration ).should == false
|
472
|
+
instance_variables.empty?.should == true
|
473
|
+
end
|
474
|
+
# => instances of including and extending classes get nothing
|
475
|
+
class ClassIncluding
|
476
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
477
|
+
instance_methods.include?( :some_configuration ).should == false
|
478
|
+
respond_to?( :some_configuration ).should == false
|
479
|
+
instance_variables.empty?.should == true
|
480
|
+
end
|
481
|
+
class ClassExtending
|
482
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
483
|
+
instance_methods.include?( :some_configuration ).should == false
|
484
|
+
respond_to?( :some_configuration ).should == false
|
485
|
+
instance_variables.empty?.should == true
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
# * module included with setting
|
490
|
+
module CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
491
|
+
include CascadingConfiguration::Setting
|
492
|
+
# => singleton gets attr_configuration and configurations
|
463
493
|
respond_to?( :attr_instance_configuration ).should == true
|
464
494
|
attr_instance_configuration :some_configuration
|
495
|
+
respond_to?( :some_configuration ).should == false
|
496
|
+
instance_methods.include?( :some_configuration ).should == true
|
497
|
+
instance_variables.empty?.should == true
|
498
|
+
# => including modules and classes get attr_configuration and configurations
|
499
|
+
module SubmoduleIncluding
|
500
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
501
|
+
instance_methods.include?( :some_configuration ).should == true
|
502
|
+
respond_to?( :some_configuration ).should == false
|
503
|
+
instance_variables.empty?.should == true
|
504
|
+
end
|
505
|
+
# => extending modules and classes get attr_configuration and configurations
|
506
|
+
module SubmoduleExtending
|
507
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
508
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
509
|
+
# - the first ancestor will be the extending module
|
510
|
+
# - the rest of the ancestors will be the extending module's include chain
|
511
|
+
respond_to?( :some_configuration ).should == true
|
512
|
+
instance_methods.include?( :some_configuration ).should == false
|
513
|
+
instance_variables.empty?.should == true
|
514
|
+
end
|
515
|
+
# => instances of including classes get configurations
|
516
|
+
class ClassIncluding
|
517
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
518
|
+
instance_methods.include?( :some_configuration ).should == true
|
519
|
+
respond_to?( :some_configuration ).should == false
|
520
|
+
instance_variables.empty?.should == true
|
521
|
+
end
|
522
|
+
setting_class_including_instance = ClassIncluding.new
|
523
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
524
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
525
|
+
# => instances of extending classes get nothing
|
526
|
+
class ClassExtending
|
527
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
528
|
+
respond_to?( :some_configuration ).should == true
|
529
|
+
instance_methods.include?( :some_configuration ).should == false
|
530
|
+
instance_variables.empty?.should == true
|
531
|
+
end
|
532
|
+
setting_class_including_instance = ClassExtending.new
|
533
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
534
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
535
|
+
end
|
536
|
+
|
537
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClass
|
538
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded::SubmoduleIncluding
|
539
|
+
respond_to?( :some_configuration ).should == false
|
540
|
+
instance_methods.include?( :some_configuration ).should == true
|
541
|
+
instance_variables.empty?.should == true
|
542
|
+
end
|
543
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1 < CascadingConfiguration::Setting::InstanceConfigurationMockClass
|
544
|
+
respond_to?( :some_configuration ).should == false
|
545
|
+
instance_methods.include?( :some_configuration ).should == true
|
546
|
+
instance_variables.empty?.should == true
|
547
|
+
end
|
548
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub2 < CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1
|
549
|
+
respond_to?( :some_configuration ).should == false
|
550
|
+
instance_methods.include?( :some_configuration ).should == true
|
551
|
+
instance_variables.empty?.should == true
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
###############################
|
556
|
+
# attr_object_configuration #
|
557
|
+
###############################
|
558
|
+
|
559
|
+
it 'can define a configuration setting for the present instance, which will not cascade' do
|
560
|
+
|
561
|
+
# possibilities:
|
562
|
+
# * module extended with setting
|
563
|
+
module CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
564
|
+
extend CascadingConfiguration::Setting
|
565
|
+
# => singleton gets attr_configuration and configurations
|
566
|
+
respond_to?( :attr_object_configuration ).should == true
|
567
|
+
attr_object_configuration :some_configuration
|
465
568
|
respond_to?( :some_configuration ).should == true
|
466
569
|
self.some_configuration = :our_setting_value
|
467
570
|
some_configuration.should == :our_setting_value
|
@@ -469,27 +572,27 @@ describe CascadingConfiguration::Setting do
|
|
469
572
|
instance_variables.empty?.should == true
|
470
573
|
# => including modules and classes get nothing
|
471
574
|
module SubmoduleIncluding
|
472
|
-
include CascadingConfiguration::Setting::
|
575
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
473
576
|
instance_methods.include?( :some_configuration ).should == false
|
474
577
|
respond_to?( :some_configuration ).should == false
|
475
578
|
instance_variables.empty?.should == true
|
476
579
|
end
|
477
580
|
# => extending modules and classes get nothing
|
478
581
|
module SubmoduleExtending
|
479
|
-
extend CascadingConfiguration::Setting::
|
582
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
480
583
|
instance_methods.include?( :some_configuration ).should == false
|
481
584
|
respond_to?( :some_configuration ).should == false
|
482
585
|
instance_variables.empty?.should == true
|
483
586
|
end
|
484
587
|
# => instances of including and extending classes get nothing
|
485
588
|
class ClassIncluding
|
486
|
-
include CascadingConfiguration::Setting::
|
589
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
487
590
|
instance_methods.include?( :some_configuration ).should == false
|
488
591
|
respond_to?( :some_configuration ).should == false
|
489
592
|
instance_variables.empty?.should == true
|
490
593
|
end
|
491
594
|
class ClassExtending
|
492
|
-
extend CascadingConfiguration::Setting::
|
595
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
493
596
|
instance_methods.include?( :some_configuration ).should == false
|
494
597
|
respond_to?( :some_configuration ).should == false
|
495
598
|
instance_variables.empty?.should == true
|
@@ -497,11 +600,11 @@ describe CascadingConfiguration::Setting do
|
|
497
600
|
end
|
498
601
|
|
499
602
|
# * module included with setting
|
500
|
-
module CascadingConfiguration::Setting::
|
603
|
+
module CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
501
604
|
include CascadingConfiguration::Setting
|
502
605
|
# => singleton gets attr_configuration and configurations
|
503
|
-
respond_to?( :
|
504
|
-
|
606
|
+
respond_to?( :attr_object_configuration ).should == true
|
607
|
+
attr_object_configuration :some_configuration
|
505
608
|
respond_to?( :some_configuration ).should == true
|
506
609
|
self.some_configuration = :our_setting_value
|
507
610
|
some_configuration.should == :our_setting_value
|
@@ -509,14 +612,14 @@ describe CascadingConfiguration::Setting do
|
|
509
612
|
instance_variables.empty?.should == true
|
510
613
|
# => including modules and classes get attr_configuration and configurations
|
511
614
|
module SubmoduleIncluding
|
512
|
-
include CascadingConfiguration::Setting::
|
615
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
513
616
|
instance_methods.include?( :some_configuration ).should == false
|
514
617
|
respond_to?( :some_configuration ).should == false
|
515
618
|
instance_variables.empty?.should == true
|
516
619
|
end
|
517
620
|
# => extending modules and classes get attr_configuration and configurations
|
518
621
|
module SubmoduleExtending
|
519
|
-
extend CascadingConfiguration::Setting::
|
622
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
520
623
|
# if we're extended then we want to use the eigenclass ancestor chain
|
521
624
|
# - the first ancestor will be the extending module
|
522
625
|
# - the rest of the ancestors will be the extending module's include chain
|
@@ -526,7 +629,7 @@ describe CascadingConfiguration::Setting do
|
|
526
629
|
end
|
527
630
|
# => instances of including classes get configurations
|
528
631
|
class ClassIncluding
|
529
|
-
include CascadingConfiguration::Setting::
|
632
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
530
633
|
instance_methods.include?( :some_configuration ).should == false
|
531
634
|
respond_to?( :some_configuration ).should == false
|
532
635
|
instance_variables.empty?.should == true
|
@@ -536,7 +639,7 @@ describe CascadingConfiguration::Setting do
|
|
536
639
|
setting_class_including_instance.instance_variables.empty?.should == true
|
537
640
|
# => instances of extending classes get nothing
|
538
641
|
class ClassExtending
|
539
|
-
extend CascadingConfiguration::Setting::
|
642
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
540
643
|
respond_to?( :some_configuration ).should == false
|
541
644
|
instance_methods.include?( :some_configuration ).should == false
|
542
645
|
instance_variables.empty?.should == true
|
@@ -546,19 +649,19 @@ describe CascadingConfiguration::Setting do
|
|
546
649
|
setting_class_including_instance.instance_variables.empty?.should == true
|
547
650
|
end
|
548
651
|
|
549
|
-
class CascadingConfiguration::Setting::
|
550
|
-
include CascadingConfiguration::Setting::
|
652
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClass
|
653
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded::SubmoduleIncluding
|
551
654
|
respond_to?( :some_configuration ).should == false
|
552
655
|
instance_variables.empty?.should == true
|
553
656
|
end
|
554
|
-
class CascadingConfiguration::Setting::
|
657
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClassSub1 < CascadingConfiguration::Setting::ObjectConfigurationMockClass
|
555
658
|
respond_to?( :some_configuration ).should == false
|
556
659
|
instance_variables.empty?.should == true
|
557
660
|
end
|
558
|
-
class CascadingConfiguration::Setting::
|
661
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClassSub2 < CascadingConfiguration::Setting::ObjectConfigurationMockClassSub1
|
559
662
|
respond_to?( :some_configuration ).should == false
|
560
663
|
instance_variables.empty?.should == true
|
561
664
|
end
|
562
665
|
end
|
563
|
-
|
666
|
+
|
564
667
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 1.4.
|
8
|
+
- 1
|
9
|
+
version: 1.4.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Asher
|
@@ -53,6 +53,7 @@ extra_rdoc_files: []
|
|
53
53
|
|
54
54
|
files:
|
55
55
|
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/AccessorDefinitionMethods.rb
|
56
|
+
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/Interface/Instance.rb
|
56
57
|
- lib/cascading-configuration-setting/CascadingConfiguration/Setting/Interface.rb
|
57
58
|
- lib/cascading-configuration-setting/CascadingConfiguration/Setting.rb
|
58
59
|
- lib/cascading-configuration-setting.rb
|