ruby_peter_v 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.txt +5 -0
- data/README.md +9 -1
- data/lib/ruby_peter_v/single.rb +1 -1
- data/lib/ruby_peter_v/version.rb +1 -1
- data/spec/lib/ruby_peter_v/single_spec.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7df5375a82188f1f26f4d0daad74483cf6f838d5
|
4
|
+
data.tar.gz: a1a8dfce9c487c07f500580b635da7a3325deb33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f87f0df0e6afed189c3d07afd1c6e169a24b5bdfac1de74f10134bad21bf0acceb913f6872965f91b44d0f59bf9fb9b35301f38ed630204aef249879c4ed497
|
7
|
+
data.tar.gz: dc68048810cb96befda298b9dd5fcb09037bf5684c5478b8bf9fe959f7748a813b3da554ce0dd51fcafeab1577232881cf95e02576dad53ee978839b6f2534b4
|
data/HISTORY.txt
CHANGED
data/README.md
CHANGED
@@ -23,10 +23,13 @@ Add this line to your application's Gemfile:
|
|
23
23
|
ActiveRecord first) which is a silent bug.
|
24
24
|
|
25
25
|
single also works smartly on an Enumerable that
|
26
|
-
does not have a `
|
26
|
+
does not have a `size` method (a lazy collection).
|
27
27
|
It will only evaluate the first(2) elements of
|
28
28
|
the collection to determine that it is oversized.
|
29
29
|
|
30
|
+
When given a block, single will filter (select) on
|
31
|
+
that block.
|
32
|
+
|
30
33
|
```
|
31
34
|
$ irb
|
32
35
|
2.0.0-p195 :001 > require 'ruby_peter_v'
|
@@ -38,6 +41,11 @@ $ irb
|
|
38
41
|
2.0.0-p195 :004 > [1,2].single
|
39
42
|
RubyPeterV::UniquenessError: size of collection was 2.
|
40
43
|
...
|
44
|
+
2.0.0-p247 :005 > [1,2,2].single{ |e| e == 1 }
|
45
|
+
=> 1
|
46
|
+
2.0.0-p247 :006 > [1,2,2].single{ |e| e == 2 }
|
47
|
+
RubyPeterV::UniquenessError: size of collection was 2.
|
48
|
+
...
|
41
49
|
```
|
42
50
|
|
43
51
|
### set_once(attribute, value) on Object
|
data/lib/ruby_peter_v/single.rb
CHANGED
@@ -6,7 +6,7 @@ module Enumerable
|
|
6
6
|
filtered = block_given? ? self.select(&block) : self
|
7
7
|
if filtered.respond_to?(:size)
|
8
8
|
_size = filtered.size
|
9
|
-
message =
|
9
|
+
message = _size
|
10
10
|
else
|
11
11
|
_size = filtered.first(2).size
|
12
12
|
message = "greater than 1 (on Enumerable, the size cannot be calculated)"
|
data/lib/ruby_peter_v/version.rb
CHANGED
@@ -32,10 +32,17 @@ describe "single" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "block filters on :a" do
|
35
|
-
a = [:a, :b]
|
35
|
+
a = [:a, :b, :b]
|
36
36
|
a.single{|e| e == :a}.should == :a
|
37
37
|
end
|
38
38
|
|
39
|
+
it "block filters on :b and raises" do
|
40
|
+
a = [:a, :b, :b]
|
41
|
+
lambda{ a.single{|e| e == :b} }.should raise_error(
|
42
|
+
RubyPeterV::UniquenessError,
|
43
|
+
"size of collection was 2.")
|
44
|
+
end
|
45
|
+
|
39
46
|
it "nil block" do
|
40
47
|
a = [:a, :b]
|
41
48
|
a.single{ }.should == nil
|