array-sorted-compositing 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +22 -0
- data/README.md +75 -0
- data/README.rdoc +0 -0
- data/lib/array-sorted-compositing.rb +2 -0
- data/lib/array/hooked/compositing/sorted.rb +2 -0
- data/lib/array/sorted/compositing.rb +17 -0
- data/lib/array/sorted/compositing/array_interface.rb +23 -0
- data/lib/array/sorted/namespaces.rb +5 -0
- data/lib/array/sorted/requires.rb +3 -0
- data/spec/array/sorted/compositing_spec.rb +1083 -0
- metadata +89 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
== 3/17/12
|
3
|
+
|
4
|
+
Initial release.
|
5
|
+
|
6
|
+
== 3/18/12
|
7
|
+
|
8
|
+
Added hooks for subclassing.
|
9
|
+
|
10
|
+
== 3/30/12
|
11
|
+
|
12
|
+
Added return self to end of reverse!
|
13
|
+
Added sort_block to :new to provide sorting by return value of block.
|
14
|
+
|
15
|
+
== 6/1/12
|
16
|
+
|
17
|
+
Added :configuration_instance parameter to :initialize.
|
18
|
+
|
19
|
+
== 6/15/12
|
20
|
+
|
21
|
+
Moved hooks out to array-sorted and utilized array-sorted as foundation.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Sorted Compositing Array #
|
2
|
+
|
3
|
+
http://rubygems.org/gems/array-sorted-compositing
|
4
|
+
|
5
|
+
# Description #
|
6
|
+
|
7
|
+
Provides Array::Sorted::Compositing.
|
8
|
+
|
9
|
+
# Summary #
|
10
|
+
|
11
|
+
An implementation of Array that permits chaining, where children inherit changes to parent and where parent settings can be overridden in children, and that retains sorted order.
|
12
|
+
|
13
|
+
# Install #
|
14
|
+
|
15
|
+
* sudo gem install array-sorted-compositing
|
16
|
+
|
17
|
+
# Usage #
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
compositing_array = Array::Sorted::Compositing.new
|
21
|
+
sub_compositing_array = Array::Sorted::Compositing.new( compositing_array )
|
22
|
+
|
23
|
+
compositing_array.push( :A )
|
24
|
+
# compositing_array
|
25
|
+
# => [ :A ]
|
26
|
+
# sub_compositing_array
|
27
|
+
# => [ :A ]
|
28
|
+
compositing_array.push( :C )
|
29
|
+
# compositing_array
|
30
|
+
# => [ :A, :C ]
|
31
|
+
# sub_compositing_array
|
32
|
+
# => [ :A, :C ]
|
33
|
+
compositing_array.push( :B )
|
34
|
+
# compositing_array
|
35
|
+
# => [ :A, :B, :C ]
|
36
|
+
# sub_compositing_array
|
37
|
+
# => [ :A, :B, :C ]
|
38
|
+
|
39
|
+
compositing_array.delete_at( 0 )
|
40
|
+
# compositing_array
|
41
|
+
# => [ :B, :C ]
|
42
|
+
# sub_compositing_array
|
43
|
+
# => [ :B, :C ]
|
44
|
+
|
45
|
+
sub_compositing_array.push( :A )
|
46
|
+
# compositing_array
|
47
|
+
# => [ :B, :C ]
|
48
|
+
# sub_compositing_array
|
49
|
+
# => [ :A, :B, :C ]
|
50
|
+
```
|
51
|
+
|
52
|
+
# License #
|
53
|
+
|
54
|
+
(The MIT License)
|
55
|
+
|
56
|
+
Copyright (c) Asher
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
'Software'), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
72
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
73
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
74
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
75
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'array/sorted'
|
3
|
+
require 'array/compositing'
|
4
|
+
#require_relative '../../../../../hooked_objects/array-sorted/lib/array-sorted.rb'
|
5
|
+
#require_relative '../../../../array-compositing/lib/array-compositing.rb'
|
6
|
+
|
7
|
+
# namespaces that have to be declared ahead of time for proper load order
|
8
|
+
require_relative './namespaces'
|
9
|
+
|
10
|
+
# source file requires
|
11
|
+
require_relative './requires.rb'
|
12
|
+
|
13
|
+
class ::Array::Sorted::Compositing < ::Array::Hooked
|
14
|
+
|
15
|
+
include ::Array::Sorted::Compositing::ArrayInterface
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module ::Array::Sorted::Compositing::ArrayInterface
|
3
|
+
|
4
|
+
include ::Array::Sorted::ArrayInterface
|
5
|
+
include ::Array::Compositing::ArrayInterface
|
6
|
+
|
7
|
+
##############
|
8
|
+
# reverse! #
|
9
|
+
##############
|
10
|
+
|
11
|
+
def reverse!
|
12
|
+
|
13
|
+
super
|
14
|
+
|
15
|
+
@sub_composite_arrays.each do |this_sub_array|
|
16
|
+
this_sub_array.instance_eval do
|
17
|
+
parent_reversed!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,1083 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../lib/array-sorted-compositing.rb'
|
3
|
+
|
4
|
+
describe ::Array::Sorted::Compositing do
|
5
|
+
|
6
|
+
################
|
7
|
+
# initialize #
|
8
|
+
################
|
9
|
+
|
10
|
+
it 'can add initialize with an ancestor, inheriting its values and linking to it as a child' do
|
11
|
+
|
12
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
13
|
+
|
14
|
+
cascading_composite_array.instance_variable_get( :@parent_composite_object ).should == nil
|
15
|
+
cascading_composite_array.should == [ ]
|
16
|
+
|
17
|
+
cascading_composite_array.push( :A, :B, :C, :D )
|
18
|
+
|
19
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
20
|
+
sub_cascading_composite_array.instance_variable_get( :@parent_composite_object ).should == cascading_composite_array
|
21
|
+
sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
#########
|
26
|
+
# []= #
|
27
|
+
#########
|
28
|
+
|
29
|
+
it 'can add elements' do
|
30
|
+
|
31
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
32
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
33
|
+
|
34
|
+
cascading_composite_array[ 0 ] = :A
|
35
|
+
cascading_composite_array.should == [ :A ]
|
36
|
+
sub_cascading_composite_array.should == [ :A ]
|
37
|
+
|
38
|
+
cascading_composite_array[ 1 ] = :B
|
39
|
+
cascading_composite_array.should == [ :A, :B ]
|
40
|
+
sub_cascading_composite_array.should == [ :A, :B ]
|
41
|
+
|
42
|
+
sub_cascading_composite_array[ 0 ] = :C
|
43
|
+
cascading_composite_array.should == [ :A, :B ]
|
44
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
45
|
+
|
46
|
+
sub_cascading_composite_array[ 0 ] = :B
|
47
|
+
cascading_composite_array.should == [ :A, :B ]
|
48
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
49
|
+
|
50
|
+
sub_cascading_composite_array[ 2 ] = :C
|
51
|
+
cascading_composite_array.should == [ :A, :B ]
|
52
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
53
|
+
|
54
|
+
cascading_composite_array[ 0 ] = :D
|
55
|
+
cascading_composite_array.should == [ :B, :D ]
|
56
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
############
|
61
|
+
# insert #
|
62
|
+
############
|
63
|
+
|
64
|
+
it 'can insert elements' do
|
65
|
+
|
66
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
67
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
68
|
+
|
69
|
+
cascading_composite_array.insert( 3, :D )
|
70
|
+
cascading_composite_array.should == [ nil, nil, nil, :D ]
|
71
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :D ]
|
72
|
+
|
73
|
+
cascading_composite_array.insert( 1, :B )
|
74
|
+
cascading_composite_array.should == [ nil, nil, nil, :B, :D ]
|
75
|
+
|
76
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :B, :D ]
|
77
|
+
|
78
|
+
cascading_composite_array.insert( 2, :C )
|
79
|
+
cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D ]
|
80
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D ]
|
81
|
+
|
82
|
+
sub_cascading_composite_array.insert( 0, :E )
|
83
|
+
cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D ]
|
84
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D, :E ]
|
85
|
+
|
86
|
+
sub_cascading_composite_array.insert( 4, :F )
|
87
|
+
cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D ]
|
88
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :B, :C, :D, :E, :F ]
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
##########
|
93
|
+
# push #
|
94
|
+
# << #
|
95
|
+
##########
|
96
|
+
|
97
|
+
it 'can add elements' do
|
98
|
+
|
99
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
100
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
101
|
+
|
102
|
+
cascading_composite_array << :A
|
103
|
+
cascading_composite_array.should == [ :A ]
|
104
|
+
sub_cascading_composite_array.should == [ :A ]
|
105
|
+
|
106
|
+
cascading_composite_array << :B
|
107
|
+
cascading_composite_array.should == [ :A, :B ]
|
108
|
+
sub_cascading_composite_array.should == [ :A, :B ]
|
109
|
+
|
110
|
+
sub_cascading_composite_array << :C
|
111
|
+
cascading_composite_array.should == [ :A, :B ]
|
112
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
113
|
+
|
114
|
+
sub_cascading_composite_array << :B
|
115
|
+
cascading_composite_array.should == [ :A, :B ]
|
116
|
+
sub_cascading_composite_array.should == [ :A, :B, :B, :C ]
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
############
|
121
|
+
# concat #
|
122
|
+
# + #
|
123
|
+
############
|
124
|
+
|
125
|
+
it 'can add elements' do
|
126
|
+
|
127
|
+
# NOTE: this breaks + by causing it to modify the array like +=
|
128
|
+
# The alternative was worse.
|
129
|
+
|
130
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
131
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
132
|
+
|
133
|
+
cascading_composite_array.concat( [ :A ] )
|
134
|
+
cascading_composite_array.should == [ :A ]
|
135
|
+
sub_cascading_composite_array.should == [ :A ]
|
136
|
+
|
137
|
+
cascading_composite_array += [ :B ]
|
138
|
+
cascading_composite_array.should == [ :A, :B ]
|
139
|
+
sub_cascading_composite_array.should == [ :A, :B ]
|
140
|
+
|
141
|
+
sub_cascading_composite_array.concat( [ :C ] )
|
142
|
+
cascading_composite_array.should == [ :A, :B ]
|
143
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
144
|
+
|
145
|
+
sub_cascading_composite_array += [ :B ]
|
146
|
+
cascading_composite_array.should == [ :A, :B ]
|
147
|
+
sub_cascading_composite_array.should == [ :A, :B, :B, :C ]
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
####################
|
152
|
+
# delete_objects #
|
153
|
+
####################
|
154
|
+
|
155
|
+
it 'can delete multiple elements' do
|
156
|
+
|
157
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
158
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
159
|
+
|
160
|
+
cascading_composite_array += [ :A, :B ]
|
161
|
+
cascading_composite_array.should == [ :A, :B ]
|
162
|
+
sub_cascading_composite_array.should == [ :A, :B ]
|
163
|
+
|
164
|
+
cascading_composite_array.delete_objects( :A, :B )
|
165
|
+
cascading_composite_array.should == [ ]
|
166
|
+
sub_cascading_composite_array.should == [ ]
|
167
|
+
|
168
|
+
sub_cascading_composite_array += [ :B, :C, :D ]
|
169
|
+
cascading_composite_array.should == [ ]
|
170
|
+
sub_cascading_composite_array.should == [ :B, :C, :D ]
|
171
|
+
|
172
|
+
sub_cascading_composite_array.delete_objects( :C, :B )
|
173
|
+
cascading_composite_array.should == [ ]
|
174
|
+
sub_cascading_composite_array.should == [ :D ]
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
#######
|
179
|
+
# - #
|
180
|
+
#######
|
181
|
+
|
182
|
+
it 'can exclude elements' do
|
183
|
+
|
184
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
185
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
186
|
+
|
187
|
+
cascading_composite_array.push( :A )
|
188
|
+
cascading_composite_array.should == [ :A ]
|
189
|
+
sub_cascading_composite_array.should == [ :A ]
|
190
|
+
|
191
|
+
cascading_composite_array -= [ :A ]
|
192
|
+
cascading_composite_array.should == [ ]
|
193
|
+
sub_cascading_composite_array.should == [ ]
|
194
|
+
|
195
|
+
cascading_composite_array.push( :B )
|
196
|
+
cascading_composite_array.should == [ :B ]
|
197
|
+
sub_cascading_composite_array.should == [ :B ]
|
198
|
+
|
199
|
+
sub_cascading_composite_array.push( :C )
|
200
|
+
cascading_composite_array.should == [ :B ]
|
201
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
202
|
+
|
203
|
+
sub_cascading_composite_array -= [ :B ]
|
204
|
+
cascading_composite_array.should == [ :B ]
|
205
|
+
sub_cascading_composite_array.should == [ :C ]
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
############
|
210
|
+
# delete #
|
211
|
+
############
|
212
|
+
|
213
|
+
it 'can delete elements' do
|
214
|
+
|
215
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
216
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
217
|
+
|
218
|
+
cascading_composite_array.push( :A )
|
219
|
+
cascading_composite_array.should == [ :A ]
|
220
|
+
sub_cascading_composite_array.should == [ :A ]
|
221
|
+
|
222
|
+
cascading_composite_array.delete( :A )
|
223
|
+
cascading_composite_array.should == [ ]
|
224
|
+
sub_cascading_composite_array.should == [ ]
|
225
|
+
|
226
|
+
cascading_composite_array.push( :B )
|
227
|
+
cascading_composite_array.should == [ :B ]
|
228
|
+
sub_cascading_composite_array.should == [ :B ]
|
229
|
+
|
230
|
+
sub_cascading_composite_array.push( :C )
|
231
|
+
cascading_composite_array.should == [ :B ]
|
232
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
233
|
+
|
234
|
+
sub_cascading_composite_array.delete( :B )
|
235
|
+
cascading_composite_array.should == [ :B ]
|
236
|
+
sub_cascading_composite_array.should == [ :C ]
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
###############
|
241
|
+
# delete_at #
|
242
|
+
###############
|
243
|
+
|
244
|
+
it 'can delete by indexes' do
|
245
|
+
|
246
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
247
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
248
|
+
|
249
|
+
cascading_composite_array.push( :A )
|
250
|
+
cascading_composite_array.should == [ :A ]
|
251
|
+
sub_cascading_composite_array.should == [ :A ]
|
252
|
+
|
253
|
+
cascading_composite_array.delete_at( 0 )
|
254
|
+
cascading_composite_array.should == [ ]
|
255
|
+
sub_cascading_composite_array.should == [ ]
|
256
|
+
|
257
|
+
cascading_composite_array.push( :B )
|
258
|
+
cascading_composite_array.should == [ :B ]
|
259
|
+
sub_cascading_composite_array.should == [ :B ]
|
260
|
+
|
261
|
+
sub_cascading_composite_array.push( :C )
|
262
|
+
cascading_composite_array.should == [ :B ]
|
263
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
264
|
+
|
265
|
+
sub_cascading_composite_array.delete_at( 0 )
|
266
|
+
cascading_composite_array.should == [ :B ]
|
267
|
+
sub_cascading_composite_array.should == [ :C ]
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
#######################
|
272
|
+
# delete_at_indexes #
|
273
|
+
#######################
|
274
|
+
|
275
|
+
it 'can delete by indexes' do
|
276
|
+
|
277
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
278
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
279
|
+
|
280
|
+
cascading_composite_array.push( :A, :B, :C )
|
281
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
282
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
283
|
+
|
284
|
+
cascading_composite_array.delete_at_indexes( 0, 1 )
|
285
|
+
cascading_composite_array.should == [ :C ]
|
286
|
+
sub_cascading_composite_array.should == [ :C ]
|
287
|
+
|
288
|
+
sub_cascading_composite_array.push( :C, :B )
|
289
|
+
cascading_composite_array.should == [ :C ]
|
290
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
291
|
+
|
292
|
+
sub_cascading_composite_array.delete_at_indexes( 0, 1, 2 )
|
293
|
+
cascading_composite_array.should == [ :C ]
|
294
|
+
sub_cascading_composite_array.should == [ ]
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
###############
|
299
|
+
# delete_if #
|
300
|
+
###############
|
301
|
+
|
302
|
+
it 'can delete by block' do
|
303
|
+
|
304
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
305
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
306
|
+
|
307
|
+
cascading_composite_array.push( :A, :B, :C )
|
308
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
309
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
310
|
+
cascading_composite_array.delete_if do |object|
|
311
|
+
object != :C
|
312
|
+
end
|
313
|
+
cascading_composite_array.should == [ :C ]
|
314
|
+
sub_cascading_composite_array.should == [ :C ]
|
315
|
+
|
316
|
+
sub_cascading_composite_array.push( :C, :B )
|
317
|
+
cascading_composite_array.should == [ :C ]
|
318
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
319
|
+
sub_cascading_composite_array.delete_if do |object|
|
320
|
+
object != nil
|
321
|
+
end
|
322
|
+
sub_cascading_composite_array.should == [ ]
|
323
|
+
cascading_composite_array.should == [ :C ]
|
324
|
+
|
325
|
+
cascading_composite_array.delete_if.is_a?( Enumerator ).should == true
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
#############
|
330
|
+
# keep_if #
|
331
|
+
#############
|
332
|
+
|
333
|
+
it 'can keep by block' do
|
334
|
+
|
335
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
336
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
337
|
+
|
338
|
+
cascading_composite_array.push( :A, :B, :C )
|
339
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
340
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
341
|
+
cascading_composite_array.keep_if do |object|
|
342
|
+
object == :C
|
343
|
+
end
|
344
|
+
cascading_composite_array.should == [ :C ]
|
345
|
+
sub_cascading_composite_array.should == [ :C ]
|
346
|
+
|
347
|
+
sub_cascading_composite_array.push( :C, :B )
|
348
|
+
cascading_composite_array.should == [ :C ]
|
349
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
350
|
+
sub_cascading_composite_array.keep_if do |object|
|
351
|
+
object == nil
|
352
|
+
end
|
353
|
+
cascading_composite_array.should == [ :C ]
|
354
|
+
sub_cascading_composite_array.should == [ ]
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
##############
|
359
|
+
# compact! #
|
360
|
+
##############
|
361
|
+
|
362
|
+
it 'can compact' do
|
363
|
+
|
364
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
365
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
366
|
+
|
367
|
+
cascading_composite_array.push( :A, nil, :B, nil, :C, nil )
|
368
|
+
cascading_composite_array.should == [ nil, nil, nil, :A, :B, :C ]
|
369
|
+
sub_cascading_composite_array.should == [ nil, nil, nil, :A, :B, :C ]
|
370
|
+
cascading_composite_array.compact!
|
371
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
372
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
373
|
+
|
374
|
+
sub_cascading_composite_array.push( nil, nil, :D )
|
375
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
376
|
+
sub_cascading_composite_array.should == [ nil, nil, :A, :B, :C, :D ]
|
377
|
+
sub_cascading_composite_array.compact!
|
378
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
379
|
+
sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
##############
|
384
|
+
# flatten! #
|
385
|
+
##############
|
386
|
+
|
387
|
+
it 'can flatten' do
|
388
|
+
|
389
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
390
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
391
|
+
|
392
|
+
cascading_composite_array.push( :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] )
|
393
|
+
cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
|
394
|
+
sub_cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
|
395
|
+
cascading_composite_array.flatten!
|
396
|
+
cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
|
397
|
+
sub_cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
|
398
|
+
|
399
|
+
sub_cascading_composite_array.push( [ :F_F, :F_G ], :D, [ :F_H ] )
|
400
|
+
cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
|
401
|
+
sub_cascading_composite_array.should == [ :A, :B, :C, :D, :F_A, :F_B, :F_C, :F_D, :F_E, [ :F_F, :F_G ], [ :F_H ] ]
|
402
|
+
sub_cascading_composite_array.flatten!
|
403
|
+
cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
|
404
|
+
sub_cascading_composite_array.should == [ :A, :B, :C, :D, :F_A, :F_B, :F_C, :F_D, :F_E, :F_F, :F_G, :F_H ]
|
405
|
+
|
406
|
+
end
|
407
|
+
|
408
|
+
#############
|
409
|
+
# reject! #
|
410
|
+
#############
|
411
|
+
|
412
|
+
it 'can reject' do
|
413
|
+
|
414
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
415
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
416
|
+
|
417
|
+
cascading_composite_array.push( :A, :B, :C )
|
418
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
419
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
420
|
+
cascading_composite_array.reject! do |object|
|
421
|
+
object != :C
|
422
|
+
end
|
423
|
+
cascading_composite_array.should == [ :C ]
|
424
|
+
sub_cascading_composite_array.should == [ :C ]
|
425
|
+
|
426
|
+
sub_cascading_composite_array.push( :C, :B )
|
427
|
+
cascading_composite_array.should == [ :C ]
|
428
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
429
|
+
sub_cascading_composite_array.reject! do |object|
|
430
|
+
object != nil
|
431
|
+
end
|
432
|
+
sub_cascading_composite_array.should == [ ]
|
433
|
+
cascading_composite_array.should == [ :C ]
|
434
|
+
|
435
|
+
cascading_composite_array.reject!.is_a?( Enumerator ).should == true
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
#############
|
440
|
+
# replace #
|
441
|
+
#############
|
442
|
+
|
443
|
+
it 'can replace self' do
|
444
|
+
|
445
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
446
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
447
|
+
|
448
|
+
cascading_composite_array.push( :A, :B, :C )
|
449
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
450
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
451
|
+
cascading_composite_array.replace( [ :D, :E, :F ] )
|
452
|
+
cascading_composite_array.should == [ :D, :E, :F ]
|
453
|
+
sub_cascading_composite_array.should == [ :D, :E, :F ]
|
454
|
+
|
455
|
+
cascading_composite_array.should == [ :D, :E, :F ]
|
456
|
+
sub_cascading_composite_array.should == [ :D, :E, :F ]
|
457
|
+
sub_cascading_composite_array.replace( [ :G, :H, :I ] )
|
458
|
+
cascading_composite_array.should == [ :D, :E, :F ]
|
459
|
+
sub_cascading_composite_array.should == [ :G, :H, :I ]
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
##############
|
464
|
+
# reverse! #
|
465
|
+
##############
|
466
|
+
|
467
|
+
it 'can reverse self' do
|
468
|
+
|
469
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
470
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
471
|
+
|
472
|
+
cascading_composite_array.push( :A, :B, :C )
|
473
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
474
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
475
|
+
cascading_composite_array.reverse!
|
476
|
+
cascading_composite_array.should == [ :C, :B, :A ]
|
477
|
+
sub_cascading_composite_array.should == [ :C, :B, :A ]
|
478
|
+
|
479
|
+
cascading_composite_array.should == [ :C, :B, :A ]
|
480
|
+
sub_cascading_composite_array.should == [ :C, :B, :A ]
|
481
|
+
sub_cascading_composite_array.reverse!
|
482
|
+
cascading_composite_array.should == [ :C, :B, :A ]
|
483
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
484
|
+
|
485
|
+
end
|
486
|
+
|
487
|
+
#############
|
488
|
+
# rotate! #
|
489
|
+
#############
|
490
|
+
|
491
|
+
it 'can rotate self' do
|
492
|
+
|
493
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
494
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
495
|
+
|
496
|
+
cascading_composite_array.push( :A, :B, :C )
|
497
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
498
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
499
|
+
|
500
|
+
cascading_composite_array.rotate!
|
501
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
502
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
503
|
+
|
504
|
+
cascading_composite_array.rotate!( -1 )
|
505
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
506
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
507
|
+
|
508
|
+
sub_cascading_composite_array.rotate!( 2 )
|
509
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
510
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
511
|
+
|
512
|
+
end
|
513
|
+
|
514
|
+
#############
|
515
|
+
# select! #
|
516
|
+
#############
|
517
|
+
|
518
|
+
it 'can keep by select' do
|
519
|
+
|
520
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
521
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
522
|
+
|
523
|
+
cascading_composite_array.push( :A, :B, :C )
|
524
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
525
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
526
|
+
cascading_composite_array.select! do |object|
|
527
|
+
object == :C
|
528
|
+
end
|
529
|
+
cascading_composite_array.should == [ :C ]
|
530
|
+
sub_cascading_composite_array.should == [ :C ]
|
531
|
+
|
532
|
+
sub_cascading_composite_array.push( :C, :B )
|
533
|
+
cascading_composite_array.should == [ :C ]
|
534
|
+
sub_cascading_composite_array.should == [ :B, :C, :C ]
|
535
|
+
sub_cascading_composite_array.select! do |object|
|
536
|
+
object == nil
|
537
|
+
end
|
538
|
+
cascading_composite_array.should == [ :C ]
|
539
|
+
sub_cascading_composite_array.should == [ ]
|
540
|
+
|
541
|
+
cascading_composite_array.select!.is_a?( Enumerator ).should == true
|
542
|
+
|
543
|
+
end
|
544
|
+
|
545
|
+
##############
|
546
|
+
# shuffle! #
|
547
|
+
##############
|
548
|
+
|
549
|
+
it 'can shuffle self' do
|
550
|
+
|
551
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
552
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
553
|
+
|
554
|
+
cascading_composite_array.push( :A, :B, :C )
|
555
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
556
|
+
sub_cascading_composite_array.should == cascading_composite_array
|
557
|
+
|
558
|
+
first_shuffle_version = cascading_composite_array.dup
|
559
|
+
cascading_composite_array.shuffle!
|
560
|
+
cascading_composite_array.should == first_shuffle_version
|
561
|
+
sub_cascading_composite_array.should == cascading_composite_array
|
562
|
+
|
563
|
+
first_shuffle_version = sub_cascading_composite_array.dup
|
564
|
+
sub_cascading_composite_array.shuffle!
|
565
|
+
sub_cascading_composite_array.should == first_shuffle_version
|
566
|
+
sub_cascading_composite_array.should == cascading_composite_array
|
567
|
+
|
568
|
+
end
|
569
|
+
|
570
|
+
##############
|
571
|
+
# collect! #
|
572
|
+
# map! #
|
573
|
+
##############
|
574
|
+
|
575
|
+
it 'can replace by collect/map' do
|
576
|
+
|
577
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
578
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
579
|
+
|
580
|
+
cascading_composite_array.push( :A, :B, :C )
|
581
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
582
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
583
|
+
cascading_composite_array.collect! do |object|
|
584
|
+
:C
|
585
|
+
end
|
586
|
+
cascading_composite_array.should == [ :C, :C, :C ]
|
587
|
+
sub_cascading_composite_array.should == [ :C, :C, :C ]
|
588
|
+
|
589
|
+
sub_cascading_composite_array.collect! do |object|
|
590
|
+
:A
|
591
|
+
end
|
592
|
+
cascading_composite_array.should == [ :C, :C, :C ]
|
593
|
+
sub_cascading_composite_array.should == [ :A, :A, :A ]
|
594
|
+
|
595
|
+
cascading_composite_array.collect!.is_a?( Enumerator ).should == true
|
596
|
+
|
597
|
+
end
|
598
|
+
|
599
|
+
###########
|
600
|
+
# sort! #
|
601
|
+
###########
|
602
|
+
|
603
|
+
it 'can replace by collect/map' do
|
604
|
+
|
605
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
606
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
607
|
+
|
608
|
+
cascading_composite_array.push( :A, :B, :C )
|
609
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
610
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
611
|
+
cascading_composite_array.sort! do |a, b|
|
612
|
+
if a < b
|
613
|
+
1
|
614
|
+
elsif a > b
|
615
|
+
-1
|
616
|
+
elsif a == b
|
617
|
+
0
|
618
|
+
end
|
619
|
+
end
|
620
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
621
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
622
|
+
|
623
|
+
sub_cascading_composite_array.sort! do |a, b|
|
624
|
+
if a < b
|
625
|
+
-1
|
626
|
+
elsif a > b
|
627
|
+
1
|
628
|
+
elsif a == b
|
629
|
+
0
|
630
|
+
end
|
631
|
+
end
|
632
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
633
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
634
|
+
|
635
|
+
cascading_composite_array.sort!
|
636
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
637
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
638
|
+
|
639
|
+
end
|
640
|
+
|
641
|
+
##############
|
642
|
+
# sort_by! #
|
643
|
+
##############
|
644
|
+
|
645
|
+
it 'can replace by collect/map' do
|
646
|
+
|
647
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
648
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
649
|
+
|
650
|
+
cascading_composite_array.push( :A, :B, :C )
|
651
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
652
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
653
|
+
cascading_composite_array.sort_by! do |object|
|
654
|
+
case object
|
655
|
+
when :A
|
656
|
+
:B
|
657
|
+
when :B
|
658
|
+
:A
|
659
|
+
when :C
|
660
|
+
:C
|
661
|
+
end
|
662
|
+
end
|
663
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
664
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
665
|
+
|
666
|
+
sub_cascading_composite_array.sort_by! do |object|
|
667
|
+
case object
|
668
|
+
when :A
|
669
|
+
:C
|
670
|
+
when :B
|
671
|
+
:B
|
672
|
+
when :C
|
673
|
+
:A
|
674
|
+
end
|
675
|
+
end
|
676
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
677
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
678
|
+
|
679
|
+
cascading_composite_array.sort_by!.is_a?( Enumerator ).should == true
|
680
|
+
|
681
|
+
end
|
682
|
+
|
683
|
+
###########
|
684
|
+
# uniq! #
|
685
|
+
###########
|
686
|
+
|
687
|
+
it 'can remove non-unique elements' do
|
688
|
+
|
689
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
690
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
691
|
+
|
692
|
+
cascading_composite_array.push( :A, :B, :C, :C, :C, :B, :A )
|
693
|
+
cascading_composite_array.should == [ :A, :A, :B, :B, :C, :C, :C ]
|
694
|
+
sub_cascading_composite_array.should == [ :A, :A, :B, :B, :C, :C, :C ]
|
695
|
+
cascading_composite_array.uniq!
|
696
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
697
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
698
|
+
|
699
|
+
sub_cascading_composite_array.push( :C, :B )
|
700
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
701
|
+
sub_cascading_composite_array.should == [ :A, :B, :B, :C, :C ]
|
702
|
+
sub_cascading_composite_array.uniq!
|
703
|
+
cascading_composite_array.should == [ :A, :B, :C ]
|
704
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
705
|
+
|
706
|
+
end
|
707
|
+
|
708
|
+
#############
|
709
|
+
# unshift #
|
710
|
+
#############
|
711
|
+
|
712
|
+
it 'can unshift onto the first element' do
|
713
|
+
|
714
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
715
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
716
|
+
|
717
|
+
cascading_composite_array += :A
|
718
|
+
cascading_composite_array.should == [ :A ]
|
719
|
+
sub_cascading_composite_array.should == [ :A ]
|
720
|
+
|
721
|
+
cascading_composite_array.unshift( :B )
|
722
|
+
cascading_composite_array.should == [ :A, :B ]
|
723
|
+
sub_cascading_composite_array.should == [ :A, :B ]
|
724
|
+
|
725
|
+
sub_cascading_composite_array.unshift( :C )
|
726
|
+
cascading_composite_array.should == [ :A, :B ]
|
727
|
+
sub_cascading_composite_array.should == [ :A, :B, :C ]
|
728
|
+
|
729
|
+
end
|
730
|
+
|
731
|
+
#########
|
732
|
+
# pop #
|
733
|
+
#########
|
734
|
+
|
735
|
+
it 'can pop the final element' do
|
736
|
+
|
737
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
738
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
739
|
+
|
740
|
+
cascading_composite_array += :A
|
741
|
+
cascading_composite_array.should == [ :A ]
|
742
|
+
sub_cascading_composite_array.should == [ :A ]
|
743
|
+
|
744
|
+
cascading_composite_array.pop.should == :A
|
745
|
+
cascading_composite_array.should == [ ]
|
746
|
+
sub_cascading_composite_array.should == [ ]
|
747
|
+
|
748
|
+
cascading_composite_array += :B
|
749
|
+
cascading_composite_array.should == [ :B ]
|
750
|
+
sub_cascading_composite_array.should == [ :B ]
|
751
|
+
|
752
|
+
sub_cascading_composite_array += :C
|
753
|
+
cascading_composite_array.should == [ :B ]
|
754
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
755
|
+
sub_cascading_composite_array.pop.should == :C
|
756
|
+
cascading_composite_array.should == [ :B ]
|
757
|
+
sub_cascading_composite_array.should == [ :B ]
|
758
|
+
|
759
|
+
end
|
760
|
+
|
761
|
+
###########
|
762
|
+
# shift #
|
763
|
+
###########
|
764
|
+
|
765
|
+
it 'can shift the first element' do
|
766
|
+
|
767
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
768
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
769
|
+
|
770
|
+
cascading_composite_array += :A
|
771
|
+
cascading_composite_array.should == [ :A ]
|
772
|
+
sub_cascading_composite_array.should == [ :A ]
|
773
|
+
|
774
|
+
cascading_composite_array.shift.should == :A
|
775
|
+
cascading_composite_array.should == [ ]
|
776
|
+
sub_cascading_composite_array.should == [ ]
|
777
|
+
|
778
|
+
cascading_composite_array += :B
|
779
|
+
cascading_composite_array.should == [ :B ]
|
780
|
+
sub_cascading_composite_array.should == [ :B ]
|
781
|
+
|
782
|
+
sub_cascading_composite_array += :C
|
783
|
+
cascading_composite_array.should == [ :B ]
|
784
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
785
|
+
sub_cascading_composite_array.shift.should == :B
|
786
|
+
cascading_composite_array.should == [ :B ]
|
787
|
+
sub_cascading_composite_array.should == [ :C ]
|
788
|
+
|
789
|
+
end
|
790
|
+
|
791
|
+
############
|
792
|
+
# slice! #
|
793
|
+
############
|
794
|
+
|
795
|
+
it 'can slice elements' do
|
796
|
+
|
797
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
798
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
799
|
+
|
800
|
+
cascading_composite_array += :A
|
801
|
+
cascading_composite_array.should == [ :A ]
|
802
|
+
sub_cascading_composite_array.should == [ :A ]
|
803
|
+
|
804
|
+
cascading_composite_array.slice!( 0, 1 ).should == [ :A ]
|
805
|
+
cascading_composite_array.should == [ ]
|
806
|
+
sub_cascading_composite_array.should == [ ]
|
807
|
+
|
808
|
+
cascading_composite_array += :B
|
809
|
+
cascading_composite_array.should == [ :B ]
|
810
|
+
sub_cascading_composite_array.should == [ :B ]
|
811
|
+
|
812
|
+
sub_cascading_composite_array += :C
|
813
|
+
cascading_composite_array.should == [ :B ]
|
814
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
815
|
+
|
816
|
+
sub_cascading_composite_array.slice!( 0, 1 ).should == [ :B ]
|
817
|
+
cascading_composite_array.should == [ :B ]
|
818
|
+
sub_cascading_composite_array.should == [ :C ]
|
819
|
+
|
820
|
+
end
|
821
|
+
|
822
|
+
###########
|
823
|
+
# clear #
|
824
|
+
###########
|
825
|
+
|
826
|
+
it 'can clear, causing present elements to be excluded' do
|
827
|
+
|
828
|
+
cascading_composite_array = ::Array::Sorted::Compositing.new
|
829
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing.new( cascading_composite_array )
|
830
|
+
|
831
|
+
cascading_composite_array += :A
|
832
|
+
cascading_composite_array.should == [ :A ]
|
833
|
+
sub_cascading_composite_array.should == [ :A ]
|
834
|
+
|
835
|
+
cascading_composite_array.clear
|
836
|
+
cascading_composite_array.should == [ ]
|
837
|
+
sub_cascading_composite_array.should == [ ]
|
838
|
+
|
839
|
+
cascading_composite_array += :B
|
840
|
+
cascading_composite_array.should == [ :B ]
|
841
|
+
sub_cascading_composite_array.should == [ :B ]
|
842
|
+
|
843
|
+
sub_cascading_composite_array += :C
|
844
|
+
cascading_composite_array.should == [ :B ]
|
845
|
+
sub_cascading_composite_array.should == [ :B, :C ]
|
846
|
+
|
847
|
+
sub_cascading_composite_array.clear
|
848
|
+
cascading_composite_array.should == [ :B ]
|
849
|
+
sub_cascading_composite_array.should == [ ]
|
850
|
+
|
851
|
+
end
|
852
|
+
|
853
|
+
##################
|
854
|
+
# pre_set_hook #
|
855
|
+
##################
|
856
|
+
|
857
|
+
it 'has a hook that is called before setting a value; return value is used in place of object' do
|
858
|
+
|
859
|
+
class ::Array::Sorted::Compositing::SubMockPreSet < ::Array::Sorted::Compositing
|
860
|
+
|
861
|
+
def pre_set_hook( index, object, is_insert = false )
|
862
|
+
return :some_other_value
|
863
|
+
end
|
864
|
+
|
865
|
+
end
|
866
|
+
|
867
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPreSet.new
|
868
|
+
|
869
|
+
cascading_composite_array.push( :some_value )
|
870
|
+
|
871
|
+
cascading_composite_array.should == [ :some_other_value ]
|
872
|
+
|
873
|
+
end
|
874
|
+
|
875
|
+
###################
|
876
|
+
# post_set_hook #
|
877
|
+
###################
|
878
|
+
|
879
|
+
it 'has a hook that is called after setting a value' do
|
880
|
+
|
881
|
+
class ::Array::Sorted::Compositing::SubMockPostSet < ::Array::Sorted::Compositing
|
882
|
+
|
883
|
+
def post_set_hook( index, object, is_insert = false )
|
884
|
+
return :some_other_value
|
885
|
+
end
|
886
|
+
|
887
|
+
end
|
888
|
+
|
889
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPostSet.new
|
890
|
+
|
891
|
+
cascading_composite_array.push( :some_value ).should == [ :some_other_value ]
|
892
|
+
|
893
|
+
cascading_composite_array.should == [ :some_value ]
|
894
|
+
|
895
|
+
end
|
896
|
+
|
897
|
+
##################
|
898
|
+
# pre_get_hook #
|
899
|
+
##################
|
900
|
+
|
901
|
+
it 'has a hook that is called before getting a value; if return value is false, get does not occur' do
|
902
|
+
|
903
|
+
class ::Array::Sorted::Compositing::SubMockPreGet < ::Array::Sorted::Compositing
|
904
|
+
|
905
|
+
def pre_get_hook( index )
|
906
|
+
return false
|
907
|
+
end
|
908
|
+
|
909
|
+
end
|
910
|
+
|
911
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPreGet.new
|
912
|
+
|
913
|
+
cascading_composite_array.push( :some_value )
|
914
|
+
cascading_composite_array[ 0 ].should == nil
|
915
|
+
|
916
|
+
cascading_composite_array.should == [ :some_value ]
|
917
|
+
|
918
|
+
end
|
919
|
+
|
920
|
+
###################
|
921
|
+
# post_get_hook #
|
922
|
+
###################
|
923
|
+
|
924
|
+
it 'has a hook that is called after getting a value' do
|
925
|
+
|
926
|
+
class ::Array::Sorted::Compositing::SubMockPostGet < ::Array::Sorted::Compositing
|
927
|
+
|
928
|
+
def post_get_hook( index, object )
|
929
|
+
return :some_other_value
|
930
|
+
end
|
931
|
+
|
932
|
+
end
|
933
|
+
|
934
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPostGet.new
|
935
|
+
|
936
|
+
cascading_composite_array.push( :some_value )
|
937
|
+
cascading_composite_array[ 0 ].should == :some_other_value
|
938
|
+
|
939
|
+
cascading_composite_array.should == [ :some_value ]
|
940
|
+
|
941
|
+
end
|
942
|
+
|
943
|
+
#####################
|
944
|
+
# pre_delete_hook #
|
945
|
+
#####################
|
946
|
+
|
947
|
+
it 'has a hook that is called before deleting an index; if return value is false, delete does not occur' do
|
948
|
+
|
949
|
+
class ::Array::Sorted::Compositing::SubMockPreDelete < ::Array::Sorted::Compositing
|
950
|
+
|
951
|
+
def pre_delete_hook( index )
|
952
|
+
return false
|
953
|
+
end
|
954
|
+
|
955
|
+
end
|
956
|
+
|
957
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPreDelete.new
|
958
|
+
|
959
|
+
cascading_composite_array.push( :some_value )
|
960
|
+
cascading_composite_array.delete_at( 0 )
|
961
|
+
|
962
|
+
cascading_composite_array.should == [ :some_value ]
|
963
|
+
|
964
|
+
end
|
965
|
+
|
966
|
+
######################
|
967
|
+
# post_delete_hook #
|
968
|
+
######################
|
969
|
+
|
970
|
+
it 'has a hook that is called after deleting an index' do
|
971
|
+
|
972
|
+
class ::Array::Sorted::Compositing::SubMockPostDelete < ::Array::Sorted::Compositing
|
973
|
+
|
974
|
+
def post_delete_hook( index, object )
|
975
|
+
return :some_other_value
|
976
|
+
end
|
977
|
+
|
978
|
+
end
|
979
|
+
|
980
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockPostDelete.new
|
981
|
+
|
982
|
+
cascading_composite_array.push( :some_value )
|
983
|
+
cascading_composite_array.delete_at( 0 ).should == :some_other_value
|
984
|
+
|
985
|
+
cascading_composite_array.should == [ ]
|
986
|
+
|
987
|
+
end
|
988
|
+
|
989
|
+
########################
|
990
|
+
# child_pre_set_hook #
|
991
|
+
########################
|
992
|
+
|
993
|
+
it 'has a hook that is called before setting a value that has been passed by a parent; return value is used in place of object' do
|
994
|
+
|
995
|
+
class ::Array::Sorted::Compositing::SubMockChildPreSet < ::Array::Sorted::Compositing
|
996
|
+
|
997
|
+
def child_pre_set_hook( index, object, is_insert = false )
|
998
|
+
return :some_other_value
|
999
|
+
end
|
1000
|
+
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPreSet.new
|
1004
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPreSet.new( cascading_composite_array )
|
1005
|
+
cascading_composite_array.push( :some_value )
|
1006
|
+
|
1007
|
+
sub_cascading_composite_array.should == [ :some_other_value ]
|
1008
|
+
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
#########################
|
1012
|
+
# child_post_set_hook #
|
1013
|
+
#########################
|
1014
|
+
|
1015
|
+
it 'has a hook that is called after setting a value passed by a parent' do
|
1016
|
+
|
1017
|
+
class ::Array::Sorted::Compositing::SubMockChildPostSet < ::Array::Sorted::Compositing
|
1018
|
+
|
1019
|
+
def child_post_set_hook( index, object, is_insert = false )
|
1020
|
+
push( :some_other_value )
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPostSet.new
|
1026
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPostSet.new( cascading_composite_array )
|
1027
|
+
cascading_composite_array.push( :some_value )
|
1028
|
+
|
1029
|
+
cascading_composite_array.should == [ :some_value ]
|
1030
|
+
sub_cascading_composite_array.should == [ :some_other_value, :some_value ]
|
1031
|
+
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
###########################
|
1035
|
+
# child_pre_delete_hook #
|
1036
|
+
###########################
|
1037
|
+
|
1038
|
+
it 'has a hook that is called before deleting an index that has been passed by a parent; if return value is false, delete does not occur' do
|
1039
|
+
|
1040
|
+
class ::Array::Sorted::Compositing::SubMockChildPreDelete < ::Array::Sorted::Compositing
|
1041
|
+
|
1042
|
+
def child_pre_delete_hook( index )
|
1043
|
+
false
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPreDelete.new
|
1049
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPreDelete.new( cascading_composite_array )
|
1050
|
+
cascading_composite_array.push( :some_value )
|
1051
|
+
cascading_composite_array.delete( :some_value )
|
1052
|
+
|
1053
|
+
cascading_composite_array.should == [ ]
|
1054
|
+
sub_cascading_composite_array.should == [ :some_value ]
|
1055
|
+
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
############################
|
1059
|
+
# child_post_delete_hook #
|
1060
|
+
############################
|
1061
|
+
|
1062
|
+
it 'has a hook that is called after deleting an index passed by a parent' do
|
1063
|
+
|
1064
|
+
class ::Array::Sorted::Compositing::SubMockChildPostDelete < ::Array::Sorted::Compositing
|
1065
|
+
|
1066
|
+
def child_post_delete_hook( index, object )
|
1067
|
+
delete( :some_other_value )
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPostDelete.new
|
1073
|
+
sub_cascading_composite_array = ::Array::Sorted::Compositing::SubMockChildPostDelete.new( cascading_composite_array )
|
1074
|
+
cascading_composite_array.push( :some_value )
|
1075
|
+
sub_cascading_composite_array.push( :some_other_value )
|
1076
|
+
cascading_composite_array.delete( :some_value )
|
1077
|
+
|
1078
|
+
cascading_composite_array.should == [ ]
|
1079
|
+
sub_cascading_composite_array.should == [ ]
|
1080
|
+
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array-sorted-compositing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Asher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: array-compositing
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: array-sorted
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: An implementation of Array that permits chaining, where children inherit
|
47
|
+
changes to parent and where parent settings can be overridden in children, and that
|
48
|
+
retains sorted order.
|
49
|
+
email: asher@ridiculouspower.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/array/hooked/compositing/sorted.rb
|
55
|
+
- lib/array/sorted/compositing/array_interface.rb
|
56
|
+
- lib/array/sorted/compositing.rb
|
57
|
+
- lib/array/sorted/namespaces.rb
|
58
|
+
- lib/array/sorted/requires.rb
|
59
|
+
- lib/array-sorted-compositing.rb
|
60
|
+
- spec/array/sorted/compositing_spec.rb
|
61
|
+
- README.md
|
62
|
+
- README.rdoc
|
63
|
+
- CHANGELOG.rdoc
|
64
|
+
homepage: http://rubygems.org/gems/array-sorted-compositing
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project: array-sorted-compositing
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Provides Array::Sorted::Compositing.
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|