Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 21 13:13

    solnic on v0.14.0

    (compare)

  • Jan 21 13:10

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 13:09

    solnic on master

    Bump dry-system to 0.14.0 (compare)

  • Jan 21 13:08

    solnic on master

    Update changelog.yml (compare)

  • Jan 21 10:31

    solnic on docsite-0.15

    (compare)

  • Jan 21 10:31

    solnic on docsite-1.0

    (compare)

  • Jan 21 10:17
    Travis dry-rb/dry-view (master) errored (706)
  • Jan 21 10:14
    jchapron starred dry-rb/dry-types
  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 21 10:13

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 20 21:48
    Travis dry-rb/dry-view (master) errored (705)
  • Jan 20 21:44

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 20 21:44

    dry-bot on master

    [devtools] sync configs (compare)

Piotr Solnica
@solnic
I hope so :laughing:
Darcy Laycock
@Sutto
The Rubyconf AU organisers are usually pretty fantastic at having all basses covered haha
Piotr Solnica
@solnic
oh yes they are amazing
Tim Riley
@timriley
@solnic FYI: I’m working on updating the dry-web-roda generators
Pat Collins
@patcoll
If I want to validate a list of email addresses at a particular key, what would be the syntax to do that?
Jonah
@jonahx
I’m trying to create a custom form validation. I got the validation part working but not sure how to customize the coercion part automatically. Here’s what I have so far:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.new < Date.parse(value)
    end
  end
  required(:date).filled(:future_date?)
end
Piotr Solnica
@solnic
@jonahx filled(:date?, :future_date?)
Jonah
@jonahx
@solnic ah, so simple. ty sir!
@solnic but say i needed to coerce to some custom object, MyCustomObj. is this easily possible too?
Piotr Solnica
@solnic
@jonahx why?
Jonah
@jonahx
@solnic, i’m not sure i understand the question. why do you coerce into built-in ruby objects like Date or Integer?
Piotr Solnica
@solnic
why you want to coerce to a custom object :)
Jonah
@jonahx
i’ll make an example, since my current example the above works well :). but say user enters a hex value for a color into a form. i want to validate it’s a valid hex value and coerce into a custom Color object that has some nice methods for working with colors, say.
Piotr Solnica
@solnic
do you need a color object for something else than the validation?
Jonah
@jonahx
yeah the “domain” code that uses the params is what would use it. So no, the Color wouldn’t be used within the validation.
Piotr Solnica
@solnic
@jonahx you can do this for more control http://dry-rb.org/gems/dry-validation/input-preprocessing/
explicit type specs will be default API in 1.0.0 btw
Jonah
@jonahx
@solnic thx for link i will reread that part. one more quick question is there a quick way to define error messages without going through a custom yaml file? eg, in this case i only need to define a single error message for this one custom future_date? method and i’d prefer to define it in code near where future_date itself is defined
I guess we should document this
Jonah
@jonahx
@solnic cool, ty. i was just in the midst of using pry to try to figure that out :), you saved me some minutes. i’d even recommend a chrome method over that , but that might be a micro-optimization
Jonah
@jonahx
@solnic I’m getting an uninitialized constanct Messages error:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.today < value
    end
    def self.messages
      Messages.default.merge(
        en: { errors: { future_date?: 'Date must be in the future' } }
      )
    end
  end
  required(:date).filled(:date?, :future_date?)
end
i thought it was because i was in Form instead of Schema but Schema isn’t working for me either...
Jonah
@jonahx
@solnic finally got it working. not sure if it’s the best way or why the way in your spec didn’t work for me, but the following works:
schema = Dry::Validation.Form do
  configure do
    def future_date?(value)
      Date.today < value
    end
    def self.messages
      default_messages.merge(
        en: { errors: { future_date?: 'Date must be in the future' } }
      )
    end
  end
  required(:date).filled(:date?, :future_date?)
end
Piotr Solnica
@solnic
@jonahx IIRC we have include Dry::Validation in spec_helper there heh
which is probably a stupid idea
Jonah
@jonahx
@solnic do i have the Piotr stamp of approval on what I did above? :)
Piotr Solnica
@solnic
@jonahx does it work? :D
Jonah
@jonahx
@solnic it does! i think it would be better to merge on messages rather than default_messages, but you get infinite recursion doing that...
Piotr Solnica
@solnic
it’s tricky stuff
defo a focus for 1.0.0
(to improve it)
Jonah
@jonahx
ok thx. for my immediate purposes this is totally fine, so nbd
Piotr Solnica
@solnic
cool
I’m not a fan of defining user-facing things in code, hence I didn’t add any nice way of defining custom messages inside code
it’s possible, but I don’t like it
I get that people often just need the quick’n’dirty solution though
and adding a special yaml file is not always desirable
I just didn’t have the need for a different approach than a yaml file because my context has been always an app with locales, where I keep dry-v’s messages
Jonah
@jonahx
@solnic fair enough. i agree in most apps of any size at all a yaml file is a better way to go. i just happen to making literally a single page form tool
Piotr Solnica
@solnic
sure thing, I’m not against it, so if somebody can make it better, then great
fwiw hanami-validation has a way of defining messages along with a predicate definition
IIRC sth like predicate(:foo?, message: “oh noez”) do.. end
Jonah
@jonahx
@solnic meh, i prefer your tools :)
Piotr Solnica
@solnic
it’s based on dry-v (as its validation engine)
but thanks :D
Jonah
@jonahx
@solnic can you set the Error message when a Dry::Types constraint fails?
Piotr Solnica
@solnic
@jonahx no, constraints != validation
Jonah
@jonahx
@solnic if i define a custom email type, which say just requires an @ symbol, why wouldn’t you want to be able to throw a custom message if someone tries to create an instance with bad data: “An email just have an ‘@‘ symbol”. How is that not an improvement upon a generic message about a contraint violation or whatnot?
Piotr Solnica
@solnic
@jonahx custom type constraints have different semantics than validation, they crash your system when something is invalid, validation is meant to process whole input and provide information about what validation rule violations.