cascading-configuration-array 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,155 @@
1
+
2
+ require_relative '../../lib/cascading-configuration-array.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationArray do
5
+
6
+ #########
7
+ # []= #
8
+ #########
9
+
10
+ it 'can add elements' do
11
+ array_instance = CascadingConfiguration::ConfigurationArray.new
12
+ array_instance[0] = :some_setting
13
+ array_instance.should == [ :some_setting ]
14
+ array_instance.exclude_array.include?( :some_setting ).should == false
15
+ array_instance[1] = :other_setting
16
+ array_instance.should == [ :other_setting, :some_setting ]
17
+ array_instance.exclude_array.include?( :other_setting ).should == false
18
+ end
19
+
20
+ ########
21
+ # << #
22
+ ########
23
+
24
+ it 'can add elements' do
25
+ array_instance = CascadingConfiguration::ConfigurationArray.new
26
+ array_instance << :some_setting
27
+ array_instance.should == [ :some_setting ]
28
+ array_instance.exclude_array.include?( :some_setting ).should == false
29
+ array_instance << :other_setting
30
+ array_instance.should == [ :other_setting, :some_setting ]
31
+ array_instance.exclude_array.include?( :other_setting ).should == false
32
+ end
33
+
34
+ #######
35
+ # + #
36
+ #######
37
+
38
+ it 'can add elements' do
39
+ array_instance = CascadingConfiguration::ConfigurationArray.new
40
+ array_instance += [ :some_setting ]
41
+ array_instance.should == [ :some_setting ]
42
+ array_instance.exclude_array.include?( :some_setting ).should == false
43
+ array_instance += [ :other_setting ]
44
+ array_instance.should == [ :other_setting, :some_setting ]
45
+ array_instance.exclude_array.include?( :other_setting ).should == false
46
+ end
47
+
48
+ ##########
49
+ # push #
50
+ ##########
51
+
52
+ it 'can add elements' do
53
+ array_instance = CascadingConfiguration::ConfigurationArray.new
54
+ array_instance.push( :some_setting )
55
+ array_instance.should == [ :some_setting ]
56
+ array_instance.exclude_array.include?( :some_setting ).should == false
57
+ array_instance.push( :other_setting )
58
+ array_instance.should == [ :other_setting, :some_setting ]
59
+ array_instance.exclude_array.include?( :other_setting ).should == false
60
+ end
61
+
62
+ ############
63
+ # concat #
64
+ ############
65
+
66
+ it 'can concat arrays' do
67
+ array_instance = CascadingConfiguration::ConfigurationArray.new
68
+ array_instance.concat( [ :some_setting ] )
69
+ array_instance.should == [ :some_setting ]
70
+ array_instance.exclude_array.include?( :some_setting ).should == false
71
+ array_instance.concat( [ :other_setting ] )
72
+ array_instance.should == [ :other_setting, :some_setting ]
73
+ array_instance.exclude_array.include?( :other_setting ).should == false
74
+ end
75
+
76
+ #######
77
+ # - #
78
+ #######
79
+
80
+ it 'can exclude elements' do
81
+ array_instance = CascadingConfiguration::ConfigurationArray.new
82
+ array_instance += [ :some_setting, :other_setting ]
83
+ array_instance -= [ :other_setting ]
84
+ array_instance.should == [ :some_setting ]
85
+ array_instance.exclude_array.include?( :other_setting ).should == true
86
+ array_instance -= [ :some_setting ]
87
+ array_instance.should == []
88
+ array_instance.exclude_array.include?( :some_setting ).should == true
89
+ end
90
+
91
+ ############
92
+ # delete #
93
+ ############
94
+
95
+ it 'can exclude elements' do
96
+ array_instance = CascadingConfiguration::ConfigurationArray.new
97
+ array_instance += [ :some_setting, :other_setting ]
98
+ array_instance.delete( :other_setting )
99
+ array_instance.should == [ :some_setting ]
100
+ array_instance.exclude_array.include?( :other_setting ).should == true
101
+ array_instance.delete( :some_setting )
102
+ array_instance.should == []
103
+ array_instance.exclude_array.include?( :some_setting ).should == true
104
+ end
105
+
106
+ #########
107
+ # pop #
108
+ #########
109
+
110
+ it 'can pop the final element' do
111
+ array_instance = CascadingConfiguration::ConfigurationArray.new
112
+ array_instance += [ :other_setting, :some_setting ]
113
+ array_instance.pop.should == :some_setting
114
+ array_instance.should == [ :other_setting ]
115
+ array_instance.exclude_array.include?( :some_setting ).should == true
116
+ end
117
+
118
+ ###########
119
+ # shift #
120
+ ###########
121
+
122
+ it 'can shift the first element' do
123
+ array_instance = CascadingConfiguration::ConfigurationArray.new
124
+ array_instance += [ :other_setting, :some_setting ]
125
+ array_instance.shift.should == :other_setting
126
+ array_instance.should == [ :some_setting ]
127
+ array_instance.exclude_array.include?( :other_setting ).should == true
128
+ end
129
+
130
+ ############
131
+ # slice! #
132
+ ############
133
+
134
+ it 'can slice elements' do
135
+ array_instance = CascadingConfiguration::ConfigurationArray.new
136
+ array_instance += [ :other_setting, :some_setting ]
137
+ array_instance.slice!( 0, 1 ).should == [ :other_setting ]
138
+ array_instance.should == [ :some_setting ]
139
+ array_instance.exclude_array.include?( :other_setting ).should == true
140
+ end
141
+
142
+ ###########
143
+ # clear #
144
+ ###########
145
+
146
+ it 'can clear, causing present elements to be excluded' do
147
+ array_instance = CascadingConfiguration::ConfigurationArray.new
148
+ array_instance += [ :some_setting, :other_setting ]
149
+ array_instance.clear
150
+ array_instance.should == []
151
+ array_instance.exclude_array.include?( :some_setting ).should == true
152
+ array_instance.exclude_array.include?( :other_setting ).should == true
153
+ end
154
+
155
+ end
@@ -0,0 +1,28 @@
1
+
2
+ require_relative '../../../lib/cascading-configuration-array.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationSettingsArray::Accessors do
5
+
6
+ #######################################
7
+ # define_configuration_array_setter #
8
+ # define_configuration_array_getter #
9
+ #######################################
10
+
11
+ it 'can define a method to get and modify the configuration array' do
12
+ class CascadingConfiguration::ConfigurationSettingsArray::Mock
13
+ include CascadingConfiguration::ConfigurationVariable
14
+ extend CascadingConfiguration::ConfigurationSettingsArray::Accessors
15
+ include CascadingConfiguration::ConfigurationSettingsArray::ObjectInstance
16
+ extend CascadingConfiguration::ConfigurationSettingsArray::ClassInstance
17
+ end
18
+ # setter
19
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.define_configuration_array_setter( :some_configuration )
20
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.methods.include?( :some_configuration= ).should == true
21
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.instance_methods.include?( :some_configuration= ).should == true
22
+ # getter
23
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.define_configuration_array_getter( :some_configuration )
24
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.methods.include?( :some_configuration ).should == true
25
+ CascadingConfiguration::ConfigurationSettingsArray::Mock.instance_methods.include?( :some_configuration ).should == true
26
+ end
27
+
28
+ end
@@ -0,0 +1,75 @@
1
+
2
+ require_relative '../../lib/cascading-configuration-array.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationSettingsArray do
5
+
6
+ ##############################
7
+ # attr_configuration_array #
8
+ ##############################
9
+
10
+ it 'can define a configuration array, which is the primary interface' do
11
+
12
+ module CascadingConfiguration::ConfigurationSettingsArray::MockModule
13
+ include CascadingConfiguration::ConfigurationSettingsArray
14
+ attr_configuration_array :configuration_setting
15
+ configuration_setting.should == []
16
+ configuration_setting.push( :a_configuration )
17
+ configuration_setting.should == [ :a_configuration ]
18
+ end
19
+
20
+ module CascadingConfiguration::ConfigurationSettingsArray::MockModule2
21
+ include CascadingConfiguration::ConfigurationSettingsArray::MockModule
22
+ configuration_setting.should == [ :a_configuration ]
23
+ configuration_setting.push( :another_configuration )
24
+ configuration_setting.should == [ :a_configuration, :another_configuration ]
25
+ end
26
+
27
+ module CascadingConfiguration::ConfigurationSettingsArray::MockModule3
28
+ include CascadingConfiguration::ConfigurationSettingsArray::MockModule2
29
+ configuration_setting.should == [ :a_configuration, :another_configuration ]
30
+ end
31
+
32
+ class CascadingConfiguration::ConfigurationSettingsArray::MockClass
33
+ include CascadingConfiguration::ConfigurationSettingsArray::MockModule3
34
+ configuration_setting.should == [ :a_configuration, :another_configuration ]
35
+ configuration_setting.delete( :another_configuration )
36
+ configuration_setting.should == [ :a_configuration ]
37
+ end
38
+
39
+ object_instance_one = CascadingConfiguration::ConfigurationSettingsArray::MockClass.new
40
+ object_instance_one.configuration_setting.should == [ :a_configuration ]
41
+ object_instance_one.configuration_setting.push( :some_other_configuration )
42
+ object_instance_one.configuration_setting.should == [ :a_configuration, :some_other_configuration ]
43
+
44
+ class CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1 < CascadingConfiguration::ConfigurationSettingsArray::MockClass
45
+ configuration_setting.should == [ :a_configuration ]
46
+ configuration_setting.push( :another_configuration)
47
+ configuration_setting.should == [ :a_configuration, :another_configuration ]
48
+ end
49
+
50
+ object_instance_two = CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1.new
51
+ object_instance_two.configuration_setting.should == [ :a_configuration, :another_configuration ]
52
+ object_instance_two.configuration_setting.push( :some_other_configuration )
53
+ object_instance_two.configuration_setting.should == [ :a_configuration, :another_configuration, :some_other_configuration ]
54
+
55
+ # change ancestor setting
56
+ CascadingConfiguration::ConfigurationSettingsArray::MockClass.configuration_setting.push( :a_yet_unused_configuration )
57
+ CascadingConfiguration::ConfigurationSettingsArray::MockClass.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration ]
58
+ object_instance_one.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :some_other_configuration ]
59
+ CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :another_configuration ]
60
+ object_instance_two.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :another_configuration, :some_other_configuration ]
61
+
62
+ # freeze ancestor setting
63
+ object_instance_one.configuration_setting.freeze!
64
+ object_instance_one.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :some_other_configuration ]
65
+ CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1.configuration_setting.freeze!
66
+ CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :another_configuration ]
67
+ CascadingConfiguration::ConfigurationSettingsArray::MockClass.configuration_setting.push( :non_cascading_configuration )
68
+ CascadingConfiguration::ConfigurationSettingsArray::MockClass.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :non_cascading_configuration ]
69
+ object_instance_one.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :some_other_configuration ]
70
+ CascadingConfiguration::ConfigurationSettingsArray::MockClassSub1.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :another_configuration ]
71
+ object_instance_two.configuration_setting.should == [ :a_configuration, :a_yet_unused_configuration, :another_configuration, :some_other_configuration ]
72
+
73
+ end
74
+
75
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cascading-configuration-array
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Asher
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-13 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cascading-configuration-variable
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Provides :attr_configuration_array.
34
+ email: asher@ridiculouspower.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - lib/cascading-configuration-array/CascadingConfiguration/_private_/CascadingCompositeArray.rb
43
+ - lib/cascading-configuration-array/CascadingConfiguration/_private_/ConfigurationArray.rb
44
+ - lib/cascading-configuration-array/CascadingConfiguration/CascadingCompositeArray/_private_/Instance.rb
45
+ - lib/cascading-configuration-array/CascadingConfiguration/CascadingCompositeArray/Instance.rb
46
+ - lib/cascading-configuration-array/CascadingConfiguration/CascadingCompositeArray.rb
47
+ - lib/cascading-configuration-array/CascadingConfiguration/ConfigurationArray.rb
48
+ - lib/cascading-configuration-array/CascadingConfiguration/ConfigurationSettingsArray/Accessors.rb
49
+ - lib/cascading-configuration-array/CascadingConfiguration/ConfigurationSettingsArray/ClassInstance.rb
50
+ - lib/cascading-configuration-array/CascadingConfiguration/ConfigurationSettingsArray/ModuleInstance.rb
51
+ - lib/cascading-configuration-array/CascadingConfiguration/ConfigurationSettingsArray.rb
52
+ - lib/cascading-configuration-array.rb
53
+ - spec/CascadingConfiguration/CascadingCompositeArray_spec.rb
54
+ - spec/CascadingConfiguration/ConfigurationArray_spec.rb
55
+ - spec/CascadingConfiguration/ConfigurationSettingsArray/Accessors_spec.rb
56
+ - spec/CascadingConfiguration/ConfigurationSettingsArray_spec.rb
57
+ - README.rdoc
58
+ has_rdoc: true
59
+ homepage: http://rubygems.org/gems/cascading-configuration-array
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: cascading-configuration-array
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Support package for cascading-configuration.
90
+ test_files: []
91
+