either_result_matcher 0.1.0 → 0.2.0
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +25 -0
- data/lib/either_result_matcher.rb +26 -0
- data/lib/either_result_matcher/version.rb +1 -1
- data/spec/examples.txt +8 -4
- data/spec/integration/match_either_result_spec.rb +79 -15
- metadata +3 -4
- data/lib/either_result_matcher/either_extensions.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a95e0850165a08bd7f7c0f492f9d11844b7b50
|
4
|
+
data.tar.gz: b430504c717d1c6121768c77caaef30644a8df07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f88039789b2bccf79ad32e72c5275472d96b4a8d4bfaadffb58d3f2f57a8bd50d66a47f5cbdf8231cf1628896e825f320a76077d5b2bafce9a9a65c28aaee1
|
7
|
+
data.tar.gz: 2b900cc22f5191ab7559d9d4523b9ca2bd1b290d5d98f6212541a13f86473646459e9f0557578dbc4cdb0689e7d28ff3a6f0161cef36038efd8bd400c8bccdce
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
either_result_matcher (0.
|
4
|
+
either_result_matcher (0.2.0)
|
5
5
|
kleisli
|
6
6
|
|
7
7
|
GEM
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
diff-lcs (1.2.5)
|
14
14
|
docile (1.1.5)
|
15
15
|
json (1.8.3)
|
16
|
-
kleisli (0.2.
|
16
|
+
kleisli (0.2.7)
|
17
17
|
parser (2.2.3.0)
|
18
18
|
ast (>= 1.1, < 3.0)
|
19
19
|
powerpack (0.1.1)
|
@@ -59,4 +59,4 @@ DEPENDENCIES
|
|
59
59
|
yard
|
60
60
|
|
61
61
|
BUNDLED WITH
|
62
|
-
1.
|
62
|
+
1.11.2
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
## Usage
|
4
4
|
|
5
|
+
Operate an an `Either` object from the outside:
|
6
|
+
|
5
7
|
```ruby
|
6
8
|
result = Right("some result")
|
7
9
|
|
@@ -15,3 +17,26 @@ MatchEitherResult(result) do |m|
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
```
|
20
|
+
|
21
|
+
Or extend your own `Either`-returning classes to support result match blocks:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class MyOperation
|
25
|
+
include EitherResultMatcher.for(:call)
|
26
|
+
|
27
|
+
def call
|
28
|
+
Right("some result")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
my_op = MyOperation.new
|
33
|
+
my_op.call() do |m|
|
34
|
+
m.success do |v|
|
35
|
+
"Success: #{v}"
|
36
|
+
end
|
37
|
+
|
38
|
+
m.failure do |v|
|
39
|
+
"Failure: #{v}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
@@ -3,3 +3,29 @@ require "either_result_matcher/matcher"
|
|
3
3
|
def MatchEitherResult(result, &block)
|
4
4
|
block.call(EitherResultMatcher::Matcher.new(result))
|
5
5
|
end
|
6
|
+
|
7
|
+
module EitherResultMatcher
|
8
|
+
def self.for(*match_methods)
|
9
|
+
matchers_mod = Module.new do
|
10
|
+
match_methods.each do |match_method|
|
11
|
+
define_method(match_method) do |*args, &block|
|
12
|
+
result = super(*args)
|
13
|
+
|
14
|
+
if block
|
15
|
+
MatchEitherResult(result, &block)
|
16
|
+
else
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Module.new do
|
24
|
+
const_set :Matchers, matchers_mod
|
25
|
+
|
26
|
+
def self.included(klass)
|
27
|
+
klass.prepend const_get(:Matchers)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/examples.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/integration/match_either_result_spec.rb[1:1:1]
|
4
|
-
./spec/integration/match_either_result_spec.rb[1:2:1]
|
1
|
+
example_id | status | run_time |
|
2
|
+
--------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/integration/match_either_result_spec.rb[1:1:1:1] | passed | 0.00011 seconds |
|
4
|
+
./spec/integration/match_either_result_spec.rb[1:1:2:1] | passed | 0.00011 seconds |
|
5
|
+
./spec/integration/match_either_result_spec.rb[1:2:1:1:1] | passed | 0.00146 seconds |
|
6
|
+
./spec/integration/match_either_result_spec.rb[1:2:1:2:1] | passed | 0.00024 seconds |
|
7
|
+
./spec/integration/match_either_result_spec.rb[1:2:2:1:1] | passed | 0.00012 seconds |
|
8
|
+
./spec/integration/match_either_result_spec.rb[1:2:2:2:1] | passed | 0.00012 seconds |
|
@@ -1,29 +1,93 @@
|
|
1
1
|
RSpec.describe "MatchEitherResult" do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
describe "external matching" do
|
3
|
+
subject(:match) {
|
4
|
+
MatchEitherResult(result) do |m|
|
5
|
+
m.success do |v|
|
6
|
+
"Matched success: #{v}"
|
7
|
+
end
|
8
|
+
|
9
|
+
m.failure do |v|
|
10
|
+
"Matched failure: #{v}"
|
11
|
+
end
|
6
12
|
end
|
13
|
+
}
|
14
|
+
|
15
|
+
context "successful result" do
|
16
|
+
let(:result) { Right("a success") }
|
7
17
|
|
8
|
-
|
9
|
-
"Matched
|
18
|
+
it "matches on success" do
|
19
|
+
expect(match).to eq "Matched success: a success"
|
10
20
|
end
|
11
21
|
end
|
12
|
-
}
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
context "failed result" do
|
24
|
+
let(:result) { Left("a failure") }
|
16
25
|
|
17
|
-
|
18
|
-
|
26
|
+
it "matches on failure" do
|
27
|
+
expect(match).to eq "Matched failure: a failure"
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
22
|
-
|
23
|
-
let(:
|
32
|
+
describe "class enhancement" do
|
33
|
+
let(:operation) {
|
34
|
+
Class.new do
|
35
|
+
include EitherResultMatcher.for(:call)
|
36
|
+
|
37
|
+
def call(bool)
|
38
|
+
bool ? Right("a success") : Left("a failure")
|
39
|
+
end
|
40
|
+
end.new
|
41
|
+
}
|
42
|
+
|
43
|
+
describe "match blocks" do
|
44
|
+
subject(:match) {
|
45
|
+
operation.call(input) do |m|
|
46
|
+
m.success do |v|
|
47
|
+
"Matched success: #{v}"
|
48
|
+
end
|
49
|
+
|
50
|
+
m.failure do |v|
|
51
|
+
"Matched failure: #{v}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
context "successful result" do
|
57
|
+
let(:input) { true }
|
58
|
+
|
59
|
+
it "matches on success" do
|
60
|
+
expect(match).to eq "Matched success: a success"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "failed result" do
|
65
|
+
let(:input) { false }
|
24
66
|
|
25
|
-
|
26
|
-
|
67
|
+
it "matches on failure" do
|
68
|
+
expect(match).to eq "Matched failure: a failure"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "without match blocks" do
|
74
|
+
subject(:result) { operation.call(input) }
|
75
|
+
|
76
|
+
context "successful result" do
|
77
|
+
let(:input) { true }
|
78
|
+
|
79
|
+
it "returns the result" do
|
80
|
+
expect(result).to eq Right("a success")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "failed result" do
|
85
|
+
let(:input) { false }
|
86
|
+
|
87
|
+
it "returns the result" do
|
88
|
+
expect(result).to eq Left("a failure")
|
89
|
+
end
|
90
|
+
end
|
27
91
|
end
|
28
92
|
end
|
29
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: either_result_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kleisli
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- README.md
|
122
122
|
- Rakefile
|
123
123
|
- lib/either_result_matcher.rb
|
124
|
-
- lib/either_result_matcher/either_extensions.rb
|
125
124
|
- lib/either_result_matcher/matcher.rb
|
126
125
|
- lib/either_result_matcher/version.rb
|
127
126
|
- spec/examples.txt
|
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
146
|
version: '0'
|
148
147
|
requirements: []
|
149
148
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.5.1
|
151
150
|
signing_key:
|
152
151
|
specification_version: 4
|
153
152
|
summary: Expressive, all-in-one match API for Kleisli Either monads
|