These are chat archives for dry-rb/chat

5th
Mar 2016
Piotr Solnica
@solnic
Mar 05 2016 17:05
Good news everybody - I just merged refactor branch into master in dry-validation. I still have a couple of smaller clean ups to do, but overall it’s ready for testing. If you’d like to give it a go you also need dry-types and dry-logic from master, so just add those to Gemfile. I’ll release all three gems once dry-types refactor is done. Need a couple more days to do so :)
Michał Pietrus
@blelump
Mar 05 2016 17:13
@solnic , hi! Any API major changes ?

I remember you've said some days ago, that with new API such approach will be possible:

rule(:user_inactive, user_active?: [:email])
rule(:password_invalid, password_valid?: [:email, :password])

where rule password_invalid doesn't fire if user_inactive is invalid. Am I right? :smiley:

Piotr Solnica
@solnic
Mar 05 2016 17:22
@blelump yeah it’s a rewrite so lots of API changes
I didn’t make this specific syntax work yet, but it’s gonna be possible now
right now sth like that should work:
rule(:password_invalid) do
  value(:email).user_active? & value(:email).password_valid?(value(:password))
end
in this case password_valid? will receive :email and :password as args
Piotr Solnica
@solnic
Mar 05 2016 17:28
I think user_active?(value(:email)) would work too, but I gotta check that
uhm, no, that won’t work
but it should be possible ;)
Michał Pietrus
@blelump
Mar 05 2016 17:30
OK! let me try this value(:email).user_active? & value(:email).password_valid?(value(:password)) :-)
Piotr Solnica
@solnic
Mar 05 2016 17:34
btw you can reach into nested structures too by providing a path to a value using an array
so ie value([:foo, :bar, :baz]) will read value from input[:foo][:bar][:baz]
Michał Pietrus
@blelump
Mar 05 2016 17:37
uhm , nice!
how shall I deal with password confirmation ? The old way (confirmation(:password)) seems to be incorrect , because of NoMethodError
@blelump just like that ^
Michał Pietrus
@blelump
Mar 05 2016 17:55
@solnic , got into that undefined method 'visit_check' for #<Dry::Validation::InputTypeCompiler> from:
rule(:user_inactive) do
  value(:email).user_active?
end
to recreate:
require 'bundler'
Bundler.require

Blah = Class.new(Dry::Validation::Schema::Form) do

  key(:email) { filled? }

  rule(:ok) do
    value(:email).custom_validation_method
  end
  def custom_validation_method(param) true; end
end

Blah.new.()
Piotr Solnica
@solnic
Mar 05 2016 18:05
@blelump k, I’ll fix that
Michał Pietrus
@blelump
Mar 05 2016 18:10
thx :-)
btw. I recognize this new syntax e.g. key(:password).required(:filled?, min_size?: 3).confirmation as more intuitive
Piotr Solnica
@solnic
Mar 05 2016 18:19
cool :)
@blelump try again (pull from master), I just fixed that crash
Michał Pietrus
@blelump
Mar 05 2016 18:24
@solnic , thanks, it works! However, now I've got another issue :-)
when you change def custom_validation_method(param) true; end to def custom_validation_method(param) false; end it raises with lib/dry/validation/error_compiler/input.rb:52:invisit_predicate': undefined method %' for nil:NilClass (NoMethodError)
I suppose it's missing a translation
Piotr Solnica
@solnic
Mar 05 2016 18:25
yeah that’s a nasty way of saying “you are missing a message for this rule"
I’ll be polishing this kind of stuff now before the release
Michał Pietrus
@blelump
Mar 05 2016 18:26
sure
Piotr Solnica
@solnic
Mar 05 2016 18:26
just add en.errors.password_invalid to messages config
I gotta run :wave: :)
Michał Pietrus
@blelump
Mar 05 2016 18:27
OK , thanks, cya !
Michał Pietrus
@blelump
Mar 05 2016 18:56

@solnic , one more thing, the old API provisioned errors in such format: :email=>[["email size cannot be less than 30"], "blah@wp.pl"] whereas now it's more like :email=>["email size cannot be less than 3"] so the error msg structure is flat.

I wonder if it's final solution, because I'm using dry-validation as a validation engine within reform gem, where it extracts message from the previous schema format and crashes finally.

That's a minor issue, however I'd be glad to know, so I can deal with it and switch to the new syntax :-)

Piotr Solnica
@solnic
Mar 05 2016 19:01
it is final
Michał Pietrus
@blelump
Mar 05 2016 19:02
OK, thanks!
Piotr Solnica
@solnic
Mar 05 2016 19:03
the way you define schema class will change too, it’ll be a block-based API, probably sth like Dry.Validation do .. end
and it’s gonna return a schema object
and this is gonna be the final step prior release
Michał Pietrus
@blelump
Mar 05 2016 19:04
I see, well I'll have to deal with it then
Piotr Solnica
@solnic
Mar 05 2016 19:06
yeah reform will have to be updated to make it work again with dry-v
Michał Pietrus
@blelump
Mar 05 2016 19:07
I think that shouldn't be an issue, I suppose thats kinda refactoring work
:-)
Hannes Nevalainen
@kwando
Mar 05 2016 22:37
@solnic block based API makes sense, I already got a wrapper in place to do that for me (along with some other things) =P
Piotr Solnica
@solnic
Mar 05 2016 23:17
@kwando which api? Everything is block based :)