Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Aaron Barthel
@abrthel
it's been awhile since I've used dry transaction but I do seem to remember there was a way to handle the failed branch.
As for deleting a record from the DB I imagine a much safer method would be wrapping the transaction in a DB transaction using 'around steps'
Jaromír Červenka
@Cervajz
Got it, I am going to look in to that, thanks
Jonah
@jonahx
Curious if anyone here has used this gem and, if so, what you thought of it: https://github.com/egonSchiele/contracts.ruby
Aaron Barthel
@abrthel
That's ironic, just looked at this gem like 20 minutes ago. Personally I like to do something like https://silkandspinach.net/2011/05/23/contract-tests-in-rspec/ instead of a contracts gem
As well I've gotten alot of mileage out of dry-types as a way to quickly --parse-- validate method inputs along with the idea of guarding the borders of my code and not the hinterlands :)
Jo-Herman Haugholt
@huyderman
Any timescale for when a new version of dry-validation will be released? Started updating my code for the breaking changes in dry-types and dry-struct, but don't really want to merge a dependency on master :/
(I'm terrible at remembering to change stuff like that back later...)
Adam Daniels
@adam12
^ I'm also curious of this as well.
Nikita Shilnikov
@flash-gordon
second half of May
Daniel Sandbecker
@daniels
What is the status of the type_specs option in dry-validation. The documentation page exists and explains that the syntax is experimental, but as far as I can tell it is not linked from the menu nor any of the other documentation pages. Yet the documentation page for input pre-processing, which has its own spot in the menu, makes use of the feature without explaining how it works. And there seems to be many quite long standing issues related to the feature. Please note that my intention is not to complain nor asking that somebody looks into all the issues, I'm just curious whether this feature is "official" or not.
Piotr Solnica
@solnic
@daniels type specs will be default behavior in 1.0.0. Bugs will be fixed but not in 0.x version
Jonah
@jonahx

is there a good ruby gem for transforming hash structures in a declarive, functional way. eg, consider this code I just wrote:

    feed = ParsedFeedjiraFeed.new(url)

    Item.new(
      title: feed.title,
      author: feed.itunes_author,
      article_link: feed.url,
      mp3_link: feed.enclosure_url
    )

This is no big deal, because I’m just changing names in a flat hash, but you can imagine more complex cases where you are changing the actual structure (input is deeply nested, output is flat or nested in a different way, etc). what you want to do in these cases is simply specify a mapping from the input name paths to the output name paths using a dot syntax or similar. most functional langs make this kind of thing easy to do but i’d like to do the same in ruby.

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)