Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 05 09:29

    solnic on master

    Clear exception message when an… Add gem names to plugins Merge pull request #128 from sk… (compare)

  • Dec 05 09:29
    solnic closed #128
  • Dec 05 09:29
    solnic closed #127
  • Dec 04 18:49
    micahphone starred dry-rb/dry-monads
  • Dec 04 17:43
    icy-arctic-fox starred dry-rb/dry-types
  • Dec 02 12:37
    pedrofurtado starred dry-rb/dry-view
  • Dec 02 11:59
    lenon starred dry-rb/dry-monads
  • Dec 01 11:06

    flash-gordon on declare-finalized

    (compare)

  • Dec 01 11:06

    flash-gordon on master

    Set initial value for ivar Merge pull request #131 from dr… (compare)

  • Dec 01 11:06
    flash-gordon closed #131
  • Dec 01 11:05
    flash-gordon opened #131
  • Dec 01 11:03

    flash-gordon on declare-finalized

    Set initial value for ivar (compare)

  • Nov 30 16:50
    paul commented #32
  • Nov 30 16:50
    paul synchronize #32
  • Nov 30 16:44
    paul synchronize #32
  • Nov 30 16:02
    paul synchronize #32
  • Nov 30 16:01
    paul commented #32
  • Nov 30 12:12

    flash-gordon on master

    Use GH badge for CI status (compare)

  • Nov 30 12:08

    dry-bot on master

    [devtools] config sync (compare)

Aaron Barthel
@abrthel
So each step would be a pure function that doesn't hold state and acts on the input and returning everything needed in the output
Jaromír Červenka
@Cervajz
@abrthel Thanks. so we have the same understanding :c) Input => Output and that's it.
Aaron Barthel
@abrthel
as for causing a side effect, well yeah you definitly have to store something to a database or where ever but you don't want your transaction object holding state.
Jaromír Červenka
@Cervajz
module ApiTokens
  class Create
    include Dry::Transaction

    step :validate
    step :persist
    step :regenerate_token

    def validate(input)
      validation = ApiTokenSchema.call(input)
      validation.success? ? Success(input) : Failure(validation.errors)
    end

    def persist(input)
      api_token = ApiToken.new(input)
      api_token.save ? Success(api_token) : Failure(api_token.errors)
    end

    def regenerate_token(api_token)
      api_token.regenerate_token!
      Success(api_token)
    end
  end
end
This is my testing class ^^ Should be as you described
The only side-effect is the DB one
Aaron Barthel
@abrthel
Seems fine to me
Jaromír Červenka
@Cervajz
Thanks! :c)
Aaron Barthel
@abrthel
np :smile:
Jaromír Červenka
@Cervajz
Is there a way where I could catch failed operations and revert them? Or is that out of the scope?
For example, if the last step would fail, I'd like to delete the record from DB.
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.