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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5ea86f91bd7f5f0025e631a78c82562a38d5d66
4
- data.tar.gz: 1300f23cad999c0c25dad32b39f019d694fd287c
3
+ metadata.gz: c64e0522ca9a0eb0401c14d9aca92be6b9f56bc8
4
+ data.tar.gz: 9a1f157736faedfa8c9aa7355bda149e6905fb4e
5
5
  SHA512:
6
- metadata.gz: 5c5fa1e332fe40a13462eeae6d959bb27d6e2122ae472414449060833e7a82de50f17c2ceaefbddd55eebe08aae7c109ceccb75dd3c8d8b5cc982c8d7c28f977
7
- data.tar.gz: f34884099fa596d6bbccd990de8c378afd7c9fcfb0dd458db0ecaebccc2e38c3f17aac80b2c4920cb65205e864c8e47ba3dcaef3b26343e8cbee246d498683ad
6
+ metadata.gz: 3a433c48bb72596127e0a797f33d9d4298252963aac6b9d479b35373d2802b129207ce1aeb726966051516d393654920b670e5922d02f8fa9ec6454df8ce3c7c
7
+ data.tar.gz: 11b2b0752a1d2a37cb1442f0452e6bf60cf7540556bc4558efadef67734e3c7ea972cbc5654e55c37c6b36ae0c76d97917859f6f8b7fecab8bace73b174c95e7
data/Gemfile CHANGED
@@ -1,3 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ group :test do
6
+ gem "codeclimate-test-reporter", require: nil
7
+ end
8
+
9
+ group :tools do
10
+ gem "pry"
11
+ end
@@ -1,16 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-result_matcher (0.3.0)
5
- kleisli
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
- kleisli (0.2.7)
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.11.2
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://travis-ci.org/dry-rb/dry-result_matcher.svg?branch=master)][travis]
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 [Kleisli](https://github.com/txus/kleisli) `Either` results.
15
+ An expressive, all-in-one API for operating on [dry-monads](https://github.com/dry-rb/dry-monads) `Either` results.
15
16
 
16
- ## Usage
17
+ ## Links
17
18
 
18
- Operate an an `Either` object from the outside:
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 "kleisli"
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.is_a?(Kleisli::Either::Right)
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.is_a?(Kleisli::Either::Left)
20
+ return output unless result.left?
20
21
  @output = block.call(result.value)
21
22
  end
22
23
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module ResultMatcher
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "0.4.0".freeze
4
4
  end
5
5
  end
@@ -1,8 +1,10 @@
1
- example_id | status | run_time |
2
- ---------------------------------------------------- | ------ | --------------- |
3
- ./spec/integration/result_matcher_spec.rb[1:1:1:1] | passed | 0.00008 seconds |
4
- ./spec/integration/result_matcher_spec.rb[1:1:2:1] | passed | 0.00014 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.00012 seconds |
7
- ./spec/integration/result_matcher_spec.rb[1:2:2:1:1] | passed | 0.00014 seconds |
8
- ./spec/integration/result_matcher_spec.rb[1:2:2:2:1] | passed | 0.00098 seconds |
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
@@ -1,7 +1,11 @@
1
- require "simplecov"
2
- SimpleCov.minimum_coverage 100
3
- SimpleCov.start do
4
- add_filter "/spec/"
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.3.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-03-22 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: kleisli
14
+ name: dry-monads
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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: '0'
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: https://github.com/dry-rb/dry-result_matcher
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: '0'
128
+ version: 2.1.0
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="