bidu-core_ext 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -2
- data/core_ext.gemspec +1 -0
- data/lib/bidu/core_ext/version.rb +1 -1
- data/lib/enumerable.rb +7 -0
- data/spec/lib/array_spec.rb +39 -0
- data/spec/lib/hash_spec.rb +58 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/shared_examples/remap.rb +0 -0
- metadata +33 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81d3366a7c3b5cd63415fc50eb42843069280983
|
4
|
+
data.tar.gz: 4e5ef6782170c62c580b7128af42decde4b909f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da316c745e01f3c425fa36c94f229b512a7a7d1794d61f5203b87f3ab99b977bd1e761eda1eea6fa5b706eeae5fc6c4d813e64c6b166288d81a63597defe354a
|
7
|
+
data.tar.gz: 94a6fb92d00af8cb2527f4a2ae62b09616739b5dfd6c7817bfd17b879598946b90bfc64bd8092df771a5a182fbe682ba839600fd516ebb374d406326387084fa
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bidu-core_ext (1.2.
|
4
|
+
bidu-core_ext (1.2.1)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
@@ -13,12 +13,20 @@ GEM
|
|
13
13
|
minitest (~> 5.1)
|
14
14
|
thread_safe (~> 0.3, >= 0.3.4)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
+
coderay (1.1.0)
|
16
17
|
diff-lcs (1.2.5)
|
17
18
|
docile (1.1.5)
|
18
19
|
i18n (0.7.0)
|
19
20
|
json (1.8.3)
|
20
|
-
|
21
|
+
method_source (0.8.2)
|
22
|
+
minitest (5.8.3)
|
21
23
|
multi_json (1.10.1)
|
24
|
+
pry (0.10.3)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.8.1)
|
27
|
+
slop (~> 3.4)
|
28
|
+
pry-nav (0.2.4)
|
29
|
+
pry (>= 0.9.10, < 0.11.0)
|
22
30
|
rake (10.3.2)
|
23
31
|
rspec (2.99.0)
|
24
32
|
rspec-core (~> 2.99.0)
|
@@ -33,6 +41,7 @@ GEM
|
|
33
41
|
multi_json (~> 1.0)
|
34
42
|
simplecov-html (~> 0.8.0)
|
35
43
|
simplecov-html (0.8.0)
|
44
|
+
slop (3.6.0)
|
36
45
|
thread_safe (0.3.5)
|
37
46
|
tzinfo (1.2.2)
|
38
47
|
thread_safe (~> 0.1)
|
@@ -43,6 +52,7 @@ PLATFORMS
|
|
43
52
|
DEPENDENCIES
|
44
53
|
bidu-core_ext!
|
45
54
|
bundler (~> 1.6)
|
55
|
+
pry-nav
|
46
56
|
rake
|
47
57
|
rspec (~> 2.14)
|
48
58
|
rspec-mocks
|
data/core_ext.gemspec
CHANGED
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'rake'
|
22
22
|
spec.add_development_dependency 'rspec', '~> 2.14'
|
23
23
|
spec.add_development_dependency 'rspec-mocks'
|
24
|
+
spec.add_development_dependency 'pry-nav'
|
24
25
|
spec.add_development_dependency 'simplecov'
|
25
26
|
end
|
data/lib/enumerable.rb
CHANGED
data/spec/lib/array_spec.rb
CHANGED
@@ -106,4 +106,43 @@ describe Array do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe '#map_and_select' do
|
111
|
+
let(:array) { [1, 2, 3, 4].map { |i| { value: i} } }
|
112
|
+
let(:filtered) { array.map_and_select(&block) }
|
113
|
+
|
114
|
+
context 'when block returns nil' do
|
115
|
+
let(:block) { proc {} }
|
116
|
+
it { expect(filtered).to be_empty }
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when block returns false' do
|
120
|
+
let(:block) { proc { false } }
|
121
|
+
it { expect(filtered).to be_empty }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when block returns a true evaluated value' do
|
125
|
+
let(:block) { proc(&:to_s) }
|
126
|
+
|
127
|
+
it { expect(filtered).to eq(array.map(&:to_s)) }
|
128
|
+
|
129
|
+
context 'but not for the first value' do
|
130
|
+
let(:transformer) { double(:transformer) }
|
131
|
+
let(:block) { proc { |v| transformer.transform(v) } }
|
132
|
+
|
133
|
+
before do
|
134
|
+
allow(transformer).to receive(:transform) do |v|
|
135
|
+
v.to_s if v[:value] > 1
|
136
|
+
end
|
137
|
+
filtered
|
138
|
+
end
|
139
|
+
|
140
|
+
it { expect(filtered).to eq(array[1..-1].map(&:to_s)) }
|
141
|
+
|
142
|
+
it 'calls the mapping only once per element' do
|
143
|
+
expect(transformer).to have_received(:transform).exactly(4)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
109
148
|
end
|
data/spec/lib/hash_spec.rb
CHANGED
@@ -259,6 +259,12 @@ describe Hash do
|
|
259
259
|
|
260
260
|
it { expect(value).to eq('1') }
|
261
261
|
|
262
|
+
context 'when block returns the key and not the value' do
|
263
|
+
let(:block) { proc { |k, v| v > 1 && k } }
|
264
|
+
|
265
|
+
it { expect(value).to eq(:b) }
|
266
|
+
end
|
267
|
+
|
262
268
|
context 'but not for the first value' do
|
263
269
|
let(:transformer) { double(:transformer) }
|
264
270
|
let(:block) { proc { |_, v| transformer.transform(v) } }
|
@@ -285,4 +291,56 @@ describe Hash do
|
|
285
291
|
end
|
286
292
|
end
|
287
293
|
end
|
294
|
+
|
295
|
+
describe '#map_and_select' do
|
296
|
+
let(:hash) { { a: 1, b: 2, c: 3, d: 4 } }
|
297
|
+
let(:list) { hash.map_and_select(&block) }
|
298
|
+
|
299
|
+
context 'when block returns nil' do
|
300
|
+
let(:block) { proc {} }
|
301
|
+
it { expect(list).to be_empty }
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'when block returns false' do
|
305
|
+
let(:block) { proc { false } }
|
306
|
+
it { expect(list).to be_empty }
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'when block returns a true evaluated value' do
|
310
|
+
let(:block) { proc { |_, v| v.to_s } }
|
311
|
+
|
312
|
+
it { expect(list).to eq((1..4).map(&:to_s)) }
|
313
|
+
|
314
|
+
context 'when block returns the key and not the value' do
|
315
|
+
let(:block) { proc { |k, v| v > 1 && k } }
|
316
|
+
|
317
|
+
it { expect(list).to eq([:b, :c, :d]) }
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'but not for the first value' do
|
321
|
+
let(:transformer) { double(:transformer) }
|
322
|
+
let(:block) { proc { |_, v| transformer.transform(v) } }
|
323
|
+
|
324
|
+
before do
|
325
|
+
allow(transformer).to receive(:transform) do |v|
|
326
|
+
v.to_s if v > 1
|
327
|
+
end
|
328
|
+
list
|
329
|
+
end
|
330
|
+
|
331
|
+
it { expect(list).to eq(hash.values[1..-1].map(&:to_s)) }
|
332
|
+
it 'calls the mapping only once for each value' do
|
333
|
+
expect(transformer).to have_received(:transform).exactly(4)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context 'when the block accepts one argument' do
|
339
|
+
let(:block) { proc { |v| v } }
|
340
|
+
|
341
|
+
it do
|
342
|
+
expect(list).to eq([[:a, 1], [:b, 2], [:c, 3], [:d, 4]])
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
288
346
|
end
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,97 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bidu-core_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bidu Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.14'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-mocks
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-nav
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - '>='
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- -
|
108
|
+
- - '>='
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
description:
|
@@ -101,8 +115,8 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
|
-
-
|
105
|
-
-
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
106
120
|
- Gemfile
|
107
121
|
- Gemfile.lock
|
108
122
|
- LICENSE
|
@@ -146,17 +160,17 @@ require_paths:
|
|
146
160
|
- lib
|
147
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
162
|
requirements:
|
149
|
-
- -
|
163
|
+
- - '>='
|
150
164
|
- !ruby/object:Gem::Version
|
151
165
|
version: '0'
|
152
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
167
|
requirements:
|
154
|
-
- -
|
168
|
+
- - '>='
|
155
169
|
- !ruby/object:Gem::Version
|
156
170
|
version: '0'
|
157
171
|
requirements: []
|
158
172
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.4.
|
173
|
+
rubygems_version: 2.4.6
|
160
174
|
signing_key:
|
161
175
|
specification_version: 4
|
162
176
|
summary: Core Extensions
|