dry-matcher 0.9.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b0215bfb6c841e25bcd167ebf29b6dd05c642926c04bb253cabe5a3d430ee27
4
- data.tar.gz: 6a69936b8ce9b3edfd22653c0e358f8c6d1149064a74782661b8a251e306ba86
3
+ metadata.gz: e15710ea8633875555598d31ceab3d2641338ee7cbcb637f97fd707df05c05c2
4
+ data.tar.gz: c946fa6d1670575a51df6a9c18ee1ab561e0d932a64938b2acb61c5e8486bc22
5
5
  SHA512:
6
- metadata.gz: a0641213eab8f65143040b0c6a61913415822e34fa985ff68a3efae84e4a21ffeb04675ad4ba5aaf7476cfd7d4bc89128f5faec7d705d36f8d262a0b131d2c76
7
- data.tar.gz: 5b42966da62e0b5665ca89c20aaef62683a9e52e4fae91ae4eb852f9e2900f417800f5ce5ca82ccf3e5403d39ce54af7862942e7ee4fda12215eee297450c21f
6
+ metadata.gz: 941a39cfa94574429caf39efdaf2670f41bcdf6043ad64f7417d68ad97ea66f78b33990b9ed51a5d6fefd43ab75c7ffc0fe12a97d41a97bc7804271746f7e6f8
7
+ data.tar.gz: 33df73d85c7bb1c11d66a1b33b22d90025cf5efb27c0e42125d014861cc224915ee02ca87b0040f6b2576beee80dc85fcfd8ae5c96554c39636e93e57c386f4c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.0.0 2023-01-01
4
+
5
+
6
+ ### Changed
7
+
8
+ - Update dry-core dependency (via #34) (@pnomolos)
9
+
10
+ [Compare v0.10.0...v1.0.0](https://github.com/dry-rb/dry-matcher/compare/v0.10.0...v1.0.0)
11
+
12
+ ## 0.10.0 2022-11-16
13
+
14
+
15
+ ### Added
16
+
17
+ - MaybeMatcher for matching against Maybe values from dry-monads (@gabfssilva) in #33
18
+
19
+ ### Changed
20
+
21
+ - This version is compatible with recently released dry-rb dependencies (@flash-gordon)
22
+
23
+ [Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-matcher/compare/v0.9.0...v0.10.0)
24
+
3
25
  ## 0.9.0 2021-03-05
4
26
 
5
27
 
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-2023 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,28 +1,21 @@
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
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-matcher
4
- [chat]: https://dry-rb.zulipchat.com
5
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-matcher
6
4
 
7
- # dry-matcher [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
-
9
- [![Gem Version](https://badge.fury.io/rb/dry-matcher.svg)][gem]
10
- [![CI Status](https://github.com/dry-rb/dry-matcher/workflows/ci/badge.svg)][actions]
11
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f09a7d1745fd430d829a1f825357db88)][codacy]
12
- [![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]
5
+ # dry-matcher [![Gem Version](https://badge.fury.io/rb/dry-matcher.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-matcher/workflows/ci/badge.svg)][actions]
14
6
 
15
7
  ## Links
16
8
 
17
- * [User documentation](http://dry-rb.org/gems/dry-matcher)
9
+ * [User documentation](https://dry-rb.org/gems/dry-matcher)
18
10
  * [API documentation](http://rubydoc.info/gems/dry-matcher)
11
+ * [Forum](https://discourse.dry-rb.org)
19
12
 
20
13
  ## Supported Ruby versions
21
14
 
22
15
  This library officially supports the following Ruby versions:
23
16
 
24
- * MRI >= `2.5`
25
- * jruby >= `9.2`
17
+ * MRI `>= 2.7.0`
18
+ * jruby `>= 9.4` (not tested on CI)
26
19
 
27
20
  ## License
28
21
 
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", "< 2"
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 = '1.0.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,15 +1,15 @@
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: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Riley
8
8
  - Nikita Shilnikov
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-05 00:00:00.000000000 Z
12
+ date: 2023-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-core
@@ -17,20 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.4'
21
- - - ">="
20
+ version: '1.0'
21
+ - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: 0.4.8
23
+ version: '2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: '0.4'
31
- - - ">="
30
+ version: '1.0'
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.8
33
+ version: '2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -62,6 +62,8 @@ files:
62
62
  - lib/dry/matcher/case.rb
63
63
  - lib/dry/matcher/either_matcher.rb
64
64
  - lib/dry/matcher/evaluator.rb
65
+ - lib/dry/matcher/match.rb
66
+ - lib/dry/matcher/maybe_matcher.rb
65
67
  - lib/dry/matcher/result_matcher.rb
66
68
  - lib/dry/matcher/version.rb
67
69
  homepage: https://dry-rb.org/gems/dry-matcher
@@ -69,10 +71,10 @@ licenses:
69
71
  - MIT
70
72
  metadata:
71
73
  allowed_push_host: https://rubygems.org
72
- changelog_uri: https://github.com/dry-rb/dry-matcher/blob/master/CHANGELOG.md
74
+ changelog_uri: https://github.com/dry-rb/dry-matcher/blob/main/CHANGELOG.md
73
75
  source_code_uri: https://github.com/dry-rb/dry-matcher
74
76
  bug_tracker_uri: https://github.com/dry-rb/dry-matcher/issues
75
- post_install_message:
77
+ post_install_message:
76
78
  rdoc_options: []
77
79
  require_paths:
78
80
  - lib
@@ -80,15 +82,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
- version: 2.5.0
85
+ version: 2.7.0
84
86
  required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  requirements:
86
88
  - - ">="
87
89
  - !ruby/object:Gem::Version
88
90
  version: '0'
89
91
  requirements: []
90
- rubygems_version: 3.1.4
91
- signing_key:
92
+ rubygems_version: 3.4.1
93
+ signing_key:
92
94
  specification_version: 4
93
95
  summary: Flexible, expressive pattern matching for Ruby
94
96
  test_files: []