flash-gordon on master
Add missing test for a default … Merge pull request #424 from dr… (compare)
flash-gordon on test_default_with_undefined
waiting-for-dev on test_default_with_undefined
Add missing test for a default … (compare)
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?
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
Classtype constraint. When using rspec, I want to pass in a double for the object. But an rspec double does not have type class. Have you ever run into this? What was your workaround?
Webservices = Types::Strict::Array(Types::Instance(Webservice))
services = Types::Webservices[some_array]