dry-matcher 0.9.0 → 0.10.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/CHANGELOG.md +9 -0
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-matcher.gemspec +15 -14
- data/lib/dry/matcher/case.rb +5 -9
- data/lib/dry/matcher/either_matcher.rb +4 -4
- data/lib/dry/matcher/evaluator.rb +2 -1
- 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 +1 -1
- metadata +9 -13
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,5 +1,14 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
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
|
+
|
3
12
|
## 0.9.0 2021-03-05
|
4
13
|
|
5
14
|
|
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
|
[][actions]
|
11
12
|
[][codacy]
|
12
13
|
[][codacy]
|
13
|
-
[][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,34 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# this file is managed by dry-rb/devtools project
|
3
2
|
|
4
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
5
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require
|
7
|
+
require "dry/matcher/version"
|
7
8
|
|
8
9
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
+
spec.name = "dry-matcher"
|
10
11
|
spec.authors = ["Tim Riley", "Nikita Shilnikov"]
|
11
12
|
spec.email = ["tim@icelab.com.au", "fg@flashgordon.ru"]
|
12
|
-
spec.license =
|
13
|
+
spec.license = "MIT"
|
13
14
|
spec.version = Dry::Matcher::VERSION.dup
|
14
15
|
|
15
16
|
spec.summary = "Flexible, expressive pattern matching for Ruby"
|
16
17
|
spec.description = spec.summary
|
17
|
-
spec.homepage =
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-matcher"
|
18
19
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-matcher.gemspec", "lib/**/*"]
|
19
|
-
spec.bindir =
|
20
|
+
spec.bindir = "bin"
|
20
21
|
spec.executables = []
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
22
23
|
|
23
|
-
spec.metadata[
|
24
|
-
spec.metadata[
|
25
|
-
spec.metadata[
|
26
|
-
spec.metadata[
|
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"
|
27
28
|
|
28
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
29
30
|
|
30
31
|
# to update dependencies edit project.yml
|
31
|
-
spec.add_runtime_dependency "dry-core", "~>
|
32
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
32
33
|
|
33
34
|
spec.add_development_dependency "rake"
|
34
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
|
@@ -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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
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
|
@@ -17,20 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.4.8
|
20
|
+
version: '1.0'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
25
|
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '0
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.4.8
|
27
|
+
version: '1.0'
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
29
|
name: rake
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +56,8 @@ files:
|
|
62
56
|
- lib/dry/matcher/case.rb
|
63
57
|
- lib/dry/matcher/either_matcher.rb
|
64
58
|
- lib/dry/matcher/evaluator.rb
|
59
|
+
- lib/dry/matcher/match.rb
|
60
|
+
- lib/dry/matcher/maybe_matcher.rb
|
65
61
|
- lib/dry/matcher/result_matcher.rb
|
66
62
|
- lib/dry/matcher/version.rb
|
67
63
|
homepage: https://dry-rb.org/gems/dry-matcher
|
@@ -69,7 +65,7 @@ licenses:
|
|
69
65
|
- MIT
|
70
66
|
metadata:
|
71
67
|
allowed_push_host: https://rubygems.org
|
72
|
-
changelog_uri: https://github.com/dry-rb/dry-matcher/blob/
|
68
|
+
changelog_uri: https://github.com/dry-rb/dry-matcher/blob/main/CHANGELOG.md
|
73
69
|
source_code_uri: https://github.com/dry-rb/dry-matcher
|
74
70
|
bug_tracker_uri: https://github.com/dry-rb/dry-matcher/issues
|
75
71
|
post_install_message:
|
@@ -80,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
76
|
requirements:
|
81
77
|
- - ">="
|
82
78
|
- !ruby/object:Gem::Version
|
83
|
-
version: 2.
|
79
|
+
version: 2.7.0
|
84
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
81
|
requirements:
|
86
82
|
- - ">="
|
87
83
|
- !ruby/object:Gem::Version
|
88
84
|
version: '0'
|
89
85
|
requirements: []
|
90
|
-
rubygems_version: 3.1.
|
86
|
+
rubygems_version: 3.1.6
|
91
87
|
signing_key:
|
92
88
|
specification_version: 4
|
93
89
|
summary: Flexible, expressive pattern matching for Ruby
|