pmackay
September 20, 2017, 4:24pm
1
I’m new to dry-rb. Is there an equivalent using dry-types of creating a custom type derived from Virtus::Attribute? Specifically how to reproduce this example using dry-rb?
Or, how to do eqivalent of these https://github.com/solnic/virtus#custom-coercions .
Thanks!
I thinks something like this might do (not tested, and will likely to fail if input is anything other than an array):
ArrayOfSchools = Dry::Types::Definition
.new(Array)
.constructor { |input| School.find(input.reject(&:blank?)) }
Not sure that Dry::Types::Definition
API is considered public though.
I added docs about the helpers we have for building custom types http://dry-rb.org/gems/dry-types/custom-types/ . They are available in 0.12+
1 Like