cascading-configuration-array 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,6 +77,42 @@ module CascadingConfiguration::Array::AccessorDefinitionMethods
77
77
  #############################################
78
78
 
79
79
  def define_local_configuration_array_setter( configuration_name )
80
+ configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
81
+ [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
82
+ module_support.module_eval do
83
+ define_method( configuration_setter_name ) do |array|
84
+ composite_array = composite_array_for_cascading_configuration( configuration_name )
85
+ # we want the array to supplant existing config
86
+ # clear the array (excludes everything explicitly)
87
+ composite_array.clear
88
+ # push array elements (removes anything excluded from exclude)
89
+ composite_array.push( *array )
90
+ return composite_array
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ #############################################
97
+ # define_local_configuration_array_getter #
98
+ #############################################
99
+
100
+ def define_local_configuration_array_getter( configuration_name )
101
+ configuration_getter_name = configuration_name
102
+ [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
103
+ module_support.module_eval do
104
+ define_method( configuration_getter_name ) do
105
+ return composite_array_for_cascading_configuration( configuration_name )
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ ################################################
112
+ # define_existant_configuration_array_setter #
113
+ ################################################
114
+
115
+ def define_existant_configuration_array_setter( configuration_name )
80
116
  configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
81
117
  accessor_local_instance_support.module_eval do
82
118
  define_method( configuration_setter_name ) do |array|
@@ -91,11 +127,11 @@ module CascadingConfiguration::Array::AccessorDefinitionMethods
91
127
  end
92
128
  end
93
129
 
94
- #############################################
95
- # define_local_configuration_array_getter #
96
- #############################################
130
+ ################################################
131
+ # define_existant_configuration_array_getter #
132
+ ################################################
97
133
 
98
- def define_local_configuration_array_getter( configuration_name )
134
+ def define_existant_configuration_array_getter( configuration_name )
99
135
  configuration_getter_name = configuration_name
100
136
  accessor_local_instance_support.module_eval do
101
137
  define_method( configuration_getter_name ) do
@@ -103,5 +139,5 @@ module CascadingConfiguration::Array::AccessorDefinitionMethods
103
139
  end
104
140
  end
105
141
  end
106
-
142
+
107
143
  end
@@ -48,6 +48,23 @@ module CascadingConfiguration::Array::Interface
48
48
  # define configuration getter
49
49
  define_local_configuration_array_getter( this_property_name )
50
50
  end
51
+ CascadingConfiguration::Variable.cascade_local_instance( self )
52
+ end
53
+
54
+ #######################################
55
+ # attr_existant_configuration_array #
56
+ #######################################
57
+
58
+ # defines configuration in present class or module context
59
+ # configuration does not cascade
60
+ def attr_existant_configuration_array( *property_names )
61
+ CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
62
+ property_names.each do |this_property_name|
63
+ # define configuration setter
64
+ define_existant_configuration_array_setter( this_property_name )
65
+ # define configuration getter
66
+ define_existant_configuration_array_getter( this_property_name )
67
+ end
51
68
  end
52
69
 
53
70
  end
@@ -414,11 +414,145 @@ describe CascadingConfiguration::Array do
414
414
  configuration_setting.should == []
415
415
  configuration_setting.push( :a_configuration )
416
416
  configuration_setting.should == [ :a_configuration ]
417
- instance_methods.include?( :configuration_setting ).should == false
417
+ instance_methods.include?( :configuration_setting ).should == true
418
418
  instance_variables.empty?.should == true
419
419
  # => including modules and classes get attr_configuration and configurations
420
420
  module SubmoduleIncluding
421
421
  include CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
422
+ instance_methods.include?( :configuration_setting ).should == true
423
+ respond_to?( :configuration_setting ).should == true
424
+ instance_variables.empty?.should == true
425
+ end
426
+ # => extending modules and classes get attr_configuration and configurations
427
+ module SubmoduleExtending
428
+ extend CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
429
+ # if we're extended then we want to use the eigenclass ancestor chain
430
+ # - the first ancestor will be the extending module
431
+ # - the rest of the ancestors will be the extending module's include chain
432
+ respond_to?( :configuration_setting ).should == true
433
+ instance_methods.include?( :configuration_setting ).should == false
434
+ instance_variables.empty?.should == true
435
+ end
436
+ # => instances of including classes get configurations
437
+ class ClassIncluding
438
+ include CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
439
+ instance_methods.include?( :configuration_setting ).should == true
440
+ respond_to?( :configuration_setting ).should == true
441
+ instance_variables.empty?.should == true
442
+ end
443
+ setting_class_including_instance = ClassIncluding.new
444
+ setting_class_including_instance.respond_to?( :configuration_setting ).should == true
445
+ setting_class_including_instance.instance_variables.empty?.should == true
446
+ # => instances of extending classes get nothing
447
+ class ClassExtending
448
+ extend CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
449
+ instance_methods.include?( :configuration_setting ).should == false
450
+ respond_to?( :configuration_setting ).should == true
451
+ instance_variables.empty?.should == true
452
+ end
453
+ setting_class_including_instance = ClassExtending.new
454
+ setting_class_including_instance.respond_to?( :configuration_setting ).should == false
455
+ setting_class_including_instance.instance_variables.empty?.should == true
456
+ end
457
+
458
+ class CascadingConfiguration::Array::LocalConfigurationMockClass
459
+ include CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded::SubmoduleIncluding
460
+ instance_methods.include?( :configuration_setting ).should == true
461
+ respond_to?( :configuration_setting ).should == false
462
+ instance_variables.empty?.should == true
463
+ end
464
+ object_instance_one = CascadingConfiguration::Array::LocalConfigurationMockClass.new
465
+ object_instance_one.respond_to?( :configuration_setting ).should == true
466
+ object_instance_one.instance_variables.empty?.should == true
467
+ class CascadingConfiguration::Array::LocalConfigurationMockClassSub1 < CascadingConfiguration::Array::LocalConfigurationMockClass
468
+ instance_methods.include?( :configuration_setting ).should == true
469
+ respond_to?( :configuration_setting ).should == false
470
+ instance_variables.empty?.should == true
471
+ end
472
+ object_instance_two = CascadingConfiguration::Array::LocalConfigurationMockClassSub1.new
473
+ object_instance_two.respond_to?( :configuration_setting ).should == true
474
+ object_instance_two.instance_variables.empty?.should == true
475
+ class CascadingConfiguration::Array::LocalConfigurationMockClassSub2 < CascadingConfiguration::Array::LocalConfigurationMockClassSub1
476
+ instance_methods.include?( :configuration_setting ).should == true
477
+ respond_to?( :configuration_setting ).should == false
478
+ instance_variables.empty?.should == true
479
+ end
480
+
481
+ end
482
+
483
+ #######################################
484
+ # attr_existant_configuration_array #
485
+ #######################################
486
+
487
+ it 'can define a local configuration array, which will not cascade' do
488
+
489
+ # possibilities:
490
+ # * module extended with setting
491
+ # => singleton gets attr_configuration and configurations
492
+ # => including modules and classes get nothing
493
+ # => extending modules and classes get nothing
494
+ # => instances of including and extending classes get nothing
495
+ # * module included with setting
496
+ # => singleton gets attr_configuration and configurations
497
+ # => including modules and classes get attr_configuration and configurations
498
+ # => instances of including classes get configurations
499
+ # => extending modules and classes get attr_configuration and configurations
500
+ # => instances of extending classes get nothing
501
+ module CascadingConfiguration::Array::InstanceConfigurationMockModuleExtended
502
+ extend CascadingConfiguration::Array
503
+ # => singleton gets attr_configuration and configurations
504
+ respond_to?( :attr_existant_configuration_array ).should == true
505
+ attr_existant_configuration_array :configuration_setting
506
+ respond_to?( :configuration_setting ).should == true
507
+ configuration_setting.should == []
508
+ configuration_setting.push( :a_configuration )
509
+ configuration_setting.should == [ :a_configuration ]
510
+ instance_methods.include?( :configuration_setting ).should == false
511
+ instance_variables.empty?.should == true
512
+ # => including modules and classes get nothing
513
+ module SubmoduleIncluding
514
+ include CascadingConfiguration::Array::InstanceConfigurationMockModuleExtended
515
+ instance_methods.include?( :configuration_setting ).should == false
516
+ respond_to?( :configuration_setting ).should == false
517
+ instance_variables.empty?.should == true
518
+ end
519
+ # => extending modules and classes get nothing
520
+ module SubmoduleExtending
521
+ extend CascadingConfiguration::Array::InstanceConfigurationMockModuleExtended
522
+ instance_methods.include?( :configuration_setting ).should == false
523
+ respond_to?( :configuration_setting ).should == false
524
+ instance_variables.empty?.should == true
525
+ end
526
+ # => instances of including and extending classes get nothing
527
+ class ClassIncluding
528
+ include CascadingConfiguration::Array::InstanceConfigurationMockModuleExtended
529
+ instance_methods.include?( :configuration_setting ).should == false
530
+ respond_to?( :configuration_setting ).should == false
531
+ instance_variables.empty?.should == true
532
+ end
533
+ class ClassExtending
534
+ extend CascadingConfiguration::Array::InstanceConfigurationMockModuleExtended
535
+ instance_methods.include?( :configuration_setting ).should == false
536
+ respond_to?( :configuration_setting ).should == false
537
+ instance_variables.empty?.should == true
538
+ end
539
+ end
540
+
541
+ # * module included with setting
542
+ module CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded
543
+ include CascadingConfiguration::Array
544
+ # => singleton gets attr_configuration and configurations
545
+ respond_to?( :attr_existant_configuration_array ).should == true
546
+ attr_existant_configuration_array :configuration_setting
547
+ respond_to?( :configuration_setting ).should == true
548
+ configuration_setting.should == []
549
+ configuration_setting.push( :a_configuration )
550
+ configuration_setting.should == [ :a_configuration ]
551
+ instance_methods.include?( :configuration_setting ).should == false
552
+ instance_variables.empty?.should == true
553
+ # => including modules and classes get attr_configuration and configurations
554
+ module SubmoduleIncluding
555
+ include CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded
422
556
  instance_methods.include?( :configuration_setting ).should == false
423
557
  respond_to?( :configuration_setting ).should == false
424
558
  instance_methods.include?( :configuration_setting ).should == false
@@ -426,7 +560,7 @@ describe CascadingConfiguration::Array do
426
560
  end
427
561
  # => extending modules and classes get attr_configuration and configurations
428
562
  module SubmoduleExtending
429
- extend CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
563
+ extend CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded
430
564
  # if we're extended then we want to use the eigenclass ancestor chain
431
565
  # - the first ancestor will be the extending module
432
566
  # - the rest of the ancestors will be the extending module's include chain
@@ -436,7 +570,7 @@ describe CascadingConfiguration::Array do
436
570
  end
437
571
  # => instances of including classes get configurations
438
572
  class ClassIncluding
439
- include CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
573
+ include CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded
440
574
  instance_methods.include?( :configuration_setting ).should == false
441
575
  respond_to?( :configuration_setting ).should == false
442
576
  instance_variables.empty?.should == true
@@ -446,7 +580,7 @@ describe CascadingConfiguration::Array do
446
580
  setting_class_including_instance.instance_variables.empty?.should == true
447
581
  # => instances of extending classes get nothing
448
582
  class ClassExtending
449
- extend CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded
583
+ extend CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded
450
584
  instance_methods.include?( :configuration_setting ).should == false
451
585
  respond_to?( :configuration_setting ).should == false
452
586
  instance_variables.empty?.should == true
@@ -456,24 +590,24 @@ describe CascadingConfiguration::Array do
456
590
  setting_class_including_instance.instance_variables.empty?.should == true
457
591
  end
458
592
 
459
- class CascadingConfiguration::Array::LocalConfigurationMockClass
460
- include CascadingConfiguration::Array::LocalConfigurationMockModuleIncluded::SubmoduleIncluding
593
+ class CascadingConfiguration::Array::InstanceConfigurationMockClass
594
+ include CascadingConfiguration::Array::InstanceConfigurationMockModuleIncluded::SubmoduleIncluding
461
595
  instance_methods.include?( :configuration_setting ).should == false
462
596
  respond_to?( :configuration_setting ).should == false
463
597
  instance_variables.empty?.should == true
464
598
  end
465
- object_instance_one = CascadingConfiguration::Array::LocalConfigurationMockClass.new
599
+ object_instance_one = CascadingConfiguration::Array::InstanceConfigurationMockClass.new
466
600
  object_instance_one.respond_to?( :configuration_setting ).should == false
467
601
  object_instance_one.instance_variables.empty?.should == true
468
- class CascadingConfiguration::Array::LocalConfigurationMockClassSub1 < CascadingConfiguration::Array::LocalConfigurationMockClass
602
+ class CascadingConfiguration::Array::InstanceConfigurationMockClassSub1 < CascadingConfiguration::Array::InstanceConfigurationMockClass
469
603
  instance_methods.include?( :configuration_setting ).should == false
470
604
  respond_to?( :configuration_setting ).should == false
471
605
  instance_variables.empty?.should == true
472
606
  end
473
- object_instance_two = CascadingConfiguration::Array::LocalConfigurationMockClassSub1.new
607
+ object_instance_two = CascadingConfiguration::Array::InstanceConfigurationMockClassSub1.new
474
608
  object_instance_two.respond_to?( :configuration_setting ).should == false
475
609
  object_instance_two.instance_variables.empty?.should == true
476
- class CascadingConfiguration::Array::LocalConfigurationMockClassSub2 < CascadingConfiguration::Array::LocalConfigurationMockClassSub1
610
+ class CascadingConfiguration::Array::InstanceConfigurationMockClassSub2 < CascadingConfiguration::Array::InstanceConfigurationMockClassSub1
477
611
  instance_methods.include?( :configuration_setting ).should == false
478
612
  respond_to?( :configuration_setting ).should == false
479
613
  instance_variables.empty?.should == true
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