Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 18:02
    ekremkaraca starred dry-rb/dry-system
  • 11:13
    dilcom commented #375
  • 10:29
    flash-gordon commented #375
  • 10:08
    wuarmin starred dry-rb/dry-configurable
  • 10:02
    dilcom commented #375
  • 10:02
    dilcom commented #375
  • 08:11
    flash-gordon commented #375
  • 07:54
    flash-gordon commented #115
  • 05:40
    wpzero starred dry-rb/dry-monads
  • 05:30
    dilcom opened #375
  • 02:18
    johnmaxwell edited #115
  • 02:18
    johnmaxwell edited #115
  • Dec 08 23:10
    johnmaxwell labeled #115
  • Dec 08 23:10
    johnmaxwell opened #115
  • Dec 07 14:03

    dry-bot on master

    [devtools] config sync (compare)

  • Dec 07 10:01
    Travis dry-rb/dry-view (master) errored (636)
  • Dec 07 09:58
    Travis dry-rb/dry-view (master) errored (635)
  • Dec 07 09:56

    dry-bot on master

    [devtools] config sync (compare)

  • Dec 07 09:56

    dry-bot on master

    [devtools] config sync (compare)

  • Dec 07 09:56

    dry-bot on master

    [devtools] config sync (compare)

Nick Sutterer
@apotonick
@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
and the schema definition contains validation logic, also
and how will a DateTime coercion/parsing will be done on a Schema object :/
Piotr Solnica
@solnic
@ivobenedito use Dry::Validation.JSON and add type expections, like date_time? etc. it will infer coercions from that and try to apply them
I’d do something like this:
UserSchema = Dry::Validation.JSON do
  required(:created_at).value(:date_time?)
end

class User < Dry::Struct
  attribute :created_at, Types::Strict::DateTime
end

user_attrs = UserSchema.(user_data)

User.new(user_attrs)
in 1.0.0 dry-validation will support infering schemas from struct definitions, for now you need to have it defined explicitly in both places
Ivo Benedito
@ivobenedito
and that JSON validation enforces the coercion? cool
Screen Shot 2016-10-14 at 17.33.33.png
this is the service object where I'm trying to inject that Schema logic you're talking about
so that you understand the context a little better
Piotr Solnica
@solnic
@ivobenedito aah so the structure is different (camel-cases keys)
anyhow, yes it will enforce coercions
Ivo Benedito
@ivobenedito
yah ... camel-cased but I don't want to make the case switch automatically
Piotr Solnica
@solnic
why do you have a guard for an empty string? is it an allowed value?
Ivo Benedito
@ivobenedito
the external API is returning unexpected values in some cases
let's say ... users that never logged in, the last_sign_in_at datetime doesn't exist
don't even know if I just tell the API owners to returning an empty field or just skip the field on the response
Piotr Solnica
@solnic
yeah this is exactly why I recommend using schemas instead of just blindly passing input to domain structs
so, uhm, you can do all sorts of things to make it easier to work with potentially garbage-data
unfortunately JSON schemas don’t turn empty strings to nils
(Form schemas do)
I’ve been thinking about changing that, it’s not gonna be pedantically correct, but it’d be very pragmatic
if you need more control over input and coercions, you can turn on explicit type specs, and define custom types where you need them