These are chat archives for dry-rb/chat

29th
Nov 2015
Hannes Nevalainen
@kwando
Nov 29 2015 12:32
This message was deleted
class UserSchema < Dry::Validation::Schema
  key(:age) do |age|
    age.filled? & age.int? & age.gt?(18) & age.lt?(100)
  end
end
@solnic ^^ that should work right?
Krzysztof Wawer
@wafcio
Nov 29 2015 12:33
@kwando how do you invoke this schema ?
Hannes Nevalainen
@kwando
Nov 29 2015 12:34
UserSchema.new.messages(user)
Krzysztof Wawer
@wafcio
Nov 29 2015 12:34
what is user ?
Hannes Nevalainen
@kwando
Nov 29 2015 12:34
a hash
Krzysztof Wawer
@wafcio
Nov 29 2015 12:35
ok but can you give example how this hash looks ?
Hannes Nevalainen
@kwando
Nov 29 2015 12:35
though the input is not there problem, it blows up when compiling the rules
the* problem
/dry-validation-185ec9d6959d/lib/dry/validation/rule_compiler.rb:48:in `visit_and': undefined method `&' for #<Dry::Validation::Rule::Conjunction:0x007fc95b01ef10> (NoMethodError)
Krzysztof Wawer
@wafcio
Nov 29 2015 12:36
in 0.1.0 I don’t have this problem
Hannes Nevalainen
@kwando
Nov 29 2015 12:37
ok, I use master.. probably not a very good idea =P
Krzysztof Wawer
@wafcio
Nov 29 2015 12:37
I am not fun of using version from master because it can be unstable. For me stable versions are tagged versions
Hannes Nevalainen
@kwando
Nov 29 2015 12:38
I do not really think there is a "stable" version yet though =P
Piotr Solnica
@solnic
Nov 29 2015 12:50
@kwando there was an issue with nil? predicate, I had to rename it to none? to avoid conflicts with the built-in nil? method on Object
btw I just added support for optional values
Hannes Nevalainen
@kwando
Nov 29 2015 12:51
Dry::Rule::Composite is missing & | methods
Piotr Solnica
@solnic
Nov 29 2015 12:51
so ie key(:age) { |age| age.none? | (age.int? & age.gt?(18)) } this is translated to a coercion that will turn empty strings to nils
in Schema::Form
this is an explicit way of handling nil and optional values
@kwando oh, lemme fix that
I need to do it properly though, we have a very specific rule interface but I haven’t added shared specs for that, so we have some holes like you found :)
lemme brew some coffee and fix this situation :)
btw thanks guys for testing this so early, I appreciate that a lot <3
Hannes Nevalainen
@kwando
Nov 29 2015 13:03
np really, thanks for "fixing" ruby =) <3
Piotr Solnica
@solnic
Nov 29 2015 13:39
@kwando I’m afraid I can’t fix that part, my C skills don’t exist :joy:
@kwando anyhow, I can’t repro issue with missing & and | in composite
it inherits from Rule so it has these interfaces
@kwando do you have a repro?
Hannes Nevalainen
@kwando
Nov 29 2015 14:00
hmm, I must have used a old version somehow =S
173a2e407ff9e652c3cb26932474375f5bcfa482 had the error
Hannes Nevalainen
@kwando
Nov 29 2015 14:16
@solnic sneaky, you fixed it while splitting rules to separate files =P
Piotr Solnica
@solnic
Nov 29 2015 14:20
@kwando huh?
oh lol
I know what happened
composite class def was before methods on abstract rule were defined
now it’s after
lol :)
well, at least I added missing specs :)
Piotr Solnica
@solnic
Nov 29 2015 16:47

[√] support for built-in form coercions based on type-check predicates
[√] support for optional keys
[√] support for optional values
[√] support for passing a block to predicates in dsl

^^ @kwando @wafcio gonna release those features today :)

Andy Holland
@AMHOL
Nov 29 2015 16:58
Piotr Solnica
@solnic
Nov 29 2015 16:58
@AMHOL no, I didn’t see it :/
Andy Holland
@AMHOL
Nov 29 2015 16:59
Ahh OK
It just removes messages and adds a compiler for returning an errors hash
So messages/i18n would become an external concern
Piotr Solnica
@solnic
Nov 29 2015 17:33
@AMHOL error hash?
Andy Holland
@AMHOL
Nov 29 2015 17:35
Yeah, like: { attribute: [{code: :gt?, value: 1, options: { num: 3 }}] }
Wanted to see what you thought about it before I did anything more with it
Just seems weird to me for a validation library to load yaml files and stuff
Piotr Solnica
@solnic
Nov 29 2015 17:38
nested hashes will be more difficult to process. I'm also not sure if making the assumption that errors are always "attached" to a specific attribute will turn out to be correct in the longer term
Andy Holland
@AMHOL
Nov 29 2015 17:40
Ahh OK