merge_enum 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/README.md +3 -1
- data/lib/merge_enum/merge_enumerable.rb +41 -14
- data/lib/merge_enum/version.rb +1 -1
- data/merge_enum.gemspec +6 -1
- data/spec/merge_enum/merge_enumerable_spec.rb +352 -100
- data/spec/spec_helper.rb +27 -1
- metadata +52 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96107e05d17a2500c015995a885805dee8f73201
|
4
|
+
data.tar.gz: 754eb0bb61e65a5d7310470a3886d0fee53a8b50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4f49e52cc5aba2650d7d59f78052b06ba1af8e0e4add8671903d840af01aecb3315879a197cee4f7cee78a17bcc0cc7f0f7e5d3489806db53c37e05bc935e3
|
7
|
+
data.tar.gz: 629aeff7a46a81ac042c58312a6fef454d29f265eef485d92ea22125f2145225c89a42ae319d935eb5ac1563ece08b71b9baee1a5c4fcdd075d0af174675a410
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# MergeEnum
|
2
|
-
###### ver 0.
|
2
|
+
###### ver 0.7.0
|
3
3
|
|
4
4
|
複数のEnumerale(*1)を連結(合成)するEnumerableです。
|
5
5
|
要素が必要になった時点で追加するように動作します。
|
@@ -91,6 +91,8 @@ Or install it yourself as:
|
|
91
91
|
- `:first` : `Integer`: 要素を取得する最大サイズ
|
92
92
|
- `:compact` : `Proc|bool`: nilを判定して除去する
|
93
93
|
- `:select` : `Proc`: nil,falseを返す要素を除去する
|
94
|
+
- `:map` : `Proc`: 要素を変換する
|
95
|
+
- `:cache` : `bool`: 要素をキャッシュする
|
94
96
|
|
95
97
|
* `Enumerable#merge_enum(enum_2, enum_3, ... , options = {})`
|
96
98
|
レシーバ自身を`enum_1`として、`MergeEnumerable.new(enum_1, enum_2, enum_3, ... , options)`を返します
|
@@ -28,17 +28,22 @@ module MergeEnum
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# options
|
31
|
-
opt_fst = @options
|
32
|
-
opt_fst = opt_fst.to_i if opt_fst
|
31
|
+
opt_fst = option_first @options
|
33
32
|
(opt_proc, _proc) = merge_options_proc @options
|
34
|
-
opt_map = map_proc @options
|
33
|
+
(opt_map, _map) = map_proc @options
|
34
|
+
opt_fill = @options[:fill]
|
35
35
|
|
36
36
|
# local variables
|
37
37
|
cnt = 0
|
38
38
|
fst = nil
|
39
39
|
cache = [] if opt_cache
|
40
40
|
|
41
|
-
|
41
|
+
cs = if opt_fst and opt_fill
|
42
|
+
@collections + [opt_fill]
|
43
|
+
else
|
44
|
+
@collections
|
45
|
+
end
|
46
|
+
cs.each do |c|
|
42
47
|
if opt_fst
|
43
48
|
fst = opt_fst - cnt
|
44
49
|
break if fst <= 0
|
@@ -69,8 +74,8 @@ module MergeEnum
|
|
69
74
|
c = c.first fst unless called_first or _proc
|
70
75
|
_cnt = 0
|
71
76
|
c.each do |e|
|
72
|
-
next if _proc and not opt_proc.call
|
73
|
-
e = opt_map.call
|
77
|
+
next if _proc and not opt_proc.call e, cnt
|
78
|
+
e = opt_map.call e, cnt if _map
|
74
79
|
block.call e
|
75
80
|
cache.push e if cache
|
76
81
|
cnt += 1
|
@@ -80,8 +85,8 @@ module MergeEnum
|
|
80
85
|
else
|
81
86
|
# without first option
|
82
87
|
c.each do |e|
|
83
|
-
next if _proc and not opt_proc.call
|
84
|
-
e = opt_map.call
|
88
|
+
next if _proc and not opt_proc.call e, cnt
|
89
|
+
e = opt_map.call e, cnt if _map
|
85
90
|
block.call e
|
86
91
|
cache.push e if cache
|
87
92
|
cnt += 1
|
@@ -96,6 +101,23 @@ module MergeEnum
|
|
96
101
|
|
97
102
|
private
|
98
103
|
|
104
|
+
def option_first options
|
105
|
+
opt_fst = options[:first]
|
106
|
+
if opt_fst
|
107
|
+
if opt_fst.is_a? Proc
|
108
|
+
arity = opt_fst.arity.abs
|
109
|
+
case arity
|
110
|
+
when 0
|
111
|
+
opt_fst = opt_fst.call
|
112
|
+
else
|
113
|
+
opt_fst = opt_fst.call *Array.new(arity, nil)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
opt_fst = opt_fst.to_i
|
117
|
+
end
|
118
|
+
opt_fst
|
119
|
+
end
|
120
|
+
|
99
121
|
def merge_options_proc options
|
100
122
|
opts = []
|
101
123
|
|
@@ -151,19 +173,20 @@ module MergeEnum
|
|
151
173
|
unless opt_map.is_a? Proc
|
152
174
|
raise ":map is must be a Proc"
|
153
175
|
end
|
154
|
-
|
176
|
+
arity = opt_map.arity.abs
|
177
|
+
case arity
|
155
178
|
when 0
|
156
|
-
-> (e, i) { opt_map.call }
|
179
|
+
[-> (e, i) { opt_map.call }, true]
|
157
180
|
when 1
|
158
|
-
-> (e, i) { opt_map.call e }
|
181
|
+
[-> (e, i) { opt_map.call e }, true]
|
159
182
|
when 2
|
160
|
-
opt_map
|
183
|
+
[opt_map, true]
|
161
184
|
else
|
162
185
|
args = Array.new arity - 2, nil
|
163
|
-
-> (e, i) { opt_map.call e, i, *args }
|
186
|
+
[-> (e, i) { opt_map.call e, i, *args }, true]
|
164
187
|
end
|
165
188
|
else
|
166
|
-
-> (e, i) { e }
|
189
|
+
[-> (e, i) { e }, false]
|
167
190
|
end
|
168
191
|
end
|
169
192
|
|
@@ -179,19 +202,23 @@ module MergeEnum
|
|
179
202
|
end
|
180
203
|
|
181
204
|
def merge_options opts
|
205
|
+
raise "opts must be a Hash" if opts and not opts.is_a? Hash
|
182
206
|
self.class.new *@collections, (@options.merge opts || {})
|
183
207
|
end
|
184
208
|
|
185
209
|
def merge_options! opts
|
210
|
+
raise "opts must be a Hash" if opts and not opts.is_a? Hash
|
186
211
|
@options.merge! opts || {}
|
187
212
|
self
|
188
213
|
end
|
189
214
|
|
190
215
|
def replace_options opts
|
216
|
+
raise "opts must be a Hash" if opts and not opts.is_a? Hash
|
191
217
|
self.class.new *@collections, opts || {}
|
192
218
|
end
|
193
219
|
|
194
220
|
def replace_options! opts
|
221
|
+
raise "opts must be a Hash" if opts and not opts.is_a? Hash
|
195
222
|
@options = opts || {}
|
196
223
|
self
|
197
224
|
end
|
data/lib/merge_enum/version.rb
CHANGED
data/merge_enum.gemspec
CHANGED
@@ -19,5 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.rc1'
|
25
|
+
spec.add_development_dependency 'simplecov', "~> 0"
|
26
|
+
|
27
|
+
spec.add_development_dependency 'rspec_term', '~> 0.3', '>= 0.3.0'
|
23
28
|
end
|
@@ -67,13 +67,8 @@ describe MergeEnum::MergeEnumerable do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
test_error self, :enum, line: __LINE__
|
73
|
-
end
|
74
|
-
|
75
|
-
["hoge", "foo", "bar"].each do |val|
|
76
|
-
describe ".new '#{val}'" do
|
70
|
+
[nil, "hoge", "foo", "bar"].each do |val|
|
71
|
+
describe ".new #{val.inspect}" do
|
77
72
|
let(:enum) { Target.new val }
|
78
73
|
test_error self, :enum, line: __LINE__
|
79
74
|
end
|
@@ -104,7 +99,7 @@ describe MergeEnum::MergeEnumerable do
|
|
104
99
|
|
105
100
|
context "<positive>" do
|
106
101
|
[1, 2, 50].each do |val|
|
107
|
-
describe "#{val}" do
|
102
|
+
describe "#{val.inspect}" do
|
108
103
|
let(:first) { val }
|
109
104
|
test_empty self, :enum, line: __LINE__
|
110
105
|
end
|
@@ -113,7 +108,7 @@ describe MergeEnum::MergeEnumerable do
|
|
113
108
|
|
114
109
|
context "<negative>" do
|
115
110
|
[-1, -2, -50].each do |val|
|
116
|
-
describe "#{val}" do
|
111
|
+
describe "#{val.inspect}" do
|
117
112
|
let(:first) { val }
|
118
113
|
test_empty self, :enum, line: __LINE__
|
119
114
|
end
|
@@ -137,7 +132,7 @@ describe MergeEnum::MergeEnumerable do
|
|
137
132
|
|
138
133
|
context "<illegal>" do
|
139
134
|
["hoge", "foo", "bar"].each do |val|
|
140
|
-
describe "
|
135
|
+
describe "#{val.inspect}" do
|
141
136
|
let(:first) { val }
|
142
137
|
test_empty self, :enum, line: __LINE__
|
143
138
|
end
|
@@ -222,7 +217,7 @@ describe MergeEnum::MergeEnumerable do
|
|
222
217
|
|
223
218
|
context "<positive>" do
|
224
219
|
[1, 2, 50].each do |val|
|
225
|
-
describe "#{val}" do
|
220
|
+
describe "#{val.inspect}" do
|
226
221
|
let(:first) { val }
|
227
222
|
test_empty self, :enum, line: __LINE__
|
228
223
|
end
|
@@ -231,7 +226,7 @@ describe MergeEnum::MergeEnumerable do
|
|
231
226
|
|
232
227
|
context "<negative>" do
|
233
228
|
[-1, -2, -50].each do |val|
|
234
|
-
describe "#{val}" do
|
229
|
+
describe "#{val.inspect}" do
|
235
230
|
let(:first) { val }
|
236
231
|
test_empty self, :enum, line: __LINE__
|
237
232
|
end
|
@@ -255,7 +250,7 @@ describe MergeEnum::MergeEnumerable do
|
|
255
250
|
|
256
251
|
context "<illegal>" do
|
257
252
|
["hoge", "foo", "bar"].each do |val|
|
258
|
-
describe "
|
253
|
+
describe "#{val.inspect}" do
|
259
254
|
let(:first) { val }
|
260
255
|
test_empty self, :enum, line: __LINE__
|
261
256
|
end
|
@@ -329,6 +324,78 @@ describe MergeEnum::MergeEnumerable do
|
|
329
324
|
let(:ary) { 0...100 }
|
330
325
|
test_all self, :enum, 0...100, line: __LINE__
|
331
326
|
end
|
327
|
+
|
328
|
+
describe "Proc.new { 0...100 }" do
|
329
|
+
let(:ary) {
|
330
|
+
ary = Proc.new { 0...100 }
|
331
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
332
|
+
ary
|
333
|
+
}
|
334
|
+
test_all self, :enum, 0...100, line: __LINE__
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "Proc.new { |e| 0...100 }" do
|
338
|
+
let(:ary) {
|
339
|
+
ary = Proc.new { |e| 0...100 }
|
340
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
341
|
+
ary
|
342
|
+
}
|
343
|
+
test_all self, :enum, 0...100, line: __LINE__
|
344
|
+
end
|
345
|
+
|
346
|
+
describe "Proc.new { |e, i| 0...100 }" do
|
347
|
+
let(:ary) {
|
348
|
+
ary = Proc.new { |e, i| 0...100 }
|
349
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
350
|
+
ary
|
351
|
+
}
|
352
|
+
test_all self, :enum, 0...100, line: __LINE__
|
353
|
+
end
|
354
|
+
|
355
|
+
describe "Proc.new { |e, i, x, y, z| 0...100 }" do
|
356
|
+
let(:ary) {
|
357
|
+
ary = Proc.new { |e, i, x, y, z| 0...100 }
|
358
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
359
|
+
ary
|
360
|
+
}
|
361
|
+
test_all self, :enum, 0...100, line: __LINE__
|
362
|
+
end
|
363
|
+
|
364
|
+
describe "-> { 0...100 }" do
|
365
|
+
let(:ary) {
|
366
|
+
ary = -> { 0...100 }
|
367
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
368
|
+
ary
|
369
|
+
}
|
370
|
+
test_all self, :enum, 0...100, line: __LINE__
|
371
|
+
end
|
372
|
+
|
373
|
+
describe "-> { |e| 0...100 }" do
|
374
|
+
let(:ary) {
|
375
|
+
ary = -> (c) { 0...100 }
|
376
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
377
|
+
ary
|
378
|
+
}
|
379
|
+
test_all self, :enum, 0...100, line: __LINE__
|
380
|
+
end
|
381
|
+
|
382
|
+
describe "-> (e, i) { 0...100 }" do
|
383
|
+
let(:ary) {
|
384
|
+
ary = -> (e, i) { 0...100 }
|
385
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
386
|
+
ary
|
387
|
+
}
|
388
|
+
test_all self, :enum, 0...100, line: __LINE__
|
389
|
+
end
|
390
|
+
|
391
|
+
describe "-> (e, i, x, y, z) { 0...100 }" do
|
392
|
+
let(:ary) {
|
393
|
+
ary = -> (e, i, x, y, z) { 0...100 }
|
394
|
+
allow(ary).to receive(:call).once.and_return 0...100
|
395
|
+
ary
|
396
|
+
}
|
397
|
+
test_all self, :enum, 0...100, line: __LINE__
|
398
|
+
end
|
332
399
|
end
|
333
400
|
|
334
401
|
describe ".new" do
|
@@ -403,6 +470,16 @@ describe MergeEnum::MergeEnumerable do
|
|
403
470
|
test_all self, :enum, (31...100).step(2), line: __LINE__
|
404
471
|
end
|
405
472
|
|
473
|
+
describe "Proc.new { |e, i| e.nil? or e < 30 }" do
|
474
|
+
let(:compact) { Proc.new { |e, i| e.nil? or e < 30 } }
|
475
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
476
|
+
end
|
477
|
+
|
478
|
+
describe "Proc.new { |e, i, x, y, z| e.nil? or e < 30 }" do
|
479
|
+
let(:compact) { Proc.new { |e, i, x, y, z| e.nil? or e < 30 } }
|
480
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
481
|
+
end
|
482
|
+
|
406
483
|
describe "-> { true }" do
|
407
484
|
let(:compact) { -> { true } }
|
408
485
|
test_all self, :enum, [], line: __LINE__
|
@@ -422,6 +499,16 @@ describe MergeEnum::MergeEnumerable do
|
|
422
499
|
let(:compact) { -> (e) { e.nil? or e < 30 } }
|
423
500
|
test_all self, :enum, (31...100).step(2), line: __LINE__
|
424
501
|
end
|
502
|
+
|
503
|
+
describe "-> (e, i) { e.nil? or e < 30 }" do
|
504
|
+
let(:compact) { -> (e, i) { e.nil? or e < 30 } }
|
505
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
506
|
+
end
|
507
|
+
|
508
|
+
describe "-> (e, i, x, y, z) { e.nil? or e < 30 }" do
|
509
|
+
let(:compact) { -> (e, i, x, y, z) { e.nil? or e < 30 } }
|
510
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
511
|
+
end
|
425
512
|
end
|
426
513
|
end
|
427
514
|
end
|
@@ -482,6 +569,16 @@ describe MergeEnum::MergeEnumerable do
|
|
482
569
|
test_all self, :enum, (1...30).step(2), line: __LINE__
|
483
570
|
end
|
484
571
|
|
572
|
+
describe "Proc.new { |e, i| not e.nil? and e < 30 }" do
|
573
|
+
let(:select) { Proc.new { |e, i| not e.nil? and e < 30 } }
|
574
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
575
|
+
end
|
576
|
+
|
577
|
+
describe "Proc.new { |e, i, x, y, z| not e.nil? and e < 30 }" do
|
578
|
+
let(:select) { Proc.new { |e, i, x, y, z| not e.nil? and e < 30 } }
|
579
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
580
|
+
end
|
581
|
+
|
485
582
|
describe "-> { true }" do
|
486
583
|
let(:select) { -> { true } }
|
487
584
|
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
@@ -501,6 +598,16 @@ describe MergeEnum::MergeEnumerable do
|
|
501
598
|
let(:select) { -> (e) { not e.nil? and e < 30 } }
|
502
599
|
test_all self, :enum, (1...30).step(2), line: __LINE__
|
503
600
|
end
|
601
|
+
|
602
|
+
describe "-> (e, i) { not e.nil? and e < 30 }" do
|
603
|
+
let(:select) { -> (e, i) { not e.nil? and e < 30 } }
|
604
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
605
|
+
end
|
606
|
+
|
607
|
+
describe "-> (e, i, x, y, z) { not e.nil? and e < 30 }" do
|
608
|
+
let(:select) { -> (e, i, x, y, z) { not e.nil? and e < 30 } }
|
609
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
610
|
+
end
|
504
611
|
end
|
505
612
|
end
|
506
613
|
end
|
@@ -548,6 +655,92 @@ describe MergeEnum::MergeEnumerable do
|
|
548
655
|
end
|
549
656
|
end
|
550
657
|
|
658
|
+
describe ".new" do
|
659
|
+
let(:enum) { Target.new ary, fill: fill }
|
660
|
+
describe "0...100," do
|
661
|
+
let(:ary) { 0...100 }
|
662
|
+
|
663
|
+
describe "fill:" do
|
664
|
+
describe "nil" do
|
665
|
+
let(:fill) { nil }
|
666
|
+
|
667
|
+
test_all self, :enum, 0...100, line: __LINE__
|
668
|
+
end
|
669
|
+
|
670
|
+
describe "true" do
|
671
|
+
let(:fill) { true }
|
672
|
+
|
673
|
+
test_all self, :enum, 0...100, line: __LINE__
|
674
|
+
end
|
675
|
+
|
676
|
+
describe "false" do
|
677
|
+
let(:fill) { false }
|
678
|
+
|
679
|
+
test_all self, :enum, 0...100, line: __LINE__
|
680
|
+
end
|
681
|
+
end
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
describe ".new" do
|
686
|
+
let(:enum) { Target.new ary, first: first, fill: fill }
|
687
|
+
describe "0...100," do
|
688
|
+
let(:ary) { 0...100 }
|
689
|
+
describe "first:" do
|
690
|
+
describe "150," do
|
691
|
+
let(:first) { 150 }
|
692
|
+
|
693
|
+
[nil, "hoge", "foo", "bar"].each do |val|
|
694
|
+
describe "fill: #{val.inspect}" do
|
695
|
+
let(:fill) { val }
|
696
|
+
test_interrupt self, :enum, (0...100).to_a, line: __LINE__
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
describe "fill:" do
|
701
|
+
describe "200...300" do
|
702
|
+
let(:fill) { 200...300 }
|
703
|
+
|
704
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
705
|
+
end
|
706
|
+
|
707
|
+
describe "Proc.new { 200...300 }" do
|
708
|
+
let(:fill) { Proc.new { 200...300 } }
|
709
|
+
|
710
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
711
|
+
end
|
712
|
+
|
713
|
+
describe "Proc.new { |c| 200...300 }" do
|
714
|
+
let(:fill) {
|
715
|
+
_proc = Proc.new { |c| 200...300 }
|
716
|
+
expect(_proc).to receive(:call).with(50).once.and_return 200...300
|
717
|
+
_proc
|
718
|
+
}
|
719
|
+
|
720
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
721
|
+
end
|
722
|
+
|
723
|
+
describe "-> { 200...300 }" do
|
724
|
+
let(:fill) { -> { 200...300 } }
|
725
|
+
|
726
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
727
|
+
end
|
728
|
+
|
729
|
+
describe "-> (c) { 200...300 }" do
|
730
|
+
let(:fill) {
|
731
|
+
_proc = -> (c) { 200...300 }
|
732
|
+
expect(_proc).to receive(:call).with(50).once.and_return 200...300
|
733
|
+
_proc
|
734
|
+
}
|
735
|
+
|
736
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
737
|
+
end
|
738
|
+
end
|
739
|
+
end
|
740
|
+
end
|
741
|
+
end
|
742
|
+
end
|
743
|
+
|
551
744
|
describe ".new" do
|
552
745
|
let(:enum) { Target.new ary1, ary2 }
|
553
746
|
describe "0...100, 200...250" do
|
@@ -623,7 +816,7 @@ describe MergeEnum::MergeEnumerable do
|
|
623
816
|
describe "130" do
|
624
817
|
let(:ary1) {
|
625
818
|
ary = Proc.new { |c| 0...100 }
|
626
|
-
allow(ary).to receive(:call).once.with(130).and_return
|
819
|
+
allow(ary).to receive(:call).once.with(130).and_return 0...100
|
627
820
|
ary
|
628
821
|
}
|
629
822
|
let(:first) { 130 }
|
@@ -631,7 +824,7 @@ describe MergeEnum::MergeEnumerable do
|
|
631
824
|
context "<all>" do
|
632
825
|
let(:ary2) {
|
633
826
|
ary = Proc.new { |c| 200...250 }
|
634
|
-
allow(ary).to receive(:call).once.with(30).and_return
|
827
|
+
allow(ary).to receive(:call).once.with(30).and_return 200...250
|
635
828
|
ary
|
636
829
|
}
|
637
830
|
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
@@ -650,7 +843,7 @@ describe MergeEnum::MergeEnumerable do
|
|
650
843
|
describe "200" do
|
651
844
|
let(:ary1) {
|
652
845
|
ary = Proc.new { |c| 0...100 }
|
653
|
-
allow(ary).to receive(:call).once.with(200).and_return
|
846
|
+
allow(ary).to receive(:call).once.with(200).and_return 0...100
|
654
847
|
ary
|
655
848
|
}
|
656
849
|
let(:ary2) { Proc.new { |c| 200...250 } }
|
@@ -687,7 +880,7 @@ describe MergeEnum::MergeEnumerable do
|
|
687
880
|
describe "50" do
|
688
881
|
let(:ary1) {
|
689
882
|
ary = -> (c) { 0...100 }
|
690
|
-
allow(ary).to receive(:call).once.with(50).and_return
|
883
|
+
allow(ary).to receive(:call).once.with(50).and_return 0...100
|
691
884
|
ary
|
692
885
|
}
|
693
886
|
let(:ary2) {
|
@@ -702,7 +895,7 @@ describe MergeEnum::MergeEnumerable do
|
|
702
895
|
describe "130" do
|
703
896
|
let(:ary1) {
|
704
897
|
ary = -> (c) { 0...100 }
|
705
|
-
allow(ary).to receive(:call).once.with(130).and_return
|
898
|
+
allow(ary).to receive(:call).once.with(130).and_return 0...100
|
706
899
|
ary
|
707
900
|
}
|
708
901
|
let(:first) { 130 }
|
@@ -710,7 +903,7 @@ describe MergeEnum::MergeEnumerable do
|
|
710
903
|
context "<all>" do
|
711
904
|
let(:ary2) {
|
712
905
|
ary = -> (c) { 200...250 }
|
713
|
-
allow(ary).to receive(:call).once.with(30).and_return
|
906
|
+
allow(ary).to receive(:call).once.with(30).and_return 200...250
|
714
907
|
ary
|
715
908
|
}
|
716
909
|
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
@@ -729,7 +922,7 @@ describe MergeEnum::MergeEnumerable do
|
|
729
922
|
describe "200" do
|
730
923
|
let(:ary1) {
|
731
924
|
ary = -> (c) { 0...100 }
|
732
|
-
allow(ary).to receive(:call).once.with(200).and_return
|
925
|
+
allow(ary).to receive(:call).once.with(200).and_return 0...100
|
733
926
|
ary
|
734
927
|
}
|
735
928
|
let(:ary2) { -> (c) { 200...250 } }
|
@@ -788,7 +981,7 @@ describe MergeEnum::MergeEnumerable do
|
|
788
981
|
describe "50" do
|
789
982
|
let(:ary1) {
|
790
983
|
ary = Proc.new { |c| 0...100 }
|
791
|
-
allow(ary).to receive(:call).once.with(50).and_return
|
984
|
+
allow(ary).to receive(:call).once.with(50).and_return 0...100
|
792
985
|
ary
|
793
986
|
}
|
794
987
|
let(:ary2) {
|
@@ -1049,17 +1242,78 @@ describe MergeEnum::MergeEnumerable do
|
|
1049
1242
|
describe ".new" do
|
1050
1243
|
describe "0...100, Array.new(10, nil), Proc.new { |c| 200...250 }, first: 130, compact: true, map: -> (e) { e * 2 }" do
|
1051
1244
|
let(:enum) { Target.new 0...100, Array.new(10, nil), Proc.new { |c| 200...250 }, first: 130, compact: true, map: map }
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1245
|
+
|
1246
|
+
describe "map: nil" do
|
1247
|
+
let(:map) { nil }
|
1248
|
+
subject { enum.to_a }
|
1249
|
+
it { is_expected.to eq (0...100).to_a + (200...230).to_a }
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
describe "map: false" do
|
1253
|
+
let(:map) { false }
|
1254
|
+
subject { enum.to_a }
|
1255
|
+
it { is_expected.to eq (0...100).to_a + (200...230).to_a }
|
1256
|
+
end
|
1257
|
+
|
1258
|
+
describe "map: true" do
|
1259
|
+
let(:map) { true }
|
1260
|
+
subject { enum.to_a }
|
1261
|
+
it { expect { is_expected }.to raise_error }
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
["hoge", "foo", "bar"].each do |m|
|
1265
|
+
describe "map: #{m.inspect}" do
|
1266
|
+
let(:map) { m }
|
1267
|
+
subject { enum.to_a }
|
1268
|
+
it { expect { is_expected }.to raise_error }
|
1056
1269
|
end
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
describe "map: -> { 100 }" do
|
1273
|
+
let(:map) {
|
1274
|
+
_proc = -> { raise "using stub" }
|
1275
|
+
expect(_proc).to receive(:call).with(no_args).exactly(130).times.and_return 100
|
1276
|
+
_proc
|
1277
|
+
}
|
1278
|
+
subject { enum.to_a }
|
1279
|
+
it { is_expected.to eq Array.new(130, 100) }
|
1280
|
+
end
|
1281
|
+
|
1282
|
+
describe "map: -> (e) { e * 2 }" do
|
1283
|
+
let(:map) {
|
1284
|
+
_proc = -> (e) { raise "using stub" }
|
1285
|
+
expect(_proc).to receive(:call).exactly(130).times do |e|
|
1286
|
+
e * 2
|
1287
|
+
end
|
1288
|
+
_proc
|
1289
|
+
}
|
1290
|
+
subject { enum.to_a }
|
1291
|
+
it { is_expected.to eq ((0...100).to_a + (200...230).to_a).map{ |e| e * 2 } }
|
1292
|
+
end
|
1293
|
+
|
1294
|
+
describe "map: -> (e, i) { i }" do
|
1295
|
+
let(:map) {
|
1296
|
+
_proc = -> (e, i) { raise "using stub" }
|
1297
|
+
expect(_proc).to receive(:call).exactly(130).times do |e, i|
|
1298
|
+
i
|
1299
|
+
end
|
1300
|
+
_proc
|
1301
|
+
}
|
1302
|
+
subject { enum.to_a }
|
1303
|
+
it { is_expected.to eq (0...130).to_a }
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
describe "map: -> (e, i, x, y, z) { i }" do
|
1307
|
+
let(:map) {
|
1308
|
+
_proc = -> (e, i, x, y, z) { raise "using stub" }
|
1309
|
+
expect(_proc).to receive(:call).exactly(130).times do |e, i|
|
1310
|
+
i
|
1311
|
+
end
|
1312
|
+
_proc
|
1313
|
+
}
|
1314
|
+
subject { enum.to_a }
|
1315
|
+
it { is_expected.to eq (0...130).to_a }
|
1316
|
+
end
|
1063
1317
|
end
|
1064
1318
|
end
|
1065
1319
|
|
@@ -1074,11 +1328,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1074
1328
|
expect(_proc).to receive(:call).exactly(10).times.and_return 0...100
|
1075
1329
|
_proc
|
1076
1330
|
}
|
1077
|
-
it {
|
1078
|
-
10.times do
|
1079
|
-
enum.to_a
|
1080
|
-
end
|
1081
|
-
}
|
1331
|
+
it { 10.times { enum.to_a } }
|
1082
1332
|
end
|
1083
1333
|
|
1084
1334
|
describe "cache: true" do
|
@@ -1089,9 +1339,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1089
1339
|
_proc
|
1090
1340
|
}
|
1091
1341
|
it {
|
1092
|
-
10.times
|
1093
|
-
enum.to_a
|
1094
|
-
end
|
1342
|
+
10.times { enum.to_a }
|
1095
1343
|
enum.options! cache: false
|
1096
1344
|
enum.to_a
|
1097
1345
|
}
|
@@ -1141,44 +1389,60 @@ describe MergeEnum::MergeEnumerable do
|
|
1141
1389
|
it { is_expected.to eq ary }
|
1142
1390
|
end
|
1143
1391
|
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1392
|
+
[true, 1, "hoge"].each do |opt|
|
1393
|
+
context "#merge_optons #{opt.inspect}" do
|
1394
|
+
subject { enum.merge_options(opt).to_a }
|
1395
|
+
it { expect { is_expected }.to raise_error }
|
1396
|
+
end
|
1147
1397
|
end
|
1148
1398
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1399
|
+
[true, 1, "hoge"].each do |opt|
|
1400
|
+
context "#merge_optons! #{opt.inspect}" do
|
1401
|
+
subject { enum.merge_options!(opt).to_a }
|
1402
|
+
it { expect { is_expected }.to raise_error }
|
1403
|
+
end
|
1152
1404
|
end
|
1153
1405
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1406
|
+
[true, 1, "hoge"].each do |opt|
|
1407
|
+
context "#replace_optons #{opt.inspect}" do
|
1408
|
+
subject { enum.replace_options(opt).to_a }
|
1409
|
+
it { expect { is_expected }.to raise_error }
|
1410
|
+
end
|
1157
1411
|
end
|
1158
1412
|
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1413
|
+
[true, 1, "hoge"].each do |opt|
|
1414
|
+
context "#replace_optons! #{opt.inspect}" do
|
1415
|
+
subject { enum.replace_options!(opt).to_a }
|
1416
|
+
it { expect { is_expected }.to raise_error }
|
1417
|
+
end
|
1162
1418
|
end
|
1163
1419
|
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1420
|
+
[nil, false, {}].each do |opt|
|
1421
|
+
context "#merge_optons #{opt.inspect}" do
|
1422
|
+
subject { enum.merge_options(opt).to_a }
|
1423
|
+
it { is_expected.to eq ary }
|
1424
|
+
end
|
1167
1425
|
end
|
1168
1426
|
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1427
|
+
[nil, false, {}].each do |opt|
|
1428
|
+
context "#merge_optons! #{opt.inspect}" do
|
1429
|
+
subject { enum.merge_options!(opt).to_a }
|
1430
|
+
it { is_expected.to eq ary }
|
1431
|
+
end
|
1172
1432
|
end
|
1173
1433
|
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1434
|
+
[nil, false, {}].each do |opt|
|
1435
|
+
context "#replace_optons #{opt.inspect}" do
|
1436
|
+
subject { enum.replace_options(opt).to_a }
|
1437
|
+
it { is_expected.to eq ary }
|
1438
|
+
end
|
1177
1439
|
end
|
1178
1440
|
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1441
|
+
[nil, false, {}].each do |opt|
|
1442
|
+
context "#replace_optons! #{opt.inspect}" do
|
1443
|
+
subject { enum.replace_options!(opt).to_a }
|
1444
|
+
it { is_expected.to eq ary }
|
1445
|
+
end
|
1182
1446
|
end
|
1183
1447
|
|
1184
1448
|
context "#merge_optons({ first: 160 })" do
|
@@ -1211,44 +1475,32 @@ describe MergeEnum::MergeEnumerable do
|
|
1211
1475
|
it { is_expected.to eq ary[0...80] }
|
1212
1476
|
end
|
1213
1477
|
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
context "#merge_optons! nil" do
|
1220
|
-
subject { enum.merge_options!(nil).to_a }
|
1221
|
-
it { is_expected.to eq ary[0...80] }
|
1222
|
-
end
|
1223
|
-
|
1224
|
-
context "#replace_optons nil" do
|
1225
|
-
subject { enum.replace_options(nil).to_a }
|
1226
|
-
it { is_expected.to eq ary }
|
1227
|
-
end
|
1228
|
-
|
1229
|
-
context "#replace_optons! nil" do
|
1230
|
-
subject { enum.replace_options!(nil).to_a }
|
1231
|
-
it { is_expected.to eq ary }
|
1232
|
-
end
|
1233
|
-
|
1234
|
-
context "#merge_optons {}" do
|
1235
|
-
subject { enum.merge_options({}).to_a }
|
1236
|
-
it { is_expected.to eq ary[0...80] }
|
1478
|
+
[nil, false, {}].each do |opt|
|
1479
|
+
context "#merge_optons #{opt.inspect}" do
|
1480
|
+
subject { enum.merge_options(opt).to_a }
|
1481
|
+
it { is_expected.to eq ary[0...80] }
|
1482
|
+
end
|
1237
1483
|
end
|
1238
1484
|
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1485
|
+
[nil, false, {}].each do |opt|
|
1486
|
+
context "#merge_optons! #{opt.inspect}" do
|
1487
|
+
subject { enum.merge_options!(opt).to_a }
|
1488
|
+
it { is_expected.to eq ary[0...80] }
|
1489
|
+
end
|
1242
1490
|
end
|
1243
1491
|
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1492
|
+
[nil, false, {}].each do |opt|
|
1493
|
+
context "#replace_optons #{opt.inspect}" do
|
1494
|
+
subject { enum.replace_options(opt).to_a }
|
1495
|
+
it { is_expected.to eq ary }
|
1496
|
+
end
|
1247
1497
|
end
|
1248
1498
|
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1499
|
+
[nil, false, {}].each do |opt|
|
1500
|
+
context "#replace_optons! #{opt.inspect}" do
|
1501
|
+
subject { enum.replace_options!(opt).to_a }
|
1502
|
+
it { is_expected.to eq ary }
|
1503
|
+
end
|
1252
1504
|
end
|
1253
1505
|
|
1254
1506
|
context "#merge_optons({ first: 160 })" do
|
@@ -1277,7 +1529,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1277
1529
|
{}, { first: 100 }, { compact: true },
|
1278
1530
|
{ hoge: "hoge", foo: "foo" }
|
1279
1531
|
].each do |opts|
|
1280
|
-
describe "0...100, #{opts}" do
|
1532
|
+
describe "0...100, #{opts.inspect}" do
|
1281
1533
|
let(:enum) { Target.new 0...100, opts }
|
1282
1534
|
|
1283
1535
|
context "<@options>" do
|
@@ -1290,7 +1542,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1290
1542
|
{ first: 100 }, { compact: true },
|
1291
1543
|
{ hoge: "hoge", foo: "foo" }
|
1292
1544
|
].each do |opts_2|
|
1293
|
-
describe "#merge_options(#{opts_2})" do
|
1545
|
+
describe "#merge_options(#{opts_2.inspect})" do
|
1294
1546
|
let(:enum_2) { enum.merge_options opts_2 }
|
1295
1547
|
|
1296
1548
|
context "<eq>" do
|
@@ -1306,7 +1558,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1306
1558
|
end
|
1307
1559
|
end
|
1308
1560
|
|
1309
|
-
describe "#merge_options!(#{opts_2})" do
|
1561
|
+
describe "#merge_options!(#{opts_2.inspect})" do
|
1310
1562
|
let(:enum_2) { enum.merge_options! opts_2 }
|
1311
1563
|
|
1312
1564
|
context "<eq>" do
|
@@ -1322,7 +1574,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1322
1574
|
end
|
1323
1575
|
end
|
1324
1576
|
|
1325
|
-
describe "#replace_options(#{opts_2})" do
|
1577
|
+
describe "#replace_options(#{opts_2.inspect})" do
|
1326
1578
|
let(:enum_2) { enum.replace_options opts_2 }
|
1327
1579
|
|
1328
1580
|
context "<eq>" do
|
@@ -1341,7 +1593,7 @@ describe MergeEnum::MergeEnumerable do
|
|
1341
1593
|
end
|
1342
1594
|
end
|
1343
1595
|
|
1344
|
-
describe "#replace_options!(#{opts_2})" do
|
1596
|
+
describe "#replace_options!(#{opts_2.inspect})" do
|
1345
1597
|
let(:enum_2) { enum.replace_options! opts_2 }
|
1346
1598
|
|
1347
1599
|
context "<eq>" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,35 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
|
-
require 'merge_enum'
|
4
3
|
|
5
4
|
RSpec.configure do |config|
|
6
5
|
config.color = true
|
7
6
|
config.order = :random
|
8
7
|
end
|
9
8
|
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter do |file|
|
12
|
+
not file.filename =~ /^#{SimpleCov.root}\/lib/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'merge_enum'
|
17
|
+
|
18
|
+
require 'rspec_term'
|
19
|
+
RSpecTerm.configure do |config|
|
20
|
+
config.success_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/success.jpg'
|
21
|
+
config.running_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/running.jpg'
|
22
|
+
config.failure_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/failure.jpg'
|
23
|
+
config.nothing_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/nothing.jpg'
|
24
|
+
config.tmp_dir = '/tmp/rspec_term'
|
25
|
+
config.coverage do
|
26
|
+
SimpleCov.result.covered_percent
|
27
|
+
end
|
28
|
+
config.coverage_url do |coverage|
|
29
|
+
case coverage
|
30
|
+
when 100
|
31
|
+
'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/coverage_100.jpg'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merge_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brightgenerous
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,64 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0.rc1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0.rc1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
39
60
|
- !ruby/object:Gem::Version
|
40
61
|
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_term
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.3'
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.3.0
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.3'
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.3.0
|
41
89
|
description: Merge those like Enumerable
|
42
90
|
email:
|
43
91
|
- katou.akihiro@gmail.com
|