translated_collection 0.1.0 → 0.1.1
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
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmMxYzFmZGJhYmFmOWQ5MjkxOWQwYWJmNDRlMDFkNzBlYzFjMGQwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTBjMjNkN2RhMDdhMmI2YTAyNGRjOGQ5MjhmZGExNjk1ZWJlMGI5MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDk2YWRiYzA3ZmUyMDJlZDEyNDI0OGJkMjc2ZWFkMWQwOTlhNDFjMjMwNGZk
|
10
|
+
ZDRiYTJlYTQ0MWExYzJkYjk2ZTE5ZTNkODUwY2QyZmI4Y2EyZTY2YjZhYjU3
|
11
|
+
ZTViYjIyOTM3Y2NiY2RhOGVlNDcxNTQ2ODMwMzI2N2FlMWExMjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGRhMmQzNzQ2MzUxYjEwYjkzMzRiNjcyMzkwYmQ1MmZlMDM5YWM1NDg5Y2Ji
|
14
|
+
YzFhZTYxOTE2NWMyMTk0ZTNjYmQzNmU0YjM2Y2U3MzFmOGQ2MDMxNTI3NThm
|
15
|
+
ZmY3YjNjNTg5NjYyMTkwOGNkY2UzNGZiNmRkYmQ2Mjc1MWZjNzg=
|
data/Gemfile.lock
CHANGED
@@ -202,5 +202,12 @@ module TranslatedCollection
|
|
202
202
|
_wrap_enumerator(@collection.reject!)
|
203
203
|
end
|
204
204
|
end
|
205
|
+
|
206
|
+
def map!(&blk)
|
207
|
+
@collection.map! {|x| @wrapfunc_in.call(blk.call(@wrapfunc_out.call(x))) }
|
208
|
+
@wrap_results ? self : self.to_a
|
209
|
+
end
|
210
|
+
|
211
|
+
alias :collect! :map!
|
205
212
|
end
|
206
213
|
end
|
@@ -20,6 +20,41 @@ describe TranslatedCollection::Wrapper do
|
|
20
20
|
collection.map {|elt| upperfn.call(elt)}
|
21
21
|
end
|
22
22
|
|
23
|
+
context 'duck API' do
|
24
|
+
context 'Enumerable methods' do
|
25
|
+
%w[all? any? as_json chunk collect collect_concat count cycle detect
|
26
|
+
drop drop_while each_cons each_entry each_slice each_with_index each_with_object
|
27
|
+
entries exclude? find find_all find_index first flat_map grep group_by
|
28
|
+
include? index_by inject many? map max max_by member? min min_by minmax
|
29
|
+
minmax_by none? one? partition reduce reject reverse_each select slice_before
|
30
|
+
sort sort_by sum take take_while to_a to_set zip].each do |meth|
|
31
|
+
it { should respond_to(meth) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Array-like methods' do
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'Destructive update methods' do
|
39
|
+
%w[map! collect! clear push []= reject!].each do |meth|
|
40
|
+
it { should respond_to(meth) }
|
41
|
+
end
|
42
|
+
|
43
|
+
%w[compact! fill flatten! reverse! rotate! select! shuffle! slice! sort_by! sort! uniq!].each do |meth|
|
44
|
+
it "should implement #{meth}" do
|
45
|
+
pending "Not implemented yet"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'Conversion methods' do
|
51
|
+
%w[to_a to_set].each do |meth|
|
52
|
+
it { should respond_to(meth) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
23
58
|
context 'creation' do
|
24
59
|
let :collection do
|
25
60
|
%w[a b C]
|
@@ -174,6 +209,22 @@ describe TranslatedCollection::Wrapper do
|
|
174
209
|
subject.reject! {|x| x == Object.new }.should be_nil
|
175
210
|
end
|
176
211
|
end
|
212
|
+
|
213
|
+
context '#map!' do
|
214
|
+
it 'should yield each element in order, and return all' do
|
215
|
+
subject.map! {|elt| elt+elt}.to_a.should == %w[AA BB CC]
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should yield each element in order, and return all unwrapped if configured' do
|
219
|
+
subject.wrap_results = false
|
220
|
+
subject.map! {|elt| elt+elt}.should == %w[AA BB CC]
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should alter the original array' do
|
224
|
+
expect { subject.map! {|elt| elt+elt} }.
|
225
|
+
to change { subject.collection }.to %w[aa bb cc]
|
226
|
+
end
|
227
|
+
end
|
177
228
|
end
|
178
229
|
|
179
230
|
context 'Enumerable' do
|