Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Nick Sutterer
@apotonick
hey @timriley i have a question about dry-auto_inject (again), because i decided we're not using dry-initializer (we don't need coercion, types, etc. at this point), but we simply have two arguments initialize(params, options) where options are all the dependencies injected
now i have two things
  1. how would i extend Ai to "eat" the two-arg version params, options? (i think you hinted this twice already)
  2. can we change Ai to not add any readers but only merge the auto-injected parameters into the options hash? that would all happen on the class-level
Nick Sutterer
@apotonick
@timriley i see that i might have to write my own strategy. fine with that, but you gotta help me!!! :tea:
Yurii Danyliak
@yuriidanyliak
Hey guys! Just a quick question: is there some ability to use dry-validation output with form_for or deliver the results of validation to front-end in some elegant way?
Nick Sutterer
@apotonick
@yuriidanyliak yes, with reform!
Yurii Danyliak
@yuriidanyliak
Hello @apotonick ! Yes, already read about reform-rails. Is there any way to use schema output with reform?
Nick Sutterer
@apotonick
schema "output", what is that?
you can use reform with dry-validation, it's pretty amazing
Yurii Danyliak
@yuriidanyliak
Sorry, going to clarify.
Nick Sutterer
@apotonick
;)
Yurii Danyliak
@yuriidanyliak
UserSchema.call({}).output :)

you can use reform with dry-validation, it's pretty amazing

Great, OK then!

Will try, thanks Nick! BTW: you had great presentation at #pivorak!
Nick Sutterer
@apotonick
oh thanks :blush: it was a fantastic audience, really!
Yurii Danyliak
@yuriidanyliak
:blush: have a nice weekend
Nick Sutterer
@apotonick
go try reform, i can help you with everything, but @fran-worley is our pro
Yurii Danyliak
@yuriidanyliak
Ok )
Tim Riley
@timriley
@apotonick if I don't have a new baby at start of the work, I'll see if I can take a quick stab at a strategy for you
Nick Sutterer
@apotonick
@timriley :heart_eyes: so, i would basically not implement define_initializer, right?
my initializer looks like
def initialize(params, options)
  @options = options #this is the dependency hash
end
so i kinda want to avoid the overriding from Ai
because we don't need separate instance variables per dependency, i store them all in one hash
@yuriidanyliak what does Schema#output do?
Yurii Danyliak
@yuriidanyliak
output's result of validation, those data that passed the validation of schema
@apotonick, usually using like
validation = schema.call(params)
validation.success? ? validation.output : validation.messages
Tim Riley
@timriley
Yeah, looks like you could skip defining the initializer, @apotonick
Nick Sutterer
@apotonick
@timriley i'll play with it now and let ya know
@yuriidanyliak ok, but what's the meaning of "output" in this specific case?
Fran Worley
@fran-worley
@apotonick output gives you pack your params
Nick Sutterer
@apotonick
i see
so basically form.sync
Fran Worley
@fran-worley
Not its used after validation and just literally returns params. More like form.to_nested_hash
Nick Sutterer
@apotonick
here we go
Fran Worley
@fran-worley
:) it's a dry-validation method that we don't use in reform.
Piotr Solnica
@solnic
Please use Result#to_h instead of output
Ivo Benedito
@ivobenedito
hey guys!
starting to try to replace my Virtus addiction by dry-types 😜
I have a domain object that maps a remote API resource object ... and for example some of the attributes are DateTime instances
& for example, the responsability of coercion for DateTime values should be done outside of the object itself?
Ivo Benedito
@ivobenedito
just asking, because if I run something like: class User < Dry::Struct; attribute :created_at, Types::DateTime; end; User.new(created_at: "2016-10-06T10:03:03.785Z")
it won't coerce anything and will just put a string on the object state
Piotr Solnica
@solnic
@ivobenedito use dry-validation schema to process data before passing it to your structs
Ivo Benedito
@ivobenedito
@solnic I'm really interested in shifting to dry-rb, but I'm finding it to be a little hard to read and find docs / blog posts about how to connect all this sub-modules together
Piotr Solnica
@solnic
@ivobenedito just apply schema validation to api input, and pass result to struct constructor, there’s no need to “connect” anything
User.new(schema.call(some_data_from_api)) <= just this
of course validation can fail so you may want to handle this however you want
Ivo Benedito
@ivobenedito
yeah I've understood that, it's a great tip thx
but that forces the schema to be defined twice somehow, right?
on the struct, and on the schema definition