We are expanding our usage of
dry-types (as well as the rest of the ecosystem) and I have a question on how to enforce a specific type.
Basically I want to check that the given type is an
ActiveRecord model that was
I tried this:
Model = Types::Instance(ApplicationRecord) Persisted = Types::Any.constructor do |input| unless input.respond_to?(:persisted?) && input.persisted? raise Dry::Types::ConstraintError.new(:persisted?, input) end input end PersistedModel = Model >> Persisted
I think that a union type would be the best solution for both constraints (saw some conversation here).
I also tried to play around with some custom predicates due to this comment without much luck mostly.
I don’t know how correct is the use of
Function for this kind of scenario. I couldn’t find any documentation so sorry if it’s somewhere.