dry-matcher 0.9.0 → 0.10.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
  SHA256:
3
- metadata.gz: 2b0215bfb6c841e25bcd167ebf29b6dd05c642926c04bb253cabe5a3d430ee27
4
- data.tar.gz: 6a69936b8ce9b3edfd22653c0e358f8c6d1149064a74782661b8a251e306ba86
3
+ metadata.gz: 70aa7037f519f35f5c9c29206d0529fe452a5e0b08268f6d7d0884846e74bfa5
4
+ data.tar.gz: c5022a321698bfff91e04688bc2c4b09487dff1c47902ade7005d6384745df2f
5
5
  SHA512:
6
- metadata.gz: a0641213eab8f65143040b0c6a61913415822e34fa985ff68a3efae84e4a21ffeb04675ad4ba5aaf7476cfd7d4bc89128f5faec7d705d36f8d262a0b131d2c76
7
- data.tar.gz: 5b42966da62e0b5665ca89c20aaef62683a9e52e4fae91ae4eb852f9e2900f417800f5ce5ca82ccf3e5403d39ce54af7862942e7ee4fda12215eee297450c21f
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2022 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
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=master)][inchpages]
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](http://dry-rb.org/gems/dry-matcher)
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 >= `2.5`
25
- * jruby >= `9.2`
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
- lib = File.expand_path('lib', __dir__)
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 'dry/matcher/version'
7
+ require "dry/matcher/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-matcher'
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 = 'MIT'
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 = 'https://dry-rb.org/gems/dry-matcher'
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 = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-matcher/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-matcher'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-matcher/issues'
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.5.0"
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", "~> 0.4", ">= 0.4.8"
32
+ spec.add_runtime_dependency "dry-core", "~> 1.0"
32
33
 
33
34
  spec.add_development_dependency "rake"
34
35
  end
@@ -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
- if block
14
- @match = block
15
- else
16
- @match = proc do |value, patterns|
17
- if match.(value, *patterns)
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 'dry/core/deprecations'
4
- require 'dry/matcher/result_matcher'
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[:'dry-matcher']
8
+ extend Dry::Core::Deprecations[:"dry-matcher"]
9
9
 
10
10
  EitherMatcher = ResultMatcher
11
11
 
12
- deprecate_constant(:EitherMatcher, message: 'Dry::Matcher::ResultMatcher')
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, "cases +#{@unhandled_cases.join(', ')}+ not handled"
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 'dry/matcher'
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/result'
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
- match.(result.value!, patterns)
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
- match.(result.failure, patterns)
86
+ Dry::Matcher::PatternMatch.(result.failure, patterns)
98
87
  else
99
88
  Undefined
100
89
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  class Matcher
5
- VERSION = '0.9.0'
5
+ VERSION = "0.10.0"
6
6
  end
7
7
  end
data/lib/dry/matcher.rb CHANGED
@@ -78,7 +78,7 @@ module Dry
78
78
  # after matched pattern
79
79
  #
80
80
  # @example Usage with `dry-monads`
81
- # require 'dry/monads/result'
81
+ # require 'dry/monads'
82
82
  # require 'dry/matcher/result_matcher'
83
83
  #
84
84
  # value = Dry::Monads::Result::Failure.new('failure!')
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.9.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: 2021-03-05 00:00:00.000000000 Z
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.4'
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.4'
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/master/CHANGELOG.md
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.5.0
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.4
86
+ rubygems_version: 3.1.6
91
87
  signing_key:
92
88
  specification_version: 4
93
89
  summary: Flexible, expressive pattern matching for Ruby