These are chat archives for dry-rb/chat

3rd
Dec 2015
Hannes Nevalainen
@kwando
Dec 03 2015 08:50 UTC
@solnic I'd like to inject a custom "key mapper" function to a form validation schema
for instance if my input hash has uppercase keys I would like the mapper to downcase them
Hannes Nevalainen
@kwando
Dec 03 2015 08:57 UTC
class MySchema < Dry::Validation::Schema::Form
  key(:database_url){ |f| f.filled? }
end

schema = MySchema.new(key_map: -> x { x.to_s.downcase })
schema.call({'DATABASE_URL' => '<url to database>'}).params #=> {database_url: '<url to database>'}
Piotr Solnica
@solnic
Dec 03 2015 09:00 UTC
@kwando sorry schema is not a data mapper
Hannes Nevalainen
@kwando
Dec 03 2015 09:04 UTC
buzz, wrong answer
=P
I understand =)
Piotr Solnica
@solnic
Dec 03 2015 09:07 UTC
I'd give you a better explanation but I'm not feeling well today so my brain is kind of partially working
Hannes Nevalainen
@kwando
Dec 03 2015 09:12 UTC
@solnic no worries =)
take care, do some rest
Piotr Solnica
@solnic
Dec 03 2015 09:57 UTC
That is my plan
Vojtěch Kusý
@wojtha
Dec 03 2015 13:27 UTC
Hi there. I finally found gitter chat for DryRb :) big :+1: for all the components.
I've played with AutoInject last night and created 3 more DI strategies for it. What do you guys @solnic @AMHOL think?
Andy Holland
@AMHOL
Dec 03 2015 13:45 UTC
@wojtha not sure about the getter/setter inject, but the key inject is something me and @solnic have discussed in the past
Was thinking of an interface more like include MyApp::Inject(messenger: 'message.store') myself
Would be good to see what @solnic thinks though
I haven't really worked on that gem
Vojtěch Kusý
@wojtha
Dec 03 2015 13:48 UTC
Yeah. Hash init came to my mind as well. But for now I sticked with AutoInject's default init.
For getter/setter: these are fallbacks for Rails controllers or similar objects as I wrote in the description.
Where constructor DI is impossible
But I think that setter DI is better than no DI at all...
Kind of shade of gray :smile:
Andy Holland
@AMHOL
Dec 03 2015 14:17 UTC
Ahh, sorry, I understand a bit better now, didn't have time to read the gist properly before
They all seem viable to me
Vojtěch Kusý
@wojtha
Dec 03 2015 14:20 UTC
Cool thx @AMHOL. I'll wait on @solnic final word before I start to work on PR and tests.
Andy Holland
@AMHOL
Dec 03 2015 14:20 UTC
:+1: