Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Nikita Shilnikov
@flash-gordon
@jonahx we do have one https://github.com/solnic/transproc
Jonah
@jonahx
@flash-gordon exactly! thank you. i knew dry-rb would have this solved :)
Jonah
@jonahx
how can i build a custom type to verify not that an object is an instance of certain class, but that it conforms to a specific interface, ie, has methods :a, :b, and :c defined on it, eg?
Jonah
@jonahx

separate question: is it possible to specify a custom error message when a constraint is violated. eg, consider:

  URI = Types::Strict::String.constrained(format: URI::regexp)

when this is violated, the message includes the very long URI regexp. it would be nice if I could specify the message as “The string does not match URI::regexp”

Nikita Shilnikov
@flash-gordon
there's no way to enforce presence of methods with dry-types, I'm also not sure this makes sense in general
in a way, dry-types targets data, not objects
and for producing nice messages there's dry-validation
Jonah
@jonahx

@flash-gordon thanks.

in a way, dry-types targets data, not objects

would it be fair to say that in “the dry rb way,” object dependencies would be handled with the auto-injector, and data dependencies would be handles with dry-struct / dry-types?

and for producing nice messages there's dry-validation

yeah, my question was specifically about the type error messages. it’s a small point, not really important.

Nikita Shilnikov
@flash-gordon
@jonahx I'm not sure if the term "data dependencies" has any concrete definition but yes, probably :)
dry-types intentionally has no control over error messages
Jonah
@jonahx
@flash-gordon i just meant youd pass them in as args defined by dry::struct attributes
Nico Ritschel
@nicosuave
Is there a sane way to define self-referential validations with dry-validation?
I am hoping to validate a tree structure for use with a search endpoint (for more context)
Ryan Bigg
@radar
@flash-gordon Could we please get a new release of dry-core that contains my patch from here? dry-rb/dry-core@cf36cbb. I have a few readers of Exploding Rails reporting an issue that I believe would be fixed by this gem release.
Nikita Shilnikov
@flash-gordon
@radar thanks for reminding me, as I said I need to test it first, shouldn't be a problem so gonna do it today, I'll ping you back
Ryan Bigg
@radar
:D Thank you! I'm about to go sleep here in kangaland.
Nikita Shilnikov
@flash-gordon
g'night =)
Nikita Shilnikov
@flash-gordon
@radar just pushed v0.4.6
Guilherme Moreira
@gmmoreira
@nicosuave do you mean a schema that use another schema? If so, yes, it's possible.
Michael Deol
@michaeldeol
@nicosuave :wave:
Nico Ritschel
@nicosuave
@gmmoreira I was hoping for a schema to reference itself (in a circular fashion)
@michaeldeol :wave:
Michael Deol
@michaeldeol
Nico Ritschel
@nicosuave
@michaeldeol I'm trying to validate a tree, so it would be nice to reference the current schema itself in a call to schema
Roland Laurès
@ShamoX
Hi, I'm trying to use dry-validation and dry-struct together and got into a versions little problem.
Do you think that a new version of dry-validation will come up using dry-types 0.13 ? (I saw the master referee t it already)
I have then some warnings, but I don't know if I should open an issue or just discuss it in here.
Tim Riley
@timriley
@ShamoX I think we’re planning to release something within the next month or so
Roland Laurès
@ShamoX
ok, so I just wait ^^. Thanks @timriley
Also, what I'm doing is to mix both Struct and Validation into one class object that create the Validation schema inside the Class object and when instantiating a new object will first validate the hash and then pass it to Struct.new. If validation doesn't pass, it then raise a ValidationError containing all the messages of the Validation::Schema result (I use call). I don't know if it's worth sharing.
Nikita Shilnikov
@flash-gordon
better to keep this concerns separated, validations usually happen on the edge of a system, rejecting invalid input as early as possible
mixing them usually end up with cumbersome code
Roland Laurès
@ShamoX
Yeah, maybe you are right, I should perhaps consider keeping my data in the Hash instead of creating objects arborescence. But it's also a way to document and clarify a complexe interleaved/nested data model.
Nikita Shilnikov
@flash-gordon
typical workflow: raw data (aka params, json) -> validation schema -> hash (usually) -> (init a struct | persist data). It usually turns out documenting complex cases through tests works better :)
Roland Laurès
@ShamoX
I see, right point
(Maybe my thought are deformed by Rails model)
Roland Laurès
@ShamoX
Yes, with your workflow, I just have to add an other step verifying the consistency of the data once it's in the struct, and then I can convert/treat it. Thanks for the tips.
Spencer Goh
@dymaxionuk
in dry-web if I wanted to plug in a differnt logger, eg for rolling file, where would I bestdo this? Should I just register this in my web.rb or what? Woudl this be picked up by dry-monitor also, or do I have to do it in a certain order/place for it to be injected correctly into dry-monitor?
Igor S. Morozov
@Morozzzko
Hey everyone!
I’ve been wondering: what does dry-types need to be released as 1.0? Seems mature enough now
ojab
@ojab
Oh hai! Is there any way to create recursive type definitions with dry-types? I want to use Hash with value that is the Hash itself, so something like
hash = Dry::Types['hash'].schema({})
hash = hash.schema(hash: hash)
but in this case value is the initial hash without any members
ojab
@ojab
…and actually more general case of circular dependencies is also can't be described
so

something like

first = Dry::Types['hash'].schema({})
second = Dry::Types['hash'].schema(first: first)
first = first.schema(second: second)

cannot be described either

ojab
@ojab
Is there any way to wrap dry-struct constructor into custom code? I want to pass XML from Nokogiri instead of Hash (which would be converted to Hash) to .new and doing this outside of constructor is quite unwieldy, since there can be nested structs. I can hack up some module/class that will return Dry::Struct instance on .new, but I'm sure that there is better way.
Nikita Shilnikov
@flash-gordon
this doesn't sound like a job for dry-struct
but you can create your own class on top of Dry::Struct and override .new, I don't think there's anything better
and imo shouldn't be
transformation should handled separately. Probably, if you have something super simple then overriding .new is fine
ojab
@ojab
Why overriding/wrapping constructor is wrong? It's just a XML -> Hash coercion IMO, and coercions are handled by constructors.