These are chat archives for dry-rb/chat

Nov 2016
Alexey Zapparov
Nov 30 2016 00:38
Hi all. Is there a way to define custom coercion type for schema?
I have an endpoint that accepts list of ids separated with comma, so i want to do something like:
schema = Dry::Validation.Form do
  required(:ids) { comma_separated_list? }
end{ "ids" => "1,2,3" })["ids"] # => ["1", "2", "3"]
Tim Riley
Nov 30 2016 10:26
@ixti Sounds like something that type specs ( and a custom type would help you achieve
e.g. something like required(:ids, Types::MyCommaSeparatedList).filled(:array?)
where that MyCommaSeparatedList type would accept string input and coerce it into an array
Alexey Zapparov
Nov 30 2016 20:30
@timriley mm, yeah. that will definitely work for me indeed. Thanks!
Alexey Zapparov
Nov 30 2016 20:40
Was it considered change API a bit? like instead of Dry::Validation.Form it would be better to write Dry::Validation::Form.describe imho :D
I'm OK with current API. It just looks a bit awkward to me :D
As awkward as when I see someone uses :: to call method