dry-matcher 0.8.3 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -33
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-matcher.gemspec +25 -17
- data/lib/dry/matcher/case.rb +5 -9
- data/lib/dry/matcher/either_matcher.rb +4 -4
- data/lib/dry/matcher/evaluator.rb +3 -2
- data/lib/dry/matcher/match.rb +23 -0
- data/lib/dry/matcher/maybe_matcher.rb +62 -0
- data/lib/dry/matcher/result_matcher.rb +5 -16
- data/lib/dry/matcher/version.rb +1 -1
- data/lib/dry/matcher.rb +4 -4
- data/lib/dry-matcher.rb +1 -1
- metadata +21 -36
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/ci.yml +0 -52
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -56
- data/.gitignore +0 -8
- data/.rspec +0 -4
- data/.rubocop.yml +0 -101
- data/.yardopts +0 -1
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -18
- data/Gemfile.devtools +0 -14
- data/LICENSE.md +0 -9
- data/Rakefile +0 -8
- data/docsite/source/class-enhancement.html.md +0 -30
- data/docsite/source/index.html.md +0 -89
- data/docsite/source/result-matcher.html.md +0 -34
- data/project.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70aa7037f519f35f5c9c29206d0529fe452a5e0b08268f6d7d0884846e74bfa5
|
4
|
+
data.tar.gz: c5022a321698bfff91e04688bc2c4b09487dff1c47902ade7005d6384745df2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a53db4413d2e75db38e6740efc025d9b71a9a92af176e50dcdc514ab6ecd8b2b5f46175588c8c16c3316ade374d936c1899d7daccf4dcd8a2529283ac52be7c
|
7
|
+
data.tar.gz: 42c1f0b533368724e43f9f01f99251bca601de0a1896a0adad2cce2362eeb3e5b76a324f4bee705dd5887f1def7c8ea24ae064889483bb9509e5b94ef9d81db6
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,47 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
-
##
|
3
|
+
## 0.10.0 2022-11-16
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- This version is compatible with recently released dry-rb dependencies (@flash-gordon)
|
9
|
+
|
10
|
+
[Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-matcher/compare/v0.9.0...v0.10.0)
|
11
|
+
|
12
|
+
## 0.9.0 2021-03-05
|
13
|
+
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Matcher evaluator is now a standard `Object` descendant (see #32) (@solnic)
|
18
|
+
|
19
|
+
[Compare v0.8.3...v0.9.0](https://github.com/dry-rb/dry-matcher/compare/v0.8.3...v0.9.0)
|
20
|
+
|
21
|
+
## 0.8.3 2020-01-07
|
22
|
+
|
23
|
+
|
24
|
+
### Fixed
|
4
25
|
|
5
26
|
- Delegation warnings about keyword arguments (flash-gordon)
|
6
27
|
|
28
|
+
|
7
29
|
[Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-matcher/compare/v0.8.2...v0.8.3)
|
8
30
|
|
9
|
-
|
31
|
+
## 0.8.2 2019-09-06
|
32
|
+
|
10
33
|
|
11
|
-
|
34
|
+
### Fixed
|
12
35
|
|
13
36
|
- Minimal dry-core version set to 0.4.8 (flash-gordon)
|
14
37
|
|
38
|
+
|
15
39
|
[Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-matcher/compare/v0.8.1...v0.8.2)
|
16
40
|
|
17
|
-
|
41
|
+
## 0.8.1 2019-08-13
|
42
|
+
|
18
43
|
|
19
|
-
|
44
|
+
### Added
|
20
45
|
|
21
46
|
- `Dry::Matcher#for` is a shortcut for `Dry::Matcher.for(..., with: matcher)` (flash-gordon)
|
22
47
|
|
@@ -32,15 +57,13 @@
|
|
32
57
|
end
|
33
58
|
```
|
34
59
|
|
35
|
-
[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-matcher/compare/v0.8.0...v0.8.1)
|
36
60
|
|
37
|
-
|
61
|
+
[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-matcher/compare/v0.8.0...v0.8.1)
|
38
62
|
|
39
|
-
##
|
63
|
+
## 0.8.0 2019-07-30
|
40
64
|
|
41
|
-
- [BREAKING] Support for Ruby 2.3 was dropped as it's EOL
|
42
65
|
|
43
|
-
|
66
|
+
### Added
|
44
67
|
|
45
68
|
- API for cases was changed to work with a single block instead of `match`/`resolve` combination (flash-gordon in [#23](https://github.com/dry-rb/dry-matcher/pull/23)):
|
46
69
|
```ruby
|
@@ -74,36 +97,43 @@
|
|
74
97
|
end #=> "Cannot be done: :reasons"
|
75
98
|
```
|
76
99
|
|
100
|
+
### Changed
|
101
|
+
|
102
|
+
- [BREAKING] Support for Ruby 2.3 was dropped as it's EOL
|
103
|
+
|
77
104
|
[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-matcher/compare/v0.7.0...v0.8.0)
|
78
105
|
|
79
|
-
|
106
|
+
## 0.7.0 2018-01-11
|
107
|
+
|
80
108
|
|
81
|
-
|
109
|
+
### Changed
|
82
110
|
|
83
111
|
- `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))
|
84
112
|
|
85
113
|
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-matcher/compare/v0.6.0...v0.7.0)
|
86
114
|
|
87
|
-
|
115
|
+
## 0.6.0 2016-12-19
|
88
116
|
|
89
|
-
|
117
|
+
|
118
|
+
### Added
|
90
119
|
|
91
120
|
- API documentation for most methods (alsemyonov in [#8](https://github.com/dry-rb/dry-matcher/pull/8))
|
92
121
|
|
93
|
-
|
122
|
+
### Fixed
|
94
123
|
|
95
|
-
-
|
96
|
-
- `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))
|
124
|
+
- Fixed handling of calls to non-existent cases within a matcher block (timriley)
|
97
125
|
|
98
|
-
|
126
|
+
### Changed
|
99
127
|
|
100
|
-
-
|
128
|
+
- 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))
|
129
|
+
- `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))
|
101
130
|
|
102
131
|
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-matcher/compare/v0.5.0...v0.6.0)
|
103
132
|
|
104
|
-
|
133
|
+
## 0.5.0 2016-06-30
|
105
134
|
|
106
|
-
|
135
|
+
|
136
|
+
### Added
|
107
137
|
|
108
138
|
- Added support for building custom matchers, with an any number of match cases, each offering their own matching and resolving logic. This is now the primary API for dry-matcher. (timriley)
|
109
139
|
|
@@ -145,7 +175,7 @@
|
|
145
175
|
result # => "Yay: success!"
|
146
176
|
```
|
147
177
|
|
148
|
-
|
178
|
+
### Changed
|
149
179
|
|
150
180
|
- Renamed to `dry-matcher`, since this is now a flexible, general purpose pattern matching API. All components are now available under the `Dry::Matcher` namespace. (timriley)
|
151
181
|
- `Dry::Matcher.for` requires a matcher object to be passed when being included in a class:
|
@@ -160,39 +190,42 @@
|
|
160
190
|
end
|
161
191
|
end
|
162
192
|
```
|
163
|
-
|
164
193
|
- The previous `Dry::ResultMatcher.match` behaviour (for matching `Either` monads) has been moved to `Dry::Matcher::EitherMatcher.call`
|
165
194
|
|
166
195
|
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-matcher/compare/v0.4.0...v0.5.0)
|
167
196
|
|
168
|
-
|
197
|
+
## 0.4.0 2016-06-08
|
169
198
|
|
170
|
-
|
199
|
+
|
200
|
+
### Added
|
171
201
|
|
172
202
|
- Support convertible result objects responding to `#to_either` (ttdonovan)
|
173
203
|
|
174
|
-
|
204
|
+
### Changed
|
175
205
|
|
176
206
|
- Expect monads from [dry-monads](https://github.com/dry-rb/dry-monads) instead of [Kleisli](https://github.com/txus/kleisli) (ttdonovan)
|
177
207
|
|
178
208
|
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-matcher/compare/v0.3.0...v0.4.0)
|
179
209
|
|
180
|
-
|
210
|
+
## 0.3.0 2016-03-23
|
211
|
+
|
181
212
|
|
182
|
-
|
213
|
+
### Changed
|
183
214
|
|
184
215
|
- Renamed to `dry-result_matcher`. Match results using `Dry::ResultMatcher.match` or extend your own classes with `Dry::ResultMatcher.for`.
|
185
216
|
|
186
217
|
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-matcher/compare/v0.2.0...v0.3.0)
|
187
218
|
|
188
|
-
|
219
|
+
## 0.2.0 2016-02-10
|
189
220
|
|
190
|
-
|
221
|
+
|
222
|
+
### Added
|
191
223
|
|
192
224
|
- 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)`.
|
193
225
|
|
194
|
-
[Compare v0.1.0...v0.22.0](https://github.com/dry-rb/dry-matcher/compare/v0.1.0...v0.2.0)
|
195
226
|
|
196
|
-
|
227
|
+
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-matcher/compare/v0.1.0...v0.2.0)
|
228
|
+
|
229
|
+
## 0.1.0 2015-12-03
|
197
230
|
|
198
231
|
Initial release.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-matcher
|
2
3
|
[actions]: https://github.com/dry-rb/dry-matcher/actions
|
3
4
|
[codacy]: https://www.codacy.com/gh/dry-rb/dry-matcher
|
@@ -10,19 +11,19 @@
|
|
10
11
|
[![CI Status](https://github.com/dry-rb/dry-matcher/workflows/ci/badge.svg)][actions]
|
11
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f09a7d1745fd430d829a1f825357db88)][codacy]
|
12
13
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f09a7d1745fd430d829a1f825357db88)][codacy]
|
13
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-matcher.svg?branch=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-matcher.svg?branch=main)][inchpages]
|
14
15
|
|
15
16
|
## Links
|
16
17
|
|
17
|
-
* [User documentation](
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-matcher)
|
18
19
|
* [API documentation](http://rubydoc.info/gems/dry-matcher)
|
19
20
|
|
20
21
|
## Supported Ruby versions
|
21
22
|
|
22
23
|
This library officially supports the following Ruby versions:
|
23
24
|
|
24
|
-
* MRI
|
25
|
-
* jruby
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
26
27
|
|
27
28
|
## License
|
28
29
|
|
data/dry-matcher.gemspec
CHANGED
@@ -1,27 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
4
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
7
|
+
require "dry/matcher/version"
|
6
8
|
|
7
9
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.
|
10
|
-
spec.
|
11
|
-
spec.
|
12
|
-
spec.
|
10
|
+
spec.name = "dry-matcher"
|
11
|
+
spec.authors = ["Tim Riley", "Nikita Shilnikov"]
|
12
|
+
spec.email = ["tim@icelab.com.au", "fg@flashgordon.ru"]
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.version = Dry::Matcher::VERSION.dup
|
15
|
+
|
16
|
+
spec.summary = "Flexible, expressive pattern matching for Ruby"
|
17
|
+
spec.description = spec.summary
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-matcher"
|
19
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-matcher.gemspec", "lib/**/*"]
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = []
|
22
|
+
spec.require_paths = ["lib"]
|
13
23
|
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-matcher/blob/main/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-matcher"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-matcher/issues"
|
17
28
|
|
18
|
-
spec.
|
19
|
-
spec.bindir = 'exe'
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ['lib']
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
22
30
|
|
23
|
-
|
31
|
+
# to update dependencies edit project.yml
|
32
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
24
33
|
|
25
|
-
spec.
|
26
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency "rake"
|
27
35
|
end
|
data/lib/dry/matcher/case.rb
CHANGED
@@ -10,15 +10,11 @@ module Dry
|
|
10
10
|
# @param match [#call] callable used to test given pattern against value
|
11
11
|
# @param resolve [#call] callable used to resolve value into a result
|
12
12
|
def initialize(match: Undefined, resolve: DEFAULT_RESOLVE, &block)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
resolve.(value)
|
19
|
-
else
|
20
|
-
Undefined
|
21
|
-
end
|
13
|
+
@match = block || proc do |value, patterns|
|
14
|
+
if match.(value, *patterns)
|
15
|
+
resolve.(value)
|
16
|
+
else
|
17
|
+
Undefined
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "dry/core/deprecations"
|
4
|
+
require "dry/matcher/result_matcher"
|
5
5
|
|
6
6
|
module Dry
|
7
7
|
class Matcher
|
8
|
-
extend Dry::Core::Deprecations[:
|
8
|
+
extend Dry::Core::Deprecations[:"dry-matcher"]
|
9
9
|
|
10
10
|
EitherMatcher = ResultMatcher
|
11
11
|
|
12
|
-
deprecate_constant(:EitherMatcher, message:
|
12
|
+
deprecate_constant(:EitherMatcher, message: "Dry::Matcher::ResultMatcher")
|
13
13
|
end
|
14
14
|
end
|
@@ -5,7 +5,7 @@ module Dry
|
|
5
5
|
NonExhaustiveMatchError = Class.new(StandardError)
|
6
6
|
|
7
7
|
# {Evaluator} is used in {Dry::Matcher#call Dry::Matcher#call} block to handle different {Case}s
|
8
|
-
class Evaluator
|
8
|
+
class Evaluator
|
9
9
|
# @param [Object] result
|
10
10
|
# @param [Hash{Symbol => Case}] cases
|
11
11
|
def initialize(result, cases)
|
@@ -61,7 +61,8 @@ module Dry
|
|
61
61
|
|
62
62
|
def ensure_exhaustive_match
|
63
63
|
if @unhandled_cases.any?
|
64
|
-
::Kernel.raise NonExhaustiveMatchError,
|
64
|
+
::Kernel.raise NonExhaustiveMatchError,
|
65
|
+
"cases +#{@unhandled_cases.join(", ")}+ not handled"
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/matcher"
|
4
|
+
|
5
|
+
# rubocop:disable Style/CaseEquality
|
6
|
+
module Dry
|
7
|
+
class Matcher
|
8
|
+
PatternMatch = proc do |value, patterns|
|
9
|
+
if patterns.empty?
|
10
|
+
value
|
11
|
+
# rubocop:disable Lint/DuplicateBranch
|
12
|
+
elsif value.is_a?(::Array) && patterns.any? { |p| p === value[0] }
|
13
|
+
value
|
14
|
+
elsif patterns.any? { |p| p === value }
|
15
|
+
# rubocop:enable Lint/DuplicateBranch
|
16
|
+
value
|
17
|
+
else
|
18
|
+
Undefined
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# rubocop:enable Style/CaseEquality
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/matcher"
|
4
|
+
require "dry/matcher/match"
|
5
|
+
|
6
|
+
module Dry
|
7
|
+
class Matcher
|
8
|
+
# Built-in {Matcher} ready to use with `Maybe` monad from
|
9
|
+
# [dry-monads](/gems/dry-monads) or any other compatible gems.
|
10
|
+
#
|
11
|
+
# Provides {Case}s for two matchers:
|
12
|
+
# * `:some` matches `Dry::Monads::Maybe::Some`
|
13
|
+
# * `:none` matches `Dry::Monads::Maybe::None`
|
14
|
+
#
|
15
|
+
# @return [Dry::Matcher]
|
16
|
+
#
|
17
|
+
# @example Usage with `dry-monads`
|
18
|
+
# require 'dry/monads'
|
19
|
+
# require 'dry/matcher/maybe_matcher'
|
20
|
+
#
|
21
|
+
# value = Dry::Monads::Maybe.new('there is a value!')
|
22
|
+
#
|
23
|
+
# Dry::Matcher::MaybeMatcher.(value) do |m|
|
24
|
+
# m.some do |v|
|
25
|
+
# "Yay: #{v}"
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# m.none do
|
29
|
+
# "Boo: none"
|
30
|
+
# end
|
31
|
+
# end #=> "Yay: there is a value!"
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# @example Usage with specific types
|
35
|
+
# value = Dry::Monads::Maybe.new([200, :ok])
|
36
|
+
#
|
37
|
+
# Dry::Matcher::MaybeMatcher.(value) do |m|
|
38
|
+
# m.some(200, :ok) do |code, value|
|
39
|
+
# "Yay: #{value}"
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# m.none do
|
43
|
+
# "Boo: none"
|
44
|
+
# end
|
45
|
+
# end #=> "Yay: :ok"
|
46
|
+
#
|
47
|
+
MaybeMatcher = Dry::Matcher.new(
|
48
|
+
some: Case.new { |maybe, patterns|
|
49
|
+
if maybe.none?
|
50
|
+
Undefined
|
51
|
+
else
|
52
|
+
Dry::Matcher::PatternMatch.(maybe.value!, patterns)
|
53
|
+
end
|
54
|
+
},
|
55
|
+
none: Case.new { |maybe|
|
56
|
+
if maybe.some?
|
57
|
+
Undefined
|
58
|
+
end
|
59
|
+
}
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
@@ -1,21 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dry/matcher"
|
4
|
+
require "dry/matcher/match"
|
4
5
|
|
5
6
|
module Dry
|
6
7
|
class Matcher
|
7
|
-
match = ::Proc.new do |value, patterns|
|
8
|
-
if patterns.empty?
|
9
|
-
value
|
10
|
-
elsif value.is_a?(::Array) && patterns.any? { |p| p === value[0] }
|
11
|
-
value
|
12
|
-
elsif patterns.any? { |p| p === value }
|
13
|
-
value
|
14
|
-
else
|
15
|
-
Undefined
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
8
|
# Built-in {Matcher} ready to use with `Result` or `Try` monads from
|
20
9
|
# [dry-monads](/gems/dry-monads) or any other compatible gems.
|
21
10
|
#
|
@@ -30,7 +19,7 @@ module Dry
|
|
30
19
|
# @return [Dry::Matcher]
|
31
20
|
#
|
32
21
|
# @example Usage with `dry-monads`
|
33
|
-
# require 'dry/monads
|
22
|
+
# require 'dry/monads'
|
34
23
|
# require 'dry/matcher/result_matcher'
|
35
24
|
#
|
36
25
|
# value = Dry::Monads::Result::Success.new('success!')
|
@@ -85,7 +74,7 @@ module Dry
|
|
85
74
|
result = result.to_result
|
86
75
|
|
87
76
|
if result.success?
|
88
|
-
|
77
|
+
Dry::Matcher::PatternMatch.(result.value!, patterns)
|
89
78
|
else
|
90
79
|
Undefined
|
91
80
|
end
|
@@ -94,7 +83,7 @@ module Dry
|
|
94
83
|
result = result.to_result
|
95
84
|
|
96
85
|
if result.failure?
|
97
|
-
|
86
|
+
Dry::Matcher::PatternMatch.(result.failure, patterns)
|
98
87
|
else
|
99
88
|
Undefined
|
100
89
|
end
|
data/lib/dry/matcher/version.rb
CHANGED
data/lib/dry/matcher.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry/core/constants"
|
4
|
+
require "dry/matcher/case"
|
5
|
+
require "dry/matcher/evaluator"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
# @see http://dry-rb.org/gems/dry-matcher
|
@@ -78,7 +78,7 @@ module Dry
|
|
78
78
|
# after matched pattern
|
79
79
|
#
|
80
80
|
# @example Usage with `dry-monads`
|
81
|
-
# require 'dry/monads
|
81
|
+
# require 'dry/monads'
|
82
82
|
# require 'dry/matcher/result_matcher'
|
83
83
|
#
|
84
84
|
# value = Dry::Monads::Result::Failure.new('failure!')
|
data/lib/dry-matcher.rb
CHANGED
metadata
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
- Nikita Shilnikov
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-core
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0
|
20
|
+
version: '1.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0
|
27
|
+
version: '1.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '0'
|
42
42
|
description: Flexible, expressive pattern matching for Ruby
|
43
43
|
email:
|
44
44
|
- tim@icelab.com.au
|
@@ -47,42 +47,27 @@ executables: []
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- ".codeclimate.yml"
|
51
|
-
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
52
|
-
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
53
|
-
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
54
|
-
- ".github/workflows/ci.yml"
|
55
|
-
- ".github/workflows/docsite.yml"
|
56
|
-
- ".github/workflows/sync_configs.yml"
|
57
|
-
- ".gitignore"
|
58
|
-
- ".rspec"
|
59
|
-
- ".rubocop.yml"
|
60
|
-
- ".yardopts"
|
61
50
|
- CHANGELOG.md
|
62
|
-
- CODE_OF_CONDUCT.md
|
63
|
-
- CONTRIBUTING.md
|
64
|
-
- Gemfile
|
65
|
-
- Gemfile.devtools
|
66
51
|
- LICENSE
|
67
|
-
- LICENSE.md
|
68
52
|
- README.md
|
69
|
-
- Rakefile
|
70
|
-
- docsite/source/class-enhancement.html.md
|
71
|
-
- docsite/source/index.html.md
|
72
|
-
- docsite/source/result-matcher.html.md
|
73
53
|
- dry-matcher.gemspec
|
74
54
|
- lib/dry-matcher.rb
|
75
55
|
- lib/dry/matcher.rb
|
76
56
|
- lib/dry/matcher/case.rb
|
77
57
|
- lib/dry/matcher/either_matcher.rb
|
78
58
|
- lib/dry/matcher/evaluator.rb
|
59
|
+
- lib/dry/matcher/match.rb
|
60
|
+
- lib/dry/matcher/maybe_matcher.rb
|
79
61
|
- lib/dry/matcher/result_matcher.rb
|
80
62
|
- lib/dry/matcher/version.rb
|
81
|
-
-
|
82
|
-
homepage: http://dry-rb.org/gems/dry-matcher
|
63
|
+
homepage: https://dry-rb.org/gems/dry-matcher
|
83
64
|
licenses:
|
84
65
|
- MIT
|
85
|
-
metadata:
|
66
|
+
metadata:
|
67
|
+
allowed_push_host: https://rubygems.org
|
68
|
+
changelog_uri: https://github.com/dry-rb/dry-matcher/blob/main/CHANGELOG.md
|
69
|
+
source_code_uri: https://github.com/dry-rb/dry-matcher
|
70
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-matcher/issues
|
86
71
|
post_install_message:
|
87
72
|
rdoc_options: []
|
88
73
|
require_paths:
|
@@ -91,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
76
|
requirements:
|
92
77
|
- - ">="
|
93
78
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.
|
79
|
+
version: 2.7.0
|
95
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
81
|
requirements:
|
97
82
|
- - ">="
|
98
83
|
- !ruby/object:Gem::Version
|
99
84
|
version: '0'
|
100
85
|
requirements: []
|
101
|
-
rubygems_version: 3.1.
|
86
|
+
rubygems_version: 3.1.6
|
102
87
|
signing_key:
|
103
88
|
specification_version: 4
|
104
89
|
summary: Flexible, expressive pattern matching for Ruby
|
data/.codeclimate.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: "\U0001F41B Bug report"
|
3
|
-
about: See CONTRIBUTING.md for more information
|
4
|
-
title: ''
|
5
|
-
labels: bug
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
|
-
|
12
|
-
For more information see `CONTRIBUTING.md`.
|
13
|
-
|
14
|
-
**Describe the bug**
|
15
|
-
|
16
|
-
A clear and concise description of what the bug is.
|
17
|
-
|
18
|
-
**To Reproduce**
|
19
|
-
|
20
|
-
Provide detailed steps to reproduce, an executable script would be best.
|
21
|
-
|
22
|
-
**Expected behavior**
|
23
|
-
|
24
|
-
A clear and concise description of what you expected to happen.
|
25
|
-
|
26
|
-
**Your environment**
|
27
|
-
|
28
|
-
- Affects my production application: **YES/NO**
|
29
|
-
- Ruby version: ...
|
30
|
-
- OS: ...
|
@@ -1,18 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: "\U0001F6E0 Feature request"
|
3
|
-
about: See CONTRIBUTING.md for more information
|
4
|
-
title: ''
|
5
|
-
labels: feature
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
Summary of what the feature is supposed to do.
|
11
|
-
|
12
|
-
## Examples
|
13
|
-
|
14
|
-
Code examples showing how the feature could be used.
|
15
|
-
|
16
|
-
## Resources
|
17
|
-
|
18
|
-
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
data/.github/workflows/ci.yml
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
name: ci
|
4
|
-
|
5
|
-
on:
|
6
|
-
push:
|
7
|
-
paths:
|
8
|
-
- .github/workflows/ci.yml
|
9
|
-
- lib/**
|
10
|
-
- spec/**
|
11
|
-
- Rakefile
|
12
|
-
- Gemfile
|
13
|
-
- Gemfile.devtools
|
14
|
-
- "*.gemspec"
|
15
|
-
- ".rubocop.yml"
|
16
|
-
pull_request:
|
17
|
-
branches:
|
18
|
-
- master
|
19
|
-
|
20
|
-
jobs:
|
21
|
-
tests:
|
22
|
-
runs-on: ubuntu-latest
|
23
|
-
strategy:
|
24
|
-
fail-fast: false
|
25
|
-
matrix:
|
26
|
-
ruby:
|
27
|
-
- "2.7"
|
28
|
-
- "2.6"
|
29
|
-
- "2.5"
|
30
|
-
- "2.4"
|
31
|
-
- "jruby"
|
32
|
-
include:
|
33
|
-
- ruby: "2.6"
|
34
|
-
coverage: "true"
|
35
|
-
steps:
|
36
|
-
- uses: actions/checkout@v1
|
37
|
-
- name: Set up Ruby
|
38
|
-
uses: eregon/use-ruby-action@master
|
39
|
-
with:
|
40
|
-
ruby-version: ${{matrix.ruby}}
|
41
|
-
- name: Install latest bundler
|
42
|
-
run: |
|
43
|
-
gem install bundler
|
44
|
-
bundle config set without 'tools benchmarks docs'
|
45
|
-
- name: Bundle install
|
46
|
-
run: bundle install --jobs 4 --retry 3
|
47
|
-
- name: Run all tests
|
48
|
-
env:
|
49
|
-
COVERAGE: ${{matrix.coverage}}
|
50
|
-
CODACY_RUN_LOCAL: true
|
51
|
-
CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
|
52
|
-
run: bundle exec rake
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
name: docsite
|
4
|
-
|
5
|
-
on:
|
6
|
-
push:
|
7
|
-
paths:
|
8
|
-
- docsite/**
|
9
|
-
- .github/workflows/docsite.yml
|
10
|
-
branches:
|
11
|
-
- master
|
12
|
-
- release-**
|
13
|
-
tags:
|
14
|
-
|
15
|
-
jobs:
|
16
|
-
update-docs:
|
17
|
-
runs-on: ubuntu-latest
|
18
|
-
steps:
|
19
|
-
- uses: actions/checkout@v1
|
20
|
-
- name: Set up Ruby
|
21
|
-
uses: actions/setup-ruby@v1
|
22
|
-
with:
|
23
|
-
ruby-version: "2.6.x"
|
24
|
-
- name: Install dependencies
|
25
|
-
run: |
|
26
|
-
gem install bundler
|
27
|
-
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
-
- name: Symlink ossy
|
29
|
-
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
-
- name: Trigger dry-rb.org deploy
|
31
|
-
env:
|
32
|
-
GITHUB_LOGIN: dry-bot
|
33
|
-
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
-
run: bin/ossy github workflow dry-rb/dry-rb.org ci
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
name: sync_configs
|
4
|
-
|
5
|
-
on:
|
6
|
-
repository_dispatch:
|
7
|
-
|
8
|
-
jobs:
|
9
|
-
sync-configs:
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
if: github.event.action == 'sync_configs'
|
12
|
-
steps:
|
13
|
-
- uses: actions/checkout@v1
|
14
|
-
- name: Set up Ruby
|
15
|
-
uses: eregon/use-ruby-action@master
|
16
|
-
with:
|
17
|
-
ruby-version: 2.6
|
18
|
-
- name: Install latest bundler
|
19
|
-
run: |
|
20
|
-
gem install bundler
|
21
|
-
bundle config set without 'tools benchmarks docs'
|
22
|
-
- name: Install dependencies
|
23
|
-
run: bundle install --jobs 4 --retry 3 --without tools test benchmarks docs
|
24
|
-
- name: Symlink ossy
|
25
|
-
run: ln -sf "$(bundle info ossy --path)/bin/ossy" bin/ossy
|
26
|
-
- name: Clone devtools
|
27
|
-
run: git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
28
|
-
- name: Compile file templates
|
29
|
-
env:
|
30
|
-
GITHUB_LOGIN: dry-bot
|
31
|
-
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
32
|
-
run: |
|
33
|
-
if [ -f "project.yml" ]; then
|
34
|
-
for t in `ls tmp/devtools/templates`
|
35
|
-
do
|
36
|
-
bin/ossy t c tmp/devtools/templates/$t $(basename $t .erb) project.yml
|
37
|
-
done
|
38
|
-
fi
|
39
|
-
- name: Update configuration files from devtools
|
40
|
-
run: |
|
41
|
-
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
42
|
-
rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
43
|
-
else
|
44
|
-
rsync -arv tmp/devtools/shared/ . ;
|
45
|
-
fi
|
46
|
-
- name: Commit changes
|
47
|
-
run: |
|
48
|
-
rm bin/ossy
|
49
|
-
git config --local user.email "dry-bot@dry-rb.org"
|
50
|
-
git config --local user.name "dry-bot"
|
51
|
-
git add -A
|
52
|
-
git commit -m "[devtools] sync configs" || echo "nothing changed"
|
53
|
-
- name: Push changes
|
54
|
-
uses: ad-m/github-push-action@master
|
55
|
-
with:
|
56
|
-
github_token: ${{ secrets.GH_PAT }}
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
AllCops:
|
4
|
-
TargetRubyVersion: 2.4
|
5
|
-
|
6
|
-
Style/EachWithObject:
|
7
|
-
Enabled: false
|
8
|
-
|
9
|
-
Style/StringLiterals:
|
10
|
-
Enabled: true
|
11
|
-
EnforcedStyle: single_quotes
|
12
|
-
|
13
|
-
Style/ParallelAssignment:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Style/Alias:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Style/LambdaCall:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Style/StabbyLambdaParentheses:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/FormatString:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Style/Documentation:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Layout/SpaceInLambdaLiteral:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Layout/MultilineMethodCallIndentation:
|
35
|
-
Enabled: true
|
36
|
-
EnforcedStyle: indented
|
37
|
-
|
38
|
-
Metrics/LineLength:
|
39
|
-
Max: 100
|
40
|
-
|
41
|
-
Metrics/MethodLength:
|
42
|
-
Enabled: false
|
43
|
-
|
44
|
-
Metrics/ClassLength:
|
45
|
-
Enabled: false
|
46
|
-
|
47
|
-
Metrics/BlockLength:
|
48
|
-
Enabled: false
|
49
|
-
|
50
|
-
Metrics/AbcSize:
|
51
|
-
Max: 20
|
52
|
-
|
53
|
-
Metrics/CyclomaticComplexity:
|
54
|
-
Enabled: true
|
55
|
-
Max: 10
|
56
|
-
|
57
|
-
Lint/BooleanSymbol:
|
58
|
-
Enabled: false
|
59
|
-
|
60
|
-
Style/AccessModifierDeclarations:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
Style/BlockDelimiters:
|
64
|
-
Enabled: false
|
65
|
-
|
66
|
-
Layout/IndentFirstArrayElement:
|
67
|
-
EnforcedStyle: consistent
|
68
|
-
|
69
|
-
Style/ClassAndModuleChildren:
|
70
|
-
Exclude:
|
71
|
-
- "spec/**/*_spec.rb"
|
72
|
-
|
73
|
-
Lint/HandleExceptions:
|
74
|
-
Exclude:
|
75
|
-
- "spec/spec_helper.rb"
|
76
|
-
|
77
|
-
Naming/PredicateName:
|
78
|
-
Enabled: false
|
79
|
-
|
80
|
-
Naming/FileName:
|
81
|
-
Exclude:
|
82
|
-
- "lib/dry-*.rb"
|
83
|
-
|
84
|
-
Style/SymbolArray:
|
85
|
-
Exclude:
|
86
|
-
- "spec/**/*_spec.rb"
|
87
|
-
|
88
|
-
Style/ConditionalAssignment:
|
89
|
-
Enabled: false
|
90
|
-
|
91
|
-
Naming/MethodName:
|
92
|
-
Enabled: false
|
93
|
-
|
94
|
-
Style/AsciiComments:
|
95
|
-
Enabled: false
|
96
|
-
|
97
|
-
Style/DateTime:
|
98
|
-
Enabled: false
|
99
|
-
|
100
|
-
Style/IfUnlessModifier:
|
101
|
-
Enabled: false
|
data/.yardopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--markup=markdown
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
|
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
|
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
eval_gemfile 'Gemfile.devtools'
|
6
|
-
|
7
|
-
gemspec
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'dry-monads', '~> 1.2.0'
|
11
|
-
gem 'rspec', '~> 3.8'
|
12
|
-
end
|
13
|
-
|
14
|
-
group :tools do
|
15
|
-
gem 'yard'
|
16
|
-
gem 'byebug', platform: :mri
|
17
|
-
gem 'pry'
|
18
|
-
end
|
data/Gemfile.devtools
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
2
|
-
|
3
|
-
gem "ossy", github: "solnic/ossy", branch: "master", platforms: :ruby
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
gem 'codacy-coverage', require: false, platforms: :ruby
|
7
|
-
gem 'simplecov', require: false, platforms: :ruby
|
8
|
-
gem 'warning'
|
9
|
-
end
|
10
|
-
|
11
|
-
group :tools do
|
12
|
-
# this is the same version that we use on codacy
|
13
|
-
gem 'rubocop', '0.71.0'
|
14
|
-
end
|
data/LICENSE.md
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright © 2015-2016 [Icelab](http://icelab.com.au/).
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
-
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: Class enhancement
|
3
|
-
layout: gem-single
|
4
|
-
name: dry-matcher
|
5
|
-
---
|
6
|
-
|
7
|
-
You can offer a match block API from your own methods using `Dry::Matcher.for`:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
require "dry-matcher"
|
11
|
-
|
12
|
-
# First, build a matcher or use an existing one (like dry-matcher's ResultMatcher)
|
13
|
-
MyMatcher = Dry::Matcher.new(...)
|
14
|
-
|
15
|
-
# Offer it from your class with `Dry::Matcher.for`
|
16
|
-
class MyOperation
|
17
|
-
include Dry::Matcher.for(:call, with: MyMatcher)
|
18
|
-
|
19
|
-
def call
|
20
|
-
# return a value here
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# And now `MyOperation#call` offers the matcher block API
|
25
|
-
operation = MyOperation.new
|
26
|
-
|
27
|
-
operation.() do |m|
|
28
|
-
# Use the matcher's API here
|
29
|
-
end
|
30
|
-
```
|
@@ -1,89 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: Introduction
|
3
|
-
description: Expressive match API for operating on computation results
|
4
|
-
layout: gem-single
|
5
|
-
type: gem
|
6
|
-
name: dry-matcher
|
7
|
-
sections:
|
8
|
-
- class-enhancement
|
9
|
-
- result-matcher
|
10
|
-
---
|
11
|
-
|
12
|
-
dry-matcher offers flexible, expressive pattern matching for Ruby.
|
13
|
-
|
14
|
-
You can build your own matcher or use the out-of-the-box support for matching on [dry-monads](/gems/dry-monads) `Result` values.
|
15
|
-
|
16
|
-
## Building a matcher
|
17
|
-
|
18
|
-
To build your own matcher, create a series of "case" objects with their own resolving logic. First argument of the case block is the value to match, second argument is the list of patterns (see below). The block must either return the result or `Dry::Matcher::Undefined` if the has no match. The latter signals dry-matcher to try the next case.
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
require "dry-matcher"
|
22
|
-
|
23
|
-
# Match `[:ok, some_value]` for success
|
24
|
-
success_case = Dry::Matcher::Case.new do |(code, value), _|
|
25
|
-
if code.equal?(:ok)
|
26
|
-
value
|
27
|
-
else
|
28
|
-
# this is a constant from dry/core/constants
|
29
|
-
Dry::Matcher::Undefined
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Match `[:err, some_error_code, some_value]` for failure
|
34
|
-
failure_case = Dry::Matcher::Case.new do |(code, value), patterns|
|
35
|
-
if code.equal?(:err) && (patterns.empty? || patterns.include?(value))
|
36
|
-
value
|
37
|
-
else
|
38
|
-
Dry::Matcher::Undefined
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Build the matcher
|
43
|
-
matcher = Dry::Matcher.new(success: success_case, failure: failure_case)
|
44
|
-
```
|
45
|
-
|
46
|
-
Then use these cases as part of an API to match on results:
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
my_success = [:ok, "success!"]
|
50
|
-
|
51
|
-
result = matcher.(my_success) do |m|
|
52
|
-
m.success do |v|
|
53
|
-
"Yay: #{v}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# :not_found and :lost are patterns
|
57
|
-
m.failure :not_found, :lost do |v|
|
58
|
-
"Oops, not found: #{v}"
|
59
|
-
end
|
60
|
-
|
61
|
-
m.failure do |v|
|
62
|
-
"Boo: #{v}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
result # => "Yay: success!"
|
67
|
-
```
|
68
|
-
|
69
|
-
Cases are executed in order. The first match wins and halts subsequent matching.
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
my_failure = [:err, :not_found, "missing!"]
|
73
|
-
|
74
|
-
result = matcher.(my_failure) do |m|
|
75
|
-
m.success do |v|
|
76
|
-
"Yay: #{v}"
|
77
|
-
end
|
78
|
-
|
79
|
-
m.failure :not_found do |v|
|
80
|
-
"Oops, not found: #{v}"
|
81
|
-
end
|
82
|
-
|
83
|
-
m.failure do |v|
|
84
|
-
"Boo: #{v}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
result # => "Oops, not found: missing!"
|
89
|
-
```
|
@@ -1,34 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: Result matcher
|
3
|
-
layout: gem-single
|
4
|
-
name: dry-matcher
|
5
|
-
---
|
6
|
-
|
7
|
-
dry-matcher provides a ready-to-use `ResultMatcher` for working with `Result` or `Try` monads from [dry-monads](/gems/dry-monads) or any other compatible gems.
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
require "dry/monads/result"
|
11
|
-
require "dry/matcher/result_matcher"
|
12
|
-
|
13
|
-
value = Dry::Monads::Success("success!")
|
14
|
-
|
15
|
-
result = Dry::Matcher::ResultMatcher.(value) do |m|
|
16
|
-
m.success(Integer) do |i|
|
17
|
-
"Got int: #{i}"
|
18
|
-
end
|
19
|
-
|
20
|
-
m.success do |v|
|
21
|
-
"Yay: #{v}"
|
22
|
-
end
|
23
|
-
|
24
|
-
m.failure :not_found do |_err, reason|
|
25
|
-
"Nope: #{reason}"
|
26
|
-
end
|
27
|
-
|
28
|
-
m.failure do |v|
|
29
|
-
"Boo: #{v}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
result # => "Yay: success!"
|
34
|
-
```
|
data/project.yml
DELETED