- Update dry-core dependency (via #34) (@pnomolos)
- MaybeMatcher for matching against Maybe values from dry-monads (@gabfssilva) in #33
- This version is compatible with recently released dry-rb dependencies (@flash-gordon)
- Matcher evaluator is now a standard
Object
descendant (see #32) (@solnic)
- Delegation warnings about keyword arguments (flash-gordon)
- Minimal dry-core version set to 0.4.8 (flash-gordon)
-
Dry::Matcher#for
is a shortcut forDry::Matcher.for(..., with: matcher)
(flash-gordon)require 'dry/matcher/result_matcher' class CreateUser include Dry::Matcher::ResultMatcher.for(:call) def call(...) # code returning an instance of Dry::Monads::Result end end
-
API for cases was changed to work with a single block instead of
match
/resolve
combination (flash-gordon in #23):Dry::Matcher::Case.new do |value, patterns| if patterns.include?(value) # value will be passed to the block value else # Undefined stands for no match Dry::Matcher::Undefined end end
-
ResultMatcher
now uses patterns for matching and matches against the first element if an array is passed (flash-gordon in #24 and #22 and michaelherold in #21)value = Dry::Monads::Result::Failure.new([:invalid, :reasons]) Dry::Matcher::ResultMatcher.(value) do |m| m.success do |v| "Yay: #{v}" end m.failure(:not_found) do "No such thing" end m.failure(:invalid) do |_code, errors| "Cannot be done: #{errors.inspect}" end end #=> "Cannot be done: :reasons"
- [BREAKING] Support for Ruby 2.3 was dropped as it's EOL
EitherMatcher
was renamed toResultMatcher
according to match the rename ofEither
toResult
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)
- API documentation for most methods (alsemyonov in #8)
- Fixed handling of calls to non-existent cases within a matcher block (timriley)
- 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)
Dry::Matcher::Case
objects can now be created without aresolve:
proc. In this case, a default will be provided that passes the result value through (timriley in #9)
-
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)
# Match `[:ok, some_value]` for success success_case = Dry::Matcher::Case.new( match: -> value { value.first == :ok }, resolve: -> value { value.last } ) # Match `[:err, some_error_code, some_value]` for failure failure_case = Dry::Matcher::Case.new( match: -> value, *pattern { value[0] == :err && (pattern.any? ? pattern.include?(value[1]) : true) }, resolve: -> value { value.last } ) # Build the matcher matcher = Dry::Matcher.new(success: success_case, failure: failure_case) # Then put it to use my_success = [:ok, "success!"] result = matcher.(my_success) do |m| m.success do |v| "Yay: #{v}" end m.failure :not_found do |v| "Oops, not found: #{v}" end m.failure do |v| "Boo: #{v}" end end result # => "Yay: success!"
-
Renamed to
dry-matcher
, since this is now a flexible, general purpose pattern matching API. All components are now available under theDry::Matcher
namespace. (timriley) -
Dry::Matcher.for
requires a matcher object to be passed when being included in a class:MyMatcher = Dry::Matcher.new(...) class MyOperation include Dry::Matcher.for(:call, with: MyMatcher) def call end end
-
The previous
Dry::ResultMatcher.match
behaviour (for matchingEither
monads) has been moved toDry::Matcher::EitherMatcher.call
- Support convertible result objects responding to
#to_either
(ttdonovan)
- Expect monads from dry-monads instead of Kleisli (ttdonovan)
- Renamed to
dry-result_matcher
. Match results usingDry::ResultMatcher.match
or extend your own classes withDry::ResultMatcher.for
.
- Added
EitherResultMatcher.for(*methods)
to return a module wrapping the specified methods (returning anEither
) with the match block API. Example usage, in a class with a#call
method:include EitherResultMatcher.for(:call)
.
Initial release.