unsound 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unsound/control.rb +14 -0
- data/lib/unsound/version.rb +1 -1
- data/spec/unit/unsound/control_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fef2d390995831f611de3a87edb4a2c90399c72
|
4
|
+
data.tar.gz: 666f8821e7286223fb5d5e7ba03b858dabf5b531
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cebd7a4a5c0939bee370a90ae0a22283692f148fc4aa6fb4d701483449fec260e3adf04fdd25599fe1626616fadaf519f648946a679779d646de4bcfbf84a31
|
7
|
+
data.tar.gz: 63b4956bcd70e4cd6b3886f9aec0dc1366e963dcd2361cdd4aec67f982b32aee6b04d0a6c46a6629bfdb2216d0ef81d6140e8dd03316124fc84a52449550fe10
|
data/lib/unsound/control.rb
CHANGED
@@ -16,5 +16,19 @@ module Unsound
|
|
16
16
|
rescue
|
17
17
|
Data::Left.new($ERROR_INFO)
|
18
18
|
end
|
19
|
+
|
20
|
+
# Execute the block. If the block
|
21
|
+
# results in Nil, return {Data::Nothing},
|
22
|
+
# otherwise wrap the result in a {Data::Just}
|
23
|
+
#
|
24
|
+
# @param block [Block] the block to execute
|
25
|
+
# @return [Data::Nothing, Data::Just] an instance of {Data::Maybe}
|
26
|
+
def maybe(&block)
|
27
|
+
if (result = block.call).nil?
|
28
|
+
Data::Nothing.new
|
29
|
+
else
|
30
|
+
Data::Just.new(result)
|
31
|
+
end
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
data/lib/unsound/version.rb
CHANGED
@@ -24,4 +24,26 @@ RSpec.describe Unsound::Control do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe Unsound::Control, ".maybe" do
|
29
|
+
subject(:run_maybe) { Unsound::Control.maybe(&blk) }
|
30
|
+
|
31
|
+
context "the block returns nil" do
|
32
|
+
let(:blk) { -> { nil } }
|
33
|
+
|
34
|
+
it "returns Nothing" do
|
35
|
+
expect(run_maybe).to be_a(Unsound::Data::Nothing)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "the block does not return nil" do
|
40
|
+
let(:blk) { -> { result } }
|
41
|
+
let(:result) { double(:result) }
|
42
|
+
|
43
|
+
it "returns a Just" do
|
44
|
+
expect(run_maybe).to be_a(Unsound::Data::Just)
|
45
|
+
expect(run_maybe.value).to eq(result)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
27
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unsound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Swan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concord
|
@@ -129,3 +129,4 @@ test_files:
|
|
129
129
|
- spec/unit/unsound/control_spec.rb
|
130
130
|
- spec/unit/unsound/data/either_spec.rb
|
131
131
|
- spec/unit/unsound/data/maybe_spec.rb
|
132
|
+
has_rdoc:
|