dry-matcher 0.6.0 → 0.7.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
- SHA1:
3
- metadata.gz: 6d10419e259ad298f3f7406069c3abedaf6d0b3a
4
- data.tar.gz: 73c64df0c8dcdbfa5729e1788af55c59c464d1ca
2
+ SHA256:
3
+ metadata.gz: a452c874d6095df3fd8a932dfc0a604fa2ef531dff6ca30ee2c850f1012ce13c
4
+ data.tar.gz: 8a061065d80d1821fdb4e9b020050cd380ee69a73af6351bbc78bfeab5153911
5
5
  SHA512:
6
- metadata.gz: 7fe5b016af423a72b690fea03bc18f310fca34d580665345096a283cf937ee26c27bac3f0de69d2a279308700b1ddc85e478e70bb8518a194ae79ae2ac692f3b
7
- data.tar.gz: 669f02bcb69d4f0c57fb38bdd0534561cf1924c4e2ecdf7cc4bf40fe928e7af585f3b5ee8c7d91799475e3b37565f609b1620c1d192538da3fb96987d42c797b
6
+ metadata.gz: 8af536933244d441747638bcf7244f1918c4cb626717d48be1087704628f0c3b09266e6b55917fd18b776a464eaae4fc25e8382e22b661d3f408dc99c69c93bf
7
+ data.tar.gz: 5ca949c319b53001db633bdf6493eb2f99ab27bea4171b3429523991f9c3063ef5edceb3a5ee068ec75f9af5269f0795d7d09d1b03437d57cbdfee2e6fd8e8b3
@@ -1,3 +1,11 @@
1
+ # 0.7.0 / to-be-released
2
+
3
+ ## Changed
4
+
5
+ - `EitherMatcher` was renamed to `ResultMatcher` according to match the rename of `Either` to `Result` in dry-monads 0.4.0. The previous name is still there for backward compatibility, we'll deprecate and drop it in furure releases (flash-gordon in [#13](https://github.com/dry-rb/dry-matcher/pull/13))
6
+
7
+ [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-matcher/compare/v0.6.0...v0.7.0)
8
+
1
9
  # 0.6.0 / 2016-12-19
2
10
 
3
11
  ## Added
@@ -9,15 +17,11 @@
9
17
  - Matches must now be exhaustive - when matching against a value, at least one match block must be provided for each of a matcher's cases (timriley in [#7](https://github.com/dry-rb/dry-matcher/pull/7))
10
18
  - `Dry::Matcher::Case` objects can now be created without a `resolve:` proc. In this case, a default will be provided that passes the result value through (timriley in [#9](https://github.com/dry-rb/dry-matcher/pull/9))
11
19
 
12
- [Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-result_matcher/compare/v0.5.1...v0.6.0)
13
-
14
- # 0.5.1 / 2016-07-06
15
-
16
20
  ## Fixed
17
21
 
18
22
  - Fixed handling of calls to non-existent cases within a matcher block (timriley)
19
23
 
20
- [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-result_matcher/compare/v0.5.0...v0.5.1)
24
+ [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-matcher/compare/v0.5.0...v0.6.0)
21
25
 
22
26
  # 0.5.0 / 2016-06-30
23
27
 
@@ -80,7 +84,7 @@
80
84
  ```
81
85
  - The previous `Dry::ResultMatcher.match` behaviour (for matching `Either` monads) has been moved to `Dry::Matcher::EitherMatcher.call`
82
86
 
83
- [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-result_matcher/compare/v0.4.0...v0.5.0)
87
+ [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-matcher/compare/v0.4.0...v0.5.0)
84
88
 
85
89
  # 0.4.0 / 2016-06-08
86
90
 
@@ -92,7 +96,7 @@
92
96
 
93
97
  * Expect monads from [dry-monads](https://github.com/dry-rb/dry-monads) instead of [Kleisli](https://github.com/txus/kleisli) (ttdonovan)
94
98
 
95
- [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-result_matcher/compare/v0.3.0...v0.4.0)
99
+ [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-matcher/compare/v0.3.0...v0.4.0)
96
100
 
97
101
  # 0.3.0 / 2016-03-23
98
102
 
@@ -100,7 +104,7 @@
100
104
 
101
105
  * Renamed to `dry-result_matcher`. Match results using `Dry::ResultMatcher.match` or extend your own classes with `Dry::ResultMatcher.for`.
102
106
 
103
- [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-result_matcher/compare/v0.2.0...v0.3.0)
107
+ [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-matcher/compare/v0.2.0...v0.3.0)
104
108
 
105
109
  # 0.2.0 / 2016-02-10
106
110
 
@@ -108,7 +112,7 @@
108
112
 
109
113
  * Added `EitherResultMatcher.for(*methods)` to return a module wrapping the specified methods (returning an `Either`) with the match block API. Example usage, in a class with a `#call` method: `include EitherResultMatcher.for(:call)`.
110
114
 
111
- [Compare v0.1.0...v0.22.0](https://github.com/dry-rb/dry-result_matcher/compare/v0.1.0...v0.2.0)
115
+ [Compare v0.1.0...v0.22.0](https://github.com/dry-rb/dry-matcher/compare/v0.1.0...v0.2.0)
112
116
 
113
117
  # 0.1.0 / 2015-12-03
114
118
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  group :test do
6
6
  gem "simplecov"
7
7
  gem "codeclimate-test-reporter"
8
- gem "dry-monads", "~> 0.0.2"
8
+ gem "dry-monads", '>= 0.4.0'
9
9
  end
10
10
 
11
11
  group :tools do
@@ -13,10 +13,10 @@ module Dry
13
13
  #
14
14
  # @example Usage with `dry-monads`
15
15
  # class MonadicOperation
16
- # include Dry::Matcher.for(:call, with: Dry::Matcher::EitherMatcher)
16
+ # include Dry::Matcher.for(:call, with: Dry::Matcher::ResultMatcher)
17
17
  #
18
18
  # def call
19
- # Dry::Monads::Either::Right.new('Success')
19
+ # Dry::Monads::Result::Success.new('Success')
20
20
  # end
21
21
  # end
22
22
  #
@@ -71,11 +71,11 @@ module Dry
71
71
  #
72
72
  # @example Usage with `dry-monads`
73
73
  # require 'dry-monads'
74
- # require 'dry/matcher/either_matcher'
74
+ # require 'dry/matcher/result_matcher'
75
75
  #
76
- # value = Dry::Monads::Either::Left.new('failure!')
76
+ # value = Dry::Monads::Result::Failure.new('failure!')
77
77
  #
78
- # Dry::Matcher::EitherMatcher.(value) do |m|
78
+ # Dry::Matcher::ResultMatcher.(value) do |m|
79
79
  # m.success { |v| "Yay: #{v}" }
80
80
  # m.failure { |v| "Boo: #{v}" }
81
81
  # end #=> "Boo: failure!"
@@ -1,74 +1,7 @@
1
- require "dry/matcher"
1
+ require "dry/matcher/result_matcher"
2
2
 
3
3
  module Dry
4
4
  class Matcher
5
- # Built-in {Matcher} ready to use with `Either` or `Try` monads from
6
- # [dry-monads](/gems/dry-monads) or any other compatible gems.
7
- #
8
- # Provides {Case}s for two matchers:
9
- # * `:success` matches `Dry::Monads::Either::Right`
10
- # and `Dry::Monads::Try::Success` (or any other monad that responds to
11
- # `#to_either` returning either monad that is `#right?`)
12
- # * `:failure` matches `Dry::Monads::Either::Left` and
13
- # `Dry::Monads::Try::Failure` (or any other monad that responds to
14
- # `#to_either` returning either monad that is `#left?`)
15
- #
16
- # @return [Dry::Matcher]
17
- #
18
- # @example Usage with `dry-monads`
19
- # require 'dry-monads'
20
- # require 'dry/matcher/either_matcher'
21
- #
22
- # value = Dry::Monads::Either::Right.new('success!')
23
- #
24
- # Dry::Matcher::EitherMatcher.(value) do |m|
25
- # m.success do |v|
26
- # "Yay: #{v}"
27
- # end
28
- #
29
- # m.failure do |v|
30
- # "Boo: #{v}"
31
- # end
32
- # end #=> "Yay: success!"
33
- #
34
- # @example Usage with custom monad
35
- # require 'dry/matcher/either_matcher'
36
- #
37
- # class CustomBooleanMonad
38
- # def initialize(value); @value = value; end
39
- # attr_reader :value
40
- # alias_method :right?, :value
41
- # def left?; !right?; end
42
- # def to_either; self; end
43
- # end
44
- #
45
- # value = CustomBooleanMonad.new(nil)
46
- #
47
- # Dry::Matcher::EitherMatcher.(value) do |m|
48
- # m.success { |v| "#{v.inspect} is truthy" }
49
- # m.failure { |v| "#{v.inspect} is falsey" }
50
- # end # => "nil is falsey"
51
- EitherMatcher = Dry::Matcher.new(
52
- success: Case.new(
53
- match: -> result, *pattern {
54
- result = result.to_either
55
- result.right?
56
- },
57
- resolve: -> result {
58
- result = result.to_either
59
- result.value
60
- },
61
- ),
62
- failure: Case.new(
63
- match: -> result, *pattern {
64
- result = result.to_either
65
- result.left?
66
- },
67
- resolve: -> result {
68
- result = result.to_either
69
- result.value
70
- },
71
- )
72
- )
5
+ EitherMatcher = ResultMatcher
73
6
  end
74
7
  end
@@ -0,0 +1,74 @@
1
+ require "dry/matcher"
2
+
3
+ module Dry
4
+ class Matcher
5
+ # Built-in {Matcher} ready to use with `Result` or `Try` monads from
6
+ # [dry-monads](/gems/dry-monads) or any other compatible gems.
7
+ #
8
+ # Provides {Case}s for two matchers:
9
+ # * `:success` matches `Dry::Monads::Result::Success`
10
+ # and `Dry::Monads::Try::Value` (or any other monad that responds to
11
+ # `#to_result` returning result monad that is `#success?`)
12
+ # * `:failure` matches `Dry::Monads::Result::Failure` and
13
+ # `Dry::Monads::Try::Error` (or any other monad that responds to
14
+ # `#to_result` returning result monad that is `#failure?`)
15
+ #
16
+ # @return [Dry::Matcher]
17
+ #
18
+ # @example Usage with `dry-monads`
19
+ # require 'dry-monads'
20
+ # require 'dry/matcher/result_matcher'
21
+ #
22
+ # value = Dry::Monads::Result::Success.new('success!')
23
+ #
24
+ # Dry::Matcher::ResultMatcher.(value) do |m|
25
+ # m.success do |v|
26
+ # "Yay: #{v}"
27
+ # end
28
+ #
29
+ # m.failure do |v|
30
+ # "Boo: #{v}"
31
+ # end
32
+ # end #=> "Yay: success!"
33
+ #
34
+ # @example Usage with custom monad
35
+ # require 'dry/matcher/result_matcher'
36
+ #
37
+ # class CustomBooleanMonad
38
+ # def initialize(value); @value = value; end
39
+ # attr_reader :value
40
+ # alias_method :success?, :value
41
+ # def failure?; !success?; end
42
+ # def to_result; self; end
43
+ # end
44
+ #
45
+ # value = CustomBooleanMonad.new(nil)
46
+ #
47
+ # Dry::Matcher::ResultMatcher.(value) do |m|
48
+ # m.success { |v| "#{v.inspect} is truthy" }
49
+ # m.failure { |v| "#{v.inspect} is falsey" }
50
+ # end # => "nil is falsey"
51
+ ResultMatcher = Dry::Matcher.new(
52
+ success: Case.new(
53
+ match: -> result, *pattern {
54
+ result = result.to_result
55
+ result.success?
56
+ },
57
+ resolve: -> result {
58
+ result = result.to_result
59
+ result.value!
60
+ },
61
+ ),
62
+ failure: Case.new(
63
+ match: -> result, *pattern {
64
+ result = result.to_result
65
+ result.failure?
66
+ },
67
+ resolve: -> result {
68
+ result = result.to_result
69
+ result.failure
70
+ },
71
+ )
72
+ )
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Matcher
3
- VERSION = "0.6.0".freeze
3
+ VERSION = "0.7.0".freeze
4
4
  end
5
5
  end
@@ -1,18 +1,18 @@
1
1
  example_id | status | run_time |
2
2
  ----------------------------------------------------- | ------ | --------------- |
3
- ./spec/integration/class_enhancement_spec.rb[1:1:1:1] | passed | 0.00015 seconds |
4
- ./spec/integration/class_enhancement_spec.rb[1:1:2:1] | passed | 0.00014 seconds |
5
- ./spec/integration/class_enhancement_spec.rb[1:2:1:1] | passed | 0.00088 seconds |
6
- ./spec/integration/class_enhancement_spec.rb[1:2:2:1] | passed | 0.00013 seconds |
7
- ./spec/integration/either_matcher_spec.rb[1:1:1:1] | passed | 0.00011 seconds |
8
- ./spec/integration/either_matcher_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
9
- ./spec/integration/either_matcher_spec.rb[1:1:3:1:1] | passed | 0.00016 seconds |
10
- ./spec/integration/either_matcher_spec.rb[1:1:3:2:1] | passed | 0.00015 seconds |
11
- ./spec/integration/matcher_spec.rb[1:1:1] | passed | 0.00016 seconds |
12
- ./spec/integration/matcher_spec.rb[1:1:2] | passed | 0.00015 seconds |
13
- ./spec/integration/matcher_spec.rb[1:1:3] | passed | 0.00159 seconds |
14
- ./spec/integration/matcher_spec.rb[1:1:4:1] | passed | 0.00018 seconds |
15
- ./spec/integration/matcher_spec.rb[1:1:4:2] | passed | 0.00185 seconds |
16
- ./spec/unit/case_spec.rb[1:1:1] | passed | 0.00054 seconds |
17
- ./spec/unit/case_spec.rb[1:2:1] | passed | 0.00048 seconds |
18
- ./spec/unit/case_spec.rb[1:2:2] | passed | 0.00008 seconds |
3
+ ./spec/integration/class_enhancement_spec.rb[1:1:1:1] | passed | 0.00011 seconds |
4
+ ./spec/integration/class_enhancement_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
5
+ ./spec/integration/class_enhancement_spec.rb[1:2:1:1] | passed | 0.00014 seconds |
6
+ ./spec/integration/class_enhancement_spec.rb[1:2:2:1] | passed | 0.0001 seconds |
7
+ ./spec/integration/matcher_spec.rb[1:1:1] | passed | 0.00017 seconds |
8
+ ./spec/integration/matcher_spec.rb[1:1:2] | passed | 0.0001 seconds |
9
+ ./spec/integration/matcher_spec.rb[1:1:3] | passed | 0.00122 seconds |
10
+ ./spec/integration/matcher_spec.rb[1:1:4:1] | passed | 0.00009 seconds |
11
+ ./spec/integration/matcher_spec.rb[1:1:4:2] | passed | 0.00147 seconds |
12
+ ./spec/integration/result_matcher_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
13
+ ./spec/integration/result_matcher_spec.rb[1:1:2:1] | passed | 0.00008 seconds |
14
+ ./spec/integration/result_matcher_spec.rb[1:1:3:1:1] | passed | 0.00015 seconds |
15
+ ./spec/integration/result_matcher_spec.rb[1:1:3:2:1] | passed | 0.00017 seconds |
16
+ ./spec/unit/case_spec.rb[1:1:1] | passed | 0.00087 seconds |
17
+ ./spec/unit/case_spec.rb[1:2:1] | passed | 0.00008 seconds |
18
+ ./spec/unit/case_spec.rb[1:2:2] | passed | 0.00056 seconds |
@@ -1,13 +1,13 @@
1
1
  require "dry-monads"
2
- require "dry/matcher/either_matcher"
2
+ require "dry/matcher/result_matcher"
3
3
 
4
4
  RSpec.describe "Class enhancement with Dry::Matcher.for" do
5
5
  let(:operation) {
6
6
  Class.new do
7
- include Dry::Matcher.for(:call, with: Dry::Matcher::EitherMatcher)
7
+ include Dry::Matcher.for(:call, with: Dry::Matcher::ResultMatcher)
8
8
 
9
9
  def call(bool)
10
- bool ? Dry::Monads::Right("a success") : Dry::Monads::Left("a failure")
10
+ bool ? Dry::Monads::Success("a success") : Dry::Monads::Failure("a failure")
11
11
  end
12
12
  end.new
13
13
  }
@@ -49,7 +49,7 @@ RSpec.describe "Class enhancement with Dry::Matcher.for" do
49
49
  let(:input) { true }
50
50
 
51
51
  it "returns the result" do
52
- expect(result).to eq Dry::Monads::Right("a success")
52
+ expect(result).to eq Dry::Monads::Success("a success")
53
53
  end
54
54
  end
55
55
 
@@ -57,7 +57,7 @@ RSpec.describe "Class enhancement with Dry::Matcher.for" do
57
57
  let(:input) { false }
58
58
 
59
59
  it "returns the result" do
60
- expect(result).to eq Dry::Monads::Left("a failure")
60
+ expect(result).to eq Dry::Monads::Failure("a failure")
61
61
  end
62
62
  end
63
63
  end
@@ -4,15 +4,15 @@ RSpec.describe Dry::Matcher do
4
4
  context "with match cases provided" do
5
5
  let(:success_case) {
6
6
  Dry::Matcher::Case.new(
7
- match: -> result { result.right? },
8
- resolve: -> result { result.value },
7
+ match: -> result { result.success? },
8
+ resolve: -> result { result.value! },
9
9
  )
10
10
  }
11
11
 
12
12
  let(:failure_case) {
13
13
  Dry::Matcher::Case.new(
14
- match: -> result { result.left? },
15
- resolve: -> result { result.value },
14
+ match: -> result { result.failure? },
15
+ resolve: -> result { result.failure },
16
16
  )
17
17
  }
18
18
 
@@ -36,17 +36,17 @@ RSpec.describe Dry::Matcher do
36
36
  end
37
37
 
38
38
  it "matches on success" do
39
- input = Dry::Monads::Right("Yes!")
39
+ input = Dry::Monads::Success("Yes!")
40
40
  expect(call_match(input)).to eq "Success: Yes!"
41
41
  end
42
42
 
43
43
  it "matches on failure" do
44
- input = Dry::Monads::Left("No!")
44
+ input = Dry::Monads::Failure("No!")
45
45
  expect(call_match(input)).to eq "Failure: No!"
46
46
  end
47
47
 
48
48
  it "requires an exhaustive match" do
49
- input = Dry::Monads::Right("Yes!")
49
+ input = Dry::Monads::Success("Yes!")
50
50
 
51
51
  expect {
52
52
  matcher.(input) do |m|
@@ -1,10 +1,10 @@
1
1
  require "dry-monads"
2
- require "dry/matcher/either_matcher"
2
+ require "dry/matcher/result_matcher"
3
3
 
4
- RSpec.describe "Dry::Matcher::EitherMatcher" do
4
+ RSpec.describe "Dry::Matcher::ResultMatcher" do
5
5
  describe "external matching" do
6
6
  subject(:match) {
7
- Dry::Matcher::EitherMatcher.(result) do |m|
7
+ Dry::Matcher::ResultMatcher.(result) do |m|
8
8
  m.success do |v|
9
9
  "Matched success: #{v}"
10
10
  end
@@ -16,7 +16,7 @@ RSpec.describe "Dry::Matcher::EitherMatcher" do
16
16
  }
17
17
 
18
18
  context "successful result" do
19
- let(:result) { Dry::Monads::Right("a success") }
19
+ let(:result) { Dry::Monads::Success("a success") }
20
20
 
21
21
  it "matches on success" do
22
22
  expect(match).to eq "Matched success: a success"
@@ -24,14 +24,14 @@ RSpec.describe "Dry::Matcher::EitherMatcher" do
24
24
  end
25
25
 
26
26
  context "failed result" do
27
- let(:result) { Dry::Monads::Left("a failure") }
27
+ let(:result) { Dry::Monads::Failure("a failure") }
28
28
 
29
29
  it "matches on failure" do
30
30
  expect(match).to eq "Matched failure: a failure"
31
31
  end
32
32
  end
33
33
 
34
- context "result convertible to either" do
34
+ context "result convertible to result" do
35
35
  context "converts to success" do
36
36
  let(:result) {
37
37
  Dry::Monads::Try.lift([StandardError], -> { 'a success' })
@@ -9,7 +9,7 @@ RSpec.describe Dry::Matcher::Case do
9
9
 
10
10
  describe "#resolve" do
11
11
  it "calls the resolve proc with the value" do
12
- kase = described_class.new(match: -> * { true }, resolve: resolve = -> value { value.to_s })
12
+ kase = described_class.new(match: -> * { true }, resolve: -> value { value.to_s })
13
13
 
14
14
  expect(kase.resolve(123)).to eq "123"
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.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-12-18 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,11 +97,12 @@ files:
97
97
  - lib/dry/matcher/case.rb
98
98
  - lib/dry/matcher/either_matcher.rb
99
99
  - lib/dry/matcher/evaluator.rb
100
+ - lib/dry/matcher/result_matcher.rb
100
101
  - lib/dry/matcher/version.rb
101
102
  - spec/examples.txt
102
103
  - spec/integration/class_enhancement_spec.rb
103
- - spec/integration/either_matcher_spec.rb
104
104
  - spec/integration/matcher_spec.rb
105
+ - spec/integration/result_matcher_spec.rb
105
106
  - spec/spec_helper.rb
106
107
  - spec/unit/case_spec.rb
107
108
  homepage: http://dry-rb.org/gems/dry-matcher
@@ -116,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
118
  - - ">="
118
119
  - !ruby/object:Gem::Version
119
- version: 2.1.0
120
+ version: 2.2.0
120
121
  required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  requirements:
122
123
  - - ">="
@@ -124,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  requirements: []
126
127
  rubyforge_project:
127
- rubygems_version: 2.5.1
128
+ rubygems_version: 2.7.3
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: Flexible, expressive pattern matching for Ruby
131
132
  test_files: []
132
- has_rdoc: