These are chat archives for dry-rb/chat
I want a type to represent a non empty string, is there a builtin for this or should I just do:
NonEmptyString = Types::Strict::String.constrained( format: /\S+/ )
In Dry::Validation, is there a way to define a custom error message for a rule block, that isn't composed of messages from the individual predicates used in the block? I have a form where I want to enforce a checkbox only if the birthdate given in another field is for a person under 18:
rule(acknowledge_age_if_young: [:acknowledge_age, :birth_date]) do |acknowledge_age, birth_date| birth_date.older?(18) | acknowledge_age.true? end
But the automatic error message is a join of the older?-message and the true?-message, with " or " as the delimiter: "must be older than 18 or must be true". I can customize each of these messages, but I don't see how/if I can use a message without an " or ". Basically I just wan't to say "You need to check this box if you're not 18".
Could someone clarify for me the purpose of
user_type = Types.Constructor(User) # It is equivalent to User.new(name: 'John') user_type[name: 'John’]
What is the differentce between
user_type — other than that you can construct with
Types.Instance makes sense to me, since we’re checking that the value passed is an instance of a certain class. But what are we checking with a constructor type?
Dry::Struct. By use case I meant, an example of a dry struct that would need an attribute with a contructor type. I’m having trouble connecting the idea to something that would come up in my work.
separate question: Is there a better (more concise) way to achieve the equivalent of the following using dry::struct or dry::types:
class Webservices include Enumerable extend Forwardable TYPE = Types.Array(Types.Instance(Webservice)) def initialize(arr) @arr = TYPE[arr] end def_delegators :@arr, :each end
Note: I want to be able to construct using a single, unnamed parameter as in
Essentially, I want a typed array constructible using