dry-result_matcher 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/Gemfile.lock +15 -4
- data/README.md +5 -41
- data/lib/dry/result_matcher/matcher.rb +4 -3
- data/lib/dry/result_matcher/version.rb +1 -1
- data/spec/examples.txt +10 -8
- data/spec/integration/result_matcher_spec.rb +33 -5
- data/spec/spec_helper.rb +8 -4
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64e0522ca9a0eb0401c14d9aca92be6b9f56bc8
|
4
|
+
data.tar.gz: 9a1f157736faedfa8c9aa7355bda149e6905fb4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a433c48bb72596127e0a797f33d9d4298252963aac6b9d479b35373d2802b129207ce1aeb726966051516d393654920b670e5922d02f8fa9ec6454df8ce3c7c
|
7
|
+
data.tar.gz: 11b2b0752a1d2a37cb1442f0452e6bf60cf7540556bc4558efadef67734e3c7ea972cbc5654e55c37c6b36ae0c76d97917859f6f8b7fecab8bace73b174c95e7
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dry-result_matcher (0.
|
5
|
-
|
4
|
+
dry-result_matcher (0.4.0)
|
5
|
+
dry-monads (~> 0.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
codeclimate-test-reporter (0.5.0)
|
11
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
12
|
+
coderay (1.1.1)
|
10
13
|
diff-lcs (1.2.5)
|
11
14
|
docile (1.1.5)
|
15
|
+
dry-monads (0.0.1)
|
12
16
|
json (1.8.3)
|
13
|
-
|
17
|
+
method_source (0.8.2)
|
18
|
+
pry (0.10.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.8.1)
|
21
|
+
slop (~> 3.4)
|
14
22
|
rake (10.4.2)
|
15
23
|
rspec (3.3.0)
|
16
24
|
rspec-core (~> 3.3.0)
|
@@ -30,6 +38,7 @@ GEM
|
|
30
38
|
json (~> 1.8)
|
31
39
|
simplecov-html (~> 0.10.0)
|
32
40
|
simplecov-html (0.10.0)
|
41
|
+
slop (3.6.0)
|
33
42
|
yard (0.8.7.6)
|
34
43
|
|
35
44
|
PLATFORMS
|
@@ -37,11 +46,13 @@ PLATFORMS
|
|
37
46
|
|
38
47
|
DEPENDENCIES
|
39
48
|
bundler (~> 1.10)
|
49
|
+
codeclimate-test-reporter
|
40
50
|
dry-result_matcher!
|
51
|
+
pry
|
41
52
|
rake (~> 10.4.2)
|
42
53
|
rspec (~> 3.3.0)
|
43
54
|
simplecov (~> 0.10.0)
|
44
55
|
yard
|
45
56
|
|
46
57
|
BUNDLED WITH
|
47
|
-
1.
|
58
|
+
1.12.3
|
data/README.md
CHANGED
@@ -7,52 +7,16 @@
|
|
7
7
|
# dry-result_matcher [![Join the Gitter chat](https://badges.gitter.im/Join%20Chat.svg)][gitter]
|
8
8
|
|
9
9
|
[![Gem Version](https://img.shields.io/gem/v/dry-result_matcher.svg)][gem]
|
10
|
-
[![Build Status](https://
|
10
|
+
[![Build Status](https://img.shields.io/travis/dry-rb/dry-result_matcher.svg)][travis]
|
11
11
|
[![Code Climate](https://img.shields.io/codeclimate/github/dry-rb/dry-result_matcher.svg)][code_climate]
|
12
|
+
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/dry-rb/dry-result_matcher.svg)][code_climate]
|
12
13
|
[![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-result_matcher.svg)][inch]
|
13
14
|
|
14
|
-
An expressive, all-in-one API for operating on [
|
15
|
+
An expressive, all-in-one API for operating on [dry-monads](https://github.com/dry-rb/dry-monads) `Either` results.
|
15
16
|
|
16
|
-
##
|
17
|
+
## Links
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
result = Right("some result")
|
22
|
-
|
23
|
-
Dry::ResultMatcher.match(result) do |m|
|
24
|
-
m.success do |v|
|
25
|
-
"Success: #{v}"
|
26
|
-
end
|
27
|
-
|
28
|
-
m.failure do |v|
|
29
|
-
"Failure: #{v}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
```
|
33
|
-
|
34
|
-
Or extend your own `Either`-returning classes to support result match blocks:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
class MyOperation
|
38
|
-
include Dry::ResultMatcher.for(:call)
|
39
|
-
|
40
|
-
def call
|
41
|
-
Right("some result")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
my_op = MyOperation.new
|
46
|
-
my_op.call() do |m|
|
47
|
-
m.success do |v|
|
48
|
-
"Success: #{v}"
|
49
|
-
end
|
50
|
-
|
51
|
-
m.failure do |v|
|
52
|
-
"Failure: #{v}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
```
|
19
|
+
* [Documentation](http://dry-rb.org/gems/dry-result_matcher)
|
56
20
|
|
57
21
|
## License
|
58
22
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "dry-monads"
|
2
2
|
|
3
3
|
module Dry
|
4
4
|
module ResultMatcher
|
@@ -7,16 +7,17 @@ module Dry
|
|
7
7
|
attr_reader :output
|
8
8
|
|
9
9
|
def initialize(result)
|
10
|
+
result = result.to_either if result.respond_to?(:to_either)
|
10
11
|
@result = result
|
11
12
|
end
|
12
13
|
|
13
14
|
def success(&block)
|
14
|
-
return output unless result.
|
15
|
+
return output unless result.right?
|
15
16
|
@output = block.call(result.value)
|
16
17
|
end
|
17
18
|
|
18
19
|
def failure(&block)
|
19
|
-
return output unless result.
|
20
|
+
return output unless result.left?
|
20
21
|
@output = block.call(result.value)
|
21
22
|
end
|
22
23
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/integration/result_matcher_spec.rb[1:1:1:1]
|
4
|
-
./spec/integration/result_matcher_spec.rb[1:1:2:1]
|
5
|
-
./spec/integration/result_matcher_spec.rb[1:2:1:1:1]
|
6
|
-
./spec/integration/result_matcher_spec.rb[1:2:1:2:1]
|
7
|
-
./spec/integration/result_matcher_spec.rb[1:2:
|
8
|
-
./spec/integration/result_matcher_spec.rb[1:2:
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------------------ | ------ | --------------- |
|
3
|
+
./spec/integration/result_matcher_spec.rb[1:1:1:1] | passed | 0.00015 seconds |
|
4
|
+
./spec/integration/result_matcher_spec.rb[1:1:2:1] | passed | 0.00213 seconds |
|
5
|
+
./spec/integration/result_matcher_spec.rb[1:2:1:1:1] | passed | 0.00013 seconds |
|
6
|
+
./spec/integration/result_matcher_spec.rb[1:2:1:2:1] | passed | 0.00013 seconds |
|
7
|
+
./spec/integration/result_matcher_spec.rb[1:2:1:3:1:1] | passed | 0.00017 seconds |
|
8
|
+
./spec/integration/result_matcher_spec.rb[1:2:1:3:2:1] | passed | 0.00017 seconds |
|
9
|
+
./spec/integration/result_matcher_spec.rb[1:2:2:1:1] | passed | 0.00016 seconds |
|
10
|
+
./spec/integration/result_matcher_spec.rb[1:2:2:2:1] | passed | 0.00014 seconds |
|
@@ -13,7 +13,7 @@ RSpec.describe Dry::ResultMatcher do
|
|
13
13
|
}
|
14
14
|
|
15
15
|
context "successful result" do
|
16
|
-
let(:result) { Right("a success") }
|
16
|
+
let(:result) { Dry::Monads::Right("a success") }
|
17
17
|
|
18
18
|
it "matches on success" do
|
19
19
|
expect(match).to eq "Matched success: a success"
|
@@ -21,7 +21,7 @@ RSpec.describe Dry::ResultMatcher do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context "failed result" do
|
24
|
-
let(:result) { Left("a failure") }
|
24
|
+
let(:result) { Dry::Monads::Left("a failure") }
|
25
25
|
|
26
26
|
it "matches on failure" do
|
27
27
|
expect(match).to eq "Matched failure: a failure"
|
@@ -35,7 +35,7 @@ RSpec.describe Dry::ResultMatcher do
|
|
35
35
|
include Dry::ResultMatcher.for(:call)
|
36
36
|
|
37
37
|
def call(bool)
|
38
|
-
bool ? Right("a success") : Left("a failure")
|
38
|
+
bool ? Dry::Monads::Right("a success") : Dry::Monads::Left("a failure")
|
39
39
|
end
|
40
40
|
end.new
|
41
41
|
}
|
@@ -68,6 +68,34 @@ RSpec.describe Dry::ResultMatcher do
|
|
68
68
|
expect(match).to eq "Matched failure: a failure"
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
context "result responds to #to_either" do
|
73
|
+
let(:operation) {
|
74
|
+
Class.new do
|
75
|
+
include Dry::ResultMatcher.for(:call)
|
76
|
+
|
77
|
+
def call(bool)
|
78
|
+
Dry::Monads::Try.lift([StandardError], -> { (bool) ? 'a success' : raise('a failure') })
|
79
|
+
end
|
80
|
+
end.new
|
81
|
+
}
|
82
|
+
|
83
|
+
context "successful result" do
|
84
|
+
let(:input) { true }
|
85
|
+
|
86
|
+
it "matches on success" do
|
87
|
+
expect(match).to eq "Matched success: a success"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "failed result" do
|
92
|
+
let(:input) { false }
|
93
|
+
|
94
|
+
it "matches on failure" do
|
95
|
+
expect(match).to eq "Matched failure: a failure"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
71
99
|
end
|
72
100
|
|
73
101
|
describe "without match blocks" do
|
@@ -77,7 +105,7 @@ RSpec.describe Dry::ResultMatcher do
|
|
77
105
|
let(:input) { true }
|
78
106
|
|
79
107
|
it "returns the result" do
|
80
|
-
expect(result).to eq Right("a success")
|
108
|
+
expect(result).to eq Dry::Monads::Right("a success")
|
81
109
|
end
|
82
110
|
end
|
83
111
|
|
@@ -85,7 +113,7 @@ RSpec.describe Dry::ResultMatcher do
|
|
85
113
|
let(:input) { false }
|
86
114
|
|
87
115
|
it "returns the result" do
|
88
|
-
expect(result).to eq Left("a failure")
|
116
|
+
expect(result).to eq Dry::Monads::Left("a failure")
|
89
117
|
end
|
90
118
|
end
|
91
119
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
if RUBY_ENGINE == "ruby"
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
|
5
|
+
require "simplecov"
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
require "dry-result_matcher"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-result_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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: 2016-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-monads
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,7 +113,7 @@ files:
|
|
113
113
|
- spec/examples.txt
|
114
114
|
- spec/integration/result_matcher_spec.rb
|
115
115
|
- spec/spec_helper.rb
|
116
|
-
homepage:
|
116
|
+
homepage: http://dry-rb.org/gems/dry-result_matcher
|
117
117
|
licenses:
|
118
118
|
- MIT
|
119
119
|
metadata: {}
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
requirements:
|
126
126
|
- - ">="
|
127
127
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
128
|
+
version: 2.1.0
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
131
|
- - ">="
|