You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to propose adding pattern matching to some of the core classes of http, primarily deconstruct_keys, to allow for matching against things like Responses and Requests.
Consider:
responsein{status: 200..299,body: /Header I want/}caseresponsein{status: 200..299,body: }thenSuccess(body)in{status: 300..,body: }thenFailure(body)elseFailure('unknown')end
This is just a theoretical example and may not be 100% accurate to the API, but I wanted to run things by the core team before implementing this as it ends up being a decent amount of additional code.
It should be noted that adding the interfaces (deconstruct and deconstruct_keys) will be backward compatible, but testing it with pattern matching will not be.
The text was updated successfully, but these errors were encountered:
baweaver
added a commit
to baweaver/http
that referenced
this issue
Jan 19, 2021
Resolves feature request httprb#642 requesting the addition of Pattern
Matching hooks for Ruby 2.7+ by introducing `to_h`, `deconstruct`, and
`deconstruct_keys` to core classes.
This change also addresses spec changes by gating pattern matching specs
on Ruby 2.7+ to prevent failures in older versions. All specs have also
been given a pattern matching spec matching their implementation to
demonstrate potential usages.
While demonstrational usages could dive into nested classes that are in
`HTTP` this was avoided to keep tests isolated from eachother.
I'd like to propose adding pattern matching to some of the core classes of
http
, primarilydeconstruct_keys
, to allow for matching against things like Responses and Requests.Consider:
This is just a theoretical example and may not be 100% accurate to the API, but I wanted to run things by the core team before implementing this as it ends up being a decent amount of additional code.
It should be noted that adding the interfaces (
deconstruct
anddeconstruct_keys
) will be backward compatible, but testing it with pattern matching will not be.The text was updated successfully, but these errors were encountered: