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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 850938ee947f3ce50fcdcfe4162e4c62374a59b0
4
- data.tar.gz: 88b16856fcf2b394c52f641b812dee72dfb3d1ae
3
+ metadata.gz: 7df5375a82188f1f26f4d0daad74483cf6f838d5
4
+ data.tar.gz: a1a8dfce9c487c07f500580b635da7a3325deb33
5
5
  SHA512:
6
- metadata.gz: 727a2fab4b29424771d37145b69e34df45ba576baa38fc6aa296a9e0c37d69cd7a2117696ed3b67114638f36a860c26a732a130f366e3a4813ae473792767c80
7
- data.tar.gz: d8e1653acbeefd69c46714db994da4a22169dc48f9f68a6c6c02f6aea3fd4b28cae7b67f38ee59fff3333af5d6ced489818a4641a5e113317d8a2fd5b52112cf
6
+ metadata.gz: 7f87f0df0e6afed189c3d07afd1c6e169a24b5bdfac1de74f10134bad21bf0acceb913f6872965f91b44d0f59bf9fb9b35301f38ed630204aef249879c4ed497
7
+ data.tar.gz: dc68048810cb96befda298b9dd5fcb09037bf5684c5478b8bf9fe959f7748a813b3da554ce0dd51fcafeab1577232881cf95e02576dad53ee978839b6f2534b4
@@ -53,5 +53,10 @@
53
53
  * refactor
54
54
  * add validation on attribute in SetOnce
55
55
 
56
+ 0.0.13 (2013-10-16)
57
+
58
+ * add docs for block usage with `single`
59
+ * fix bug in exception message
60
+
56
61
  TODO
57
62
  * Object#assert_keys_in
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 `single` method (a lazy collection).
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
@@ -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 = size
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)"
@@ -1,3 +1,3 @@
1
1
  module RubyPeterV
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_peter_v
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Vandenabeele