These are chat archives for dry-rb/chat

12th
Jul 2016
Mateusz Karbowiak
@trnks__twitter
Jul 12 2016 07:03
hey, should I expect from Dry::Validation.Schema to coerce data to given type?
Tim Riley
@timriley
Jul 12 2016 07:08
No, it doesn’t do that, @trnks__twitter
Dry::Validation.Form does, however
Mateusz Karbowiak
@trnks__twitter
Jul 12 2016 07:11
and while creating nested validations with Dry::Validation.Form do I still write required(:foo).schema do; required(:bar).filled(:str?); end ?
teju_chile
@tejaswinichile
Jul 12 2016 07:47
How can I test the validations on console, As I am trying to play with it.
John Backus
@backus
Jul 12 2016 08:34
@solnic dry-rb/dry-types#108 is updated
Piotr Solnica
@solnic
Jul 12 2016 08:37
@trnks__twitter usage is exactly the same from the DSL pov
the only diff is that plain Schema doesn’t have the input processing step prior validation
Piotr Solnica
@solnic
Jul 12 2016 10:09
@tejaswinichile try Dry::Validation.Schema { required(:name).filled(:str?) }.call(name: nil).messages
Mateusz Karbowiak
@trnks__twitter
Jul 12 2016 12:18
@solnic thanks!
teju_chile
@tejaswinichile
Jul 12 2016 13:38
@solnic got it, thank you, it worked
Piotr Solnica
@solnic
Jul 12 2016 19:20
wdyt about renaming Dry::Validation.Form to Dry::Validation.Params? not a great general name but in ruby world params are typically used in rack-based frameworks so…
renaming or adding Params I should say
John Backus
@backus
Jul 12 2016 20:42
I've needed this in multiple projects. I think it should be a default predicate
module MyProject
  module Predicates
    include Dry::Logic::Predicates

    # Based on https://en.wikipedia.org/wiki/Whitespace_character#Unicode
    # Matches official ASCII and Unicode whitespace as well as characters
    # which are effectively whitespace characters
    effective_whitespace = "\u200B\u200C\u200D\u2060\uFEFF"
    WHITESPACE_PATTERN = /\A[[:space:]#{effective_whitespace}]*\z/

    def self.contains_text?(string)
      WHITESPACE_PATTERN !~ string
    end
    predicate(:contains_text?, &public_method(:contains_text?))
  end
end
I imagine it might be like text? or something in dry-validation
but basically it is the equivalent of !String#blank? in ActiveSupport
but it takes a few more liberties (that dry-v might not take) for things that are not defined as whitespace but effectively are (for example the "mongolian vowel separator")
John Backus
@backus
Jul 12 2016 20:51
Consequence is that, otherwise, we get required(:foo).filled(:str?) lets through " " which is often not something we want
John Backus
@backus
Jul 12 2016 20:59
Any opinion on whether this belongs in dry-v or not @solnic?
Piotr Solnica
@solnic
Jul 12 2016 21:12
@backus pls report an issue. This needs some discussion