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
This is a design issue I'm not sure how to tackle. It seems as though there will invariably be situations where there are Types::Instance or Types::Constructor types for which the (lower-cased, last segment of the) class name matches a predicate (as is the case with URI).
I understand that inferring predicates based on class name has been deprecated, though it isn't clear to me why I would have ever wanted this or what these were even used for. All I want (for now) is a type based on the URI class, and the predicate-inferring behaviour is interfering with that. This was first an issue in dry-rb/dry-schema#335 and I appreciate the workaround in #414 but it seems like I am going to have to monitor my code for breaking upstream changes when the workaround itself is deprecated.
Moreover, I know that one is supposed to invoke Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false to eliminate this deprecation error, but it seems to me like this kind of thing would make more sense to have localized by the individual type as opposed to blanket behaviour for all types.
To Reproduce
moduleMy# make a types modulemoduleTypesincludeDry::Types()# make a URI typeURI=Types.Constructor(::URI)do |x|
beginout= ::URI.parse(x)rescue ::URI::InvalidURIError=>eraiseDry::Types::CoercionError.neweendoutendend# make a schemaConfig=Dry::Schema.Paramsdo# include uri type; this will predictably complainrequired(:base).valueTypes::URIendend
Describe the bug
This is a design issue I'm not sure how to tackle. It seems as though there will invariably be situations where there are
Types::Instance
orTypes::Constructor
types for which the (lower-cased, last segment of the) class name matches a predicate (as is the case withURI
).I understand that inferring predicates based on class name has been deprecated, though it isn't clear to me why I would have ever wanted this or what these were even used for. All I want (for now) is a type based on the
URI
class, and the predicate-inferring behaviour is interfering with that. This was first an issue in dry-rb/dry-schema#335 and I appreciate the workaround in #414 but it seems like I am going to have to monitor my code for breaking upstream changes when the workaround itself is deprecated.Moreover, I know that one is supposed to invoke
Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false
to eliminate this deprecation error, but it seems to me like this kind of thing would make more sense to have localized by the individual type as opposed to blanket behaviour for all types.To Reproduce
Expected behavior
I'm not sure what exact mechanism would make the most sense but attaching the predicate-inferring state to the individual type objects seems like it could work:
…then pick that up in
Dry::Schema
or whatever.My environment
Ruby 2.7 or 3.1 (depending on the machine) and all newest releases of
dry-rb
modules.The text was updated successfully, but these errors were encountered: