Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 10 21:35
    pregozgin starred dry-rb/dry-monads
  • Nov 10 12:22
    flash-gordon opened #371
  • Nov 10 12:22

    flash-gordon on no-rewrap-for-structs

    Don't build constructors when c… (compare)

  • Nov 08 06:56
  • Nov 08 01:12

    AMHOL on master

    Fix gem metadata URIs (compare)

  • Nov 07 22:01
    orien edited #20
  • Nov 07 21:58

    flash-gordon on master

    Add project metadata to the gem… Merge pull request #20 from ori… (compare)

  • Nov 07 21:58
    flash-gordon closed #20
  • Nov 07 21:58
    flash-gordon commented #20
  • Nov 07 21:51
    orien opened #20
  • Nov 07 21:44
  • Nov 07 19:56

    flash-gordon on master

    Update CHANGELOG (compare)

  • Nov 07 19:54

    flash-gordon on fix-keyword-warnings

    (compare)

  • Nov 07 19:54

    flash-gordon on master

    Fix keyword warnings This chan… Merge pull request #114 from dr… (compare)

  • Nov 07 19:54
    flash-gordon closed #114
  • Nov 07 19:53
    flash-gordon opened #114
  • Nov 07 19:53

    flash-gordon on fix-keyword-warnings

    Fix keyword warnings This chan… (compare)

  • Nov 07 19:40
    Travis dry-rb/dry-view (master) errored (634)
  • Nov 07 19:37
    Travis dry-rb/dry-view (master) errored (633)
Damien Timewell
@idlefingers
:+1: it was a little confusing before. Much prefer the new approach, even if my implementation was a bit of a rocky road
Daniel Sandbecker
@daniels
In Dry::Struct, can a default value depend on the value of another attribute?
Nikita Shilnikov
@flash-gordon
no
however, you can override the constructor
Daniel Sandbecker
@daniels
Ok. Thanks, that was quick.
Grant Shangreaux
@gcentauri
hm, did the little pop-up window just tell me i shouldn't ask user questions here? i'm new to dry and very excited about getting it into my development at work
Dean Chuang
@bluekites
Hello, I have a question about dry-validation. I want to be able to validate an array and that the elements within the array are integers. I also would like to be able to accept an empty array. Currently I have something something that looks like this optional(:group_ids, [:int]).value(:array?) but am having trouble figuring out how the element validation would work. Any advice?
Jaromír Červenka
@Cervajz

Hi guys :) I am learning (and trying to implement) dry-transaction, I am going thru the Introduction and found this:
Each operation shouldn’t accumulate state, instead it should receive an input and return an output without causing any side-effects.

What do you mean by that? Especially this part without causing any side-effects?

I understand that I should not keep some state across operations on the "transaction class" level, but isn't "causing side-effect" a natural outcome of an operation?
Thanks in advance for clarifying
Aaron Barthel
@abrthel
Dry-transaction's naming is a bit weird to me but think of it like a process instead of a database transaction. The idea is you create a transaction object that has all the steps needed to handle a process. Then you reuse that transaction object again and again and the only difference is what input you've given it.
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.