These are chat archives for dry-rb/chat

2nd
Oct 2017
Markus Unterwaditzer
@untitaker
Oct 02 2017 15:13
@flash-gordon done at dry-rb/dry-struct#53
Nikita Shilnikov
@flash-gordon
Oct 02 2017 15:44
:heart:
Aaron Jensen
@aaronjensen
Oct 02 2017 22:14
How does dry-validation work w/ strong_parameters? It seems that if you pass a strong param hash to dry-validation it will validate it, but then to_h will still return a strong param hash that can't actually be used (unless you actually do strong param's require(...).permit(...)
Nikita Shilnikov
@flash-gordon
Oct 02 2017 22:23
it makes sense to bypass strong parameters completely because it adds nothing to what dry-validation already does, at least in rails 4.2 it can be done with params.to_unsafe_h but the API may have changed
Aaron Jensen
@aaronjensen
Oct 02 2017 22:23
is there a way to do that as part of all of our validations?
the dsl makes it very unclear how to extend it override something like #call
Nikita Shilnikov
@flash-gordon
Oct 02 2017 22:26
hm, what's the problem with #call? A simple proc object will do the trick since it has just the same interface
i.e. schema_that_accepts_strong_parameters = proc { |params| schema.call(params.to_unsafe_h) }
Aaron Jensen
@aaronjensen
Oct 02 2017 22:46
yeah, the problem is i don't want to wrap every schema i create another function call
Ideally i could just MySchema do ... end
Nikita Shilnikov
@flash-gordon
Oct 02 2017 22:48
def AppNamespace.Schema(&block)
  schema = Dry::Validation.Schema(&block)
  -> params { schema.(params.to_unsafe_h) }
end
@aaronjensen ^
Aaron Jensen
@aaronjensen
Oct 02 2017 22:49
ok, thanks!