cascading-configuration-array-sorted-unique 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +225 -0
- data/README.rdoc +58 -0
- data/lib/cascading-configuration-array-sorted-unique.rb +34 -0
- data/lib/cascading-configuration-array-sorted-unique/CascadingConfiguration/Array/Sorted/Unique.rb +12 -0
- data/lib/cascading-configuration-array-sorted-unique/CascadingConfiguration/Array/Sorted/Unique/Interface.rb +107 -0
- data/lib/cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/CompositingArray.rb +17 -0
- data/lib/cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/Interface/GettersSetters.rb +224 -0
- data/lib/cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/ModuleSupportMethods.rb +47 -0
- data/spec/CascadingConfiguration/Array/Sorted/Unique_spec.rb +748 -0
- data/spec/_private_/CascadingConfiguration/Array/Sorted/Unique/CompositingArray_spec.rb +1008 -0
- metadata +87 -0
data/README.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
# Cascading Configuration Array #
|
2
|
+
|
3
|
+
http://rubygems.org/gems/cascading-configuration-array
|
4
|
+
|
5
|
+
# Description #
|
6
|
+
|
7
|
+
Adds methods for cascading configuration arrays. Support package for cascading-configuration.
|
8
|
+
|
9
|
+
# Summary #
|
10
|
+
|
11
|
+
Cascading configuration methods for arrays, 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.
|
14
|
+
|
15
|
+
# Install #
|
16
|
+
|
17
|
+
* sudo gem install cascading-configuration
|
18
|
+
|
19
|
+
# Usage #
|
20
|
+
|
21
|
+
Including the module will enable support for singleton and for instances.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module AnyModuleOrClass
|
25
|
+
include CascadingConfiguration
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Extending the module will enable support for singleton only.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
module AnyModuleOrClass
|
33
|
+
extend CascadingConfiguration
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Including or extending CascadingConfiguration includes or extends:
|
38
|
+
|
39
|
+
* CascadingConfiguration::Variable
|
40
|
+
|
41
|
+
## :attr_configuration_sorted_unique_array ##
|
42
|
+
|
43
|
+
:attr_configuration_sorted_unique_array provides inheritable array configurations that cascade downward. A composite sorted and unique array will be returned (merging downward from most distant ancestor to self).
|
44
|
+
|
45
|
+
An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
|
46
|
+
|
47
|
+
The array maintained by :attr_configuration_sorted_unique_array is kept ordered and unique.
|
48
|
+
|
49
|
+
Define initial configuration in a module or class:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
module SomeModule
|
53
|
+
|
54
|
+
include CascadingConfiguration::Array
|
55
|
+
|
56
|
+
attr_array_configuration :some_array_setting
|
57
|
+
|
58
|
+
some_array_setting # => nil
|
59
|
+
|
60
|
+
some_array_setting.push( :some_value )
|
61
|
+
|
62
|
+
some_array_setting # => [ :some_value ]
|
63
|
+
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Include initial module in a module or class:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class SomeClass
|
71
|
+
|
72
|
+
include SomeModule
|
73
|
+
|
74
|
+
some_array_setting # => [ :some_value ]
|
75
|
+
|
76
|
+
self.some_array_setting = [ :some_other_value ]
|
77
|
+
|
78
|
+
some_array_setting # => [ :some_other_value ]
|
79
|
+
|
80
|
+
some_array_setting.push( :another_value ) # => [ :another_value, :some_other_value ]
|
81
|
+
|
82
|
+
SomeModule.some_array_setting # => [ :some_value ]
|
83
|
+
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
And it cascades to instances:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
instance = SomeClass.new
|
91
|
+
|
92
|
+
instance.some_array_setting.should == [ :another_value, :some_other_value ]
|
93
|
+
|
94
|
+
instance.some_array_setting.delete( :some_other_value )
|
95
|
+
|
96
|
+
instance.some_array_setting.should == [ :another_value ]
|
97
|
+
```
|
98
|
+
|
99
|
+
### :attr_module_configuration_sorted_unique_array, :attr_class_configuration_sorted_unique_array ###
|
100
|
+
|
101
|
+
:attr_class_configuration_sorted_unique_array works like :attr_configuration_sorted_unique_array but does not cascade to instances.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
module SomeModule
|
105
|
+
|
106
|
+
include CascadingConfiguration::Array
|
107
|
+
|
108
|
+
attr_array_configuration :some_array_setting
|
109
|
+
|
110
|
+
some_array_setting # => nil
|
111
|
+
|
112
|
+
some_array_setting.push( :some_value )
|
113
|
+
|
114
|
+
some_array_setting # => [ :some_value ]
|
115
|
+
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
Include initial module in a module or class:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class SomeClass
|
123
|
+
|
124
|
+
include SomeModule
|
125
|
+
|
126
|
+
some_array_setting # => [ :some_value ]
|
127
|
+
|
128
|
+
self.some_array_setting = [ :some_other_value ]
|
129
|
+
|
130
|
+
some_array_setting # => [ :some_other_value ]
|
131
|
+
|
132
|
+
some_array_setting.push( :another_value ) # => [ :another_value, :some_other_value ]
|
133
|
+
|
134
|
+
SomeModule.some_array_setting # => [ :some_value ]
|
135
|
+
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
And it does not cascade to instances:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
instance = SomeClass.new
|
143
|
+
|
144
|
+
instance.respond_to?( :some_array_setting ).should == false
|
145
|
+
```
|
146
|
+
|
147
|
+
### :attr_local_configuration_sorted_unique_array ###
|
148
|
+
|
149
|
+
:attr_local_configuration_sorted_unique_array works like :attr_configuration_sorted_unique_array 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).
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
module SomeModule
|
153
|
+
|
154
|
+
include CascadingConfiguration::Array
|
155
|
+
|
156
|
+
attr_array_configuration :some_array_setting
|
157
|
+
|
158
|
+
some_array_setting # => nil
|
159
|
+
|
160
|
+
some_array_setting.push( :some_value )
|
161
|
+
|
162
|
+
some_array_setting # => [ :some_value ]
|
163
|
+
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
Include initial module in a module or class:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
class SomeClass
|
171
|
+
|
172
|
+
include SomeModule
|
173
|
+
|
174
|
+
respond_to?( :some_array_setting ).should == false
|
175
|
+
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
## Additional Functionality ##
|
180
|
+
|
181
|
+
Cascading-configuration also provides several other convenience functions.
|
182
|
+
|
183
|
+
### Method Redefinition ###
|
184
|
+
|
185
|
+
Any declared configuration is defined in order to support locally redefining the method and accessing the original by calling super.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
module SomeModule
|
189
|
+
|
190
|
+
include CascadingConfiguration
|
191
|
+
|
192
|
+
attr_configuration :some_array_setting
|
193
|
+
|
194
|
+
def some_array_setting=( value )
|
195
|
+
puts 'Replacing configuration array!'
|
196
|
+
super
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
```
|
201
|
+
|
202
|
+
# License #
|
203
|
+
|
204
|
+
(The MIT License)
|
205
|
+
|
206
|
+
Copyright (c) 2011 Asher
|
207
|
+
|
208
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
209
|
+
a copy of this software and associated documentation files (the
|
210
|
+
'Software'), to deal in the Software without restriction, including
|
211
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
212
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
213
|
+
permit persons to whom the Software is furnished to do so, subject to
|
214
|
+
the following conditions:
|
215
|
+
|
216
|
+
The above copyright notice and this permission notice shall be
|
217
|
+
included in all copies or substantial portions of the Software.
|
218
|
+
|
219
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
220
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
221
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
222
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
223
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
224
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
225
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
== Cascading Configuration
|
2
|
+
|
3
|
+
http://rubygems.org/gems/cascading-configuration-array
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Adds methods for cascading configuration arrays. Support package for cascading-configuration.
|
8
|
+
|
9
|
+
== Summary
|
10
|
+
|
11
|
+
Cascading configuration methods for arrays, 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.
|
14
|
+
|
15
|
+
== :attr_configuration_sorted_unique_array
|
16
|
+
|
17
|
+
:attr_configuration_sorted_unique_array provides inheritable array configurations that cascade downward. A composite sorted and unique array will be returned (merging downward from most distant ancestor to self).
|
18
|
+
|
19
|
+
An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
|
20
|
+
|
21
|
+
The array maintained by :attr_configuration_sorted_unique_array is kept ordered and unique.
|
22
|
+
|
23
|
+
:attr_class_configuration_sorted_unique_array works like :attr_configuration_sorted_unique_array but does not cascade to instances.
|
24
|
+
|
25
|
+
:attr_local_configuration_sorted_unique_array works like :attr_configuration_sorted_unique_array 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).
|
26
|
+
|
27
|
+
== Install
|
28
|
+
|
29
|
+
* sudo gem install cascading-configuration
|
30
|
+
|
31
|
+
== Usage
|
32
|
+
|
33
|
+
See README.md
|
34
|
+
|
35
|
+
== License
|
36
|
+
|
37
|
+
(The MIT License)
|
38
|
+
|
39
|
+
Copyright (c) 2011 Asher
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
42
|
+
a copy of this software and associated documentation files (the
|
43
|
+
'Software'), to deal in the Software without restriction, including
|
44
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
45
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
46
|
+
permit persons to whom the Software is furnished to do so, subject to
|
47
|
+
the following conditions:
|
48
|
+
|
49
|
+
The above copyright notice and this permission notice shall be
|
50
|
+
included in all copies or substantial portions of the Software.
|
51
|
+
|
52
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
53
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
54
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
55
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
56
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
57
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
58
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
if $__cascading_configuration__spec__development
|
3
|
+
require_relative '../../settings-array-sorted/lib/cascading-configuration-array-sorted.rb'
|
4
|
+
require_relative '../../settings-array-unique/lib/cascading-configuration-array-unique.rb'
|
5
|
+
else
|
6
|
+
require 'cascading-configuration-array-sorted'
|
7
|
+
require 'cascading-configuration-array-unique'
|
8
|
+
end
|
9
|
+
|
10
|
+
module CascadingConfiguration
|
11
|
+
module Array
|
12
|
+
module Sorted
|
13
|
+
module Unique
|
14
|
+
class CompositingArray < ::CascadingConfiguration::Array::Unique::CompositingArray
|
15
|
+
end
|
16
|
+
module ModuleSupportMethods
|
17
|
+
end
|
18
|
+
module Interface
|
19
|
+
module GettersSetters
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require_relative 'cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/CompositingArray.rb'
|
28
|
+
require_relative 'cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/Interface/GettersSetters.rb'
|
29
|
+
require_relative 'cascading-configuration-array-sorted-unique/_private_/CascadingConfiguration/Array/Sorted/Unique/ModuleSupportMethods.rb'
|
30
|
+
|
31
|
+
require_relative 'cascading-configuration-array-sorted-unique/CascadingConfiguration/Array/Sorted/Unique/Interface.rb'
|
32
|
+
require_relative 'cascading-configuration-array-sorted-unique/CascadingConfiguration/Array/Sorted/Unique.rb'
|
33
|
+
|
34
|
+
|
data/lib/cascading-configuration-array-sorted-unique/CascadingConfiguration/Array/Sorted/Unique.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array::Sorted::Unique
|
3
|
+
|
4
|
+
# Configuration modules for storage of settings arrays
|
5
|
+
include ::CascadingConfiguration::Variable
|
6
|
+
|
7
|
+
# Interface to declare configuration settings arrays
|
8
|
+
include ::CascadingConfiguration::Array::Sorted::Unique::Interface
|
9
|
+
|
10
|
+
extend ::CascadingConfiguration::Array::Sorted::Unique::ModuleSupportMethods
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array::Sorted::Unique::Interface
|
3
|
+
|
4
|
+
# Support methods that define configuration settings array methods
|
5
|
+
include ::CascadingConfiguration::Array::Sorted::Unique::Interface::GettersSetters
|
6
|
+
|
7
|
+
############################################
|
8
|
+
# attr_configuration_sorted_unique_array #
|
9
|
+
############################################
|
10
|
+
|
11
|
+
# defines configuration in class or module
|
12
|
+
# configuration cascades downward to instance including all classes or modules in-between
|
13
|
+
def attr_configuration_sorted_unique_array( *configuration_names )
|
14
|
+
|
15
|
+
configuration_names.each do |this_configuration_name|
|
16
|
+
# define configuration setter
|
17
|
+
define_cascading_sorted_unique_array_setter( this_configuration_name )
|
18
|
+
# define configuration getter
|
19
|
+
define_cascading_sorted_unique_array_getter( this_configuration_name )
|
20
|
+
end
|
21
|
+
|
22
|
+
return self
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
###################################################
|
27
|
+
# attr_module_configuration_sorted_unique_array #
|
28
|
+
###################################################
|
29
|
+
|
30
|
+
# defines configuration in class or module
|
31
|
+
# configuration cascades downward to last class or module
|
32
|
+
def attr_module_configuration_sorted_unique_array( *configuration_names )
|
33
|
+
|
34
|
+
configuration_names.each do |this_configuration_name|
|
35
|
+
# define configuration setter
|
36
|
+
define_class_configuration_sorted_unique_array_setter( this_configuration_name )
|
37
|
+
# define configuration getter
|
38
|
+
define_class_configuration_sorted_unique_array_getter( this_configuration_name )
|
39
|
+
end
|
40
|
+
|
41
|
+
return self
|
42
|
+
|
43
|
+
end
|
44
|
+
alias_method :attr_class_configuration_sorted_unique_array, :attr_module_configuration_sorted_unique_array
|
45
|
+
|
46
|
+
##################################################
|
47
|
+
# attr_local_configuration_sorted_unique_array #
|
48
|
+
##################################################
|
49
|
+
|
50
|
+
# defines configuration in present class or module context
|
51
|
+
# configuration does not cascade
|
52
|
+
def attr_local_configuration_sorted_unique_array( *configuration_names )
|
53
|
+
|
54
|
+
::CascadingConfiguration::Variable.create_local_instance_configuration_support_module( self )
|
55
|
+
|
56
|
+
configuration_names.each do |this_configuration_name|
|
57
|
+
# define configuration setter
|
58
|
+
define_local_configuration_sorted_unique_array_setter( this_configuration_name )
|
59
|
+
# define configuration getter
|
60
|
+
define_local_configuration_sorted_unique_array_getter( this_configuration_name )
|
61
|
+
end
|
62
|
+
|
63
|
+
return self
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
###################################################
|
68
|
+
# attr_object_configuration_sorted_unique_array #
|
69
|
+
###################################################
|
70
|
+
|
71
|
+
# defines configuration in present instance
|
72
|
+
# configuration does not cascade
|
73
|
+
def attr_object_configuration_sorted_unique_array( *configuration_names )
|
74
|
+
|
75
|
+
::CascadingConfiguration::Variable.create_local_instance_configuration_support_module( self )
|
76
|
+
|
77
|
+
configuration_names.each do |this_configuration_name|
|
78
|
+
# define configuration setter
|
79
|
+
define_object_configuration_sorted_unique_array_setter( this_configuration_name )
|
80
|
+
# define configuration getter
|
81
|
+
define_object_configuration_sorted_unique_array_getter( this_configuration_name )
|
82
|
+
end
|
83
|
+
|
84
|
+
return self
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
#####################################################
|
89
|
+
# attr_instance_configuration_sorted_unique_array #
|
90
|
+
#####################################################
|
91
|
+
|
92
|
+
# defines configuration in present class or module context
|
93
|
+
# configuration does not cascade
|
94
|
+
def attr_instance_configuration_sorted_unique_array( *configuration_names )
|
95
|
+
|
96
|
+
configuration_names.each do |this_configuration_name|
|
97
|
+
# define configuration setter
|
98
|
+
define_instance_configuration_sorted_unique_array_setter( this_configuration_name )
|
99
|
+
# define configuration getter
|
100
|
+
define_instance_configuration_sorted_unique_array_getter( this_configuration_name )
|
101
|
+
end
|
102
|
+
|
103
|
+
return self
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
class ::CascadingConfiguration::Array::Sorted::Unique::CompositingArray <
|
3
|
+
::CascadingConfiguration::Array::Unique::CompositingArray
|
4
|
+
|
5
|
+
include CascadingConfiguration::Array::Sorted::CompositingArray::Interface
|
6
|
+
|
7
|
+
###########
|
8
|
+
# uniq! #
|
9
|
+
###########
|
10
|
+
|
11
|
+
def uniq!
|
12
|
+
|
13
|
+
return self
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|