These are chat archives for dry-rb/chat

25th
Apr 2016
Tim Riley
@timriley
Apr 25 2016 07:21
Here’s a draft of my next next-gen Ruby article: “Functional command objects in Ruby”. Would appreciate any feedback! https://draftin.com/documents/854843?token=Qm-VkDc3aIYo_FAKreRlkmY_iiCcSIBjf4tn2J2A40eQR28Z0VWG7uHDGsN3LxY_KXmw4tbcm95DEMveJqCcEfE
Andy Holland
@AMHOL
Apr 25 2016 08:18
@timriley nice job, really nice article :+1:
Benjamin Klotz
@tak1n
Apr 25 2016 08:24
@timriley awesome article :+1: :D
Kuba Krzempek
@kubakrzempek
Apr 25 2016 08:30
@timriley I like it too :thumbsup: Learnt quite a few from it.
Tim Riley
@timriley
Apr 25 2016 08:39
Thanks! After some other feedback I just updated the rspec example to make it better at simluating a real validation object. And added an explainer about why I’m just hand-waving the persistence step away.
Piotr Solnica
@solnic
Apr 25 2016 09:01
@timriley :+1:
Tim Riley
@timriley
Apr 25 2016 09:05
Woot, the solnic thumbs-up!
timriley @timriley sneaks back into the draft and names this The Solnica Pattern ;)
Tim Riley
@timriley
Apr 25 2016 09:09
Actually though, I might add a note that this approach needn’t be restricted to commands only. Works for anything which would otherwise make sense as a standalone function, and not some part of an object with a wider API.
Nikita Shilnikov
@flash-gordon
Apr 25 2016 09:49
@timriley great! That's how I write code today thanks to dry-stuff :)
Also most of my my classes returns Either object so I can compose it with dry-transaction
Tim Riley
@timriley
Apr 25 2016 09:51
@flash-gordon awesome :) Yeah, in this article I’m side-stepping Eithers for simplicity. I hope to introduce them in 3 or 4 more weeks :grin:
Nikita Shilnikov
@flash-gordon
Apr 25 2016 09:52
Yeah, don't push too hard lol
Andy Holland
@AMHOL
Apr 25 2016 09:55
I'd consider not adding the side note about the same interface being applicable to other situations for the sake of simplicity too
Tim Riley
@timriley
Apr 25 2016 09:58
@AMHOL True. I’ll just make that another article. Heh.
Andy Holland
@AMHOL
Apr 25 2016 09:58
:D
Any plans to link to these articles from the dry-rb.org site too?
Would be cool to have an "External resources" page
Tim Riley
@timriley
Apr 25 2016 10:03
Good question. Would be pretty easy to throw up a resources page for links elsewhere. I’d be happy to help with that. Alternatively, if you think these articles express the dry-rb philosophy well enough – and if we have an editorial policy that allows more than strict orginsation “news” – I’d even be happy for the articles to be cross-posted through to the dry-rb.org blog
Andrew Kozin
@nepalez
Apr 25 2016 10:44
@timriley nice! cannot wait the next one
Andy Holland
@AMHOL
Apr 25 2016 10:56
@timriley cross-posting would be cool, could just add an attribution link at the top
Also SEO implications to consider, duplicate content and all
Tim Riley
@timriley
Apr 25 2016 10:57
I don’t spend much time thinking about SEO. Is duplicate content bad? Given it’s only in a few places (Icelab’s blog, cross-posted to Medium, and now dry-rb.org)...
Andy Holland
@AMHOL
Apr 25 2016 10:59
Is it posted directly to Medium or as an external link?
Tim Riley
@timriley
Apr 25 2016 10:59
I make a full copy of the article there. Just giving it a try to see if I can reach more people.
With an “originally posted on…” link at the bottom
Andy Holland
@AMHOL
Apr 25 2016 11:00
I notice some are hosted on their site and some are just external links, would be better if you could just use the external link method, also drives traffic to your site :)
Also not sure whether cross-site canonical tags work
But that's an option
If you click on the first article on https://medium.com/ it just links to an external site, that would be a better option for you IMO
Tim Riley
@timriley
Apr 25 2016 11:02
I probably see a different feed of articles to you...
Andy Holland
@AMHOL
Apr 25 2016 11:02
Ahh OK, it was "A $400 emergency" but I'm sure others will do the same
Tim Riley
@timriley
Apr 25 2016 11:04
That looks like a link to a medium.com publication just with a custom domain.
which is something they offer now.
Andy Holland
@AMHOL
Apr 25 2016 11:04
Looks like cross-site canonical tags work BTW
Medium is new to me BTW :)
Tim Riley
@timriley
Apr 25 2016 11:09
Looks like you need to use their API to set a canonical URL
This was an interesting digresion, thanks @AMHOL
Andy Holland
@AMHOL
Apr 25 2016 11:12
:+1:
Tim Riley
@timriley
Apr 25 2016 11:12
At least my future medium cross-posts will have the canonical link. I’ll set dry-rb’s site to do the same too.
Andy Holland
@AMHOL
Apr 25 2016 11:13
Nice one :D
stigchristian
@stigchristian
Apr 25 2016 11:54
Is it possible to validate each hash in an array?
Piotr Solnica
@solnic
Apr 25 2016 11:56
@stigchristian key(:arr).each { schema { key(:foo).required } }
stigchristian
@stigchristian
Apr 25 2016 11:56
ah, great!
Piotr Solnica
@solnic
Apr 25 2016 12:48
@timriley any chance for making auto_inject work with rom-repos during this week?
would be nice to see that it can Just Work™
Tim Riley
@timriley
Apr 25 2016 12:49
@solnic Totally. It seems doable. I can start by spending an hour on it tomorrow morning and see how far I get.
Piotr Solnica
@solnic
Apr 25 2016 12:49
that’s great
I don’t think I will have time for any dry-* activities this week, that’s why I’m asking
just want to wrap up rom stuff
Tim Riley
@timriley
Apr 25 2016 12:50
Of course! The ROM stuff is sounding great, btw.
Piotr Solnica
@solnic
Apr 25 2016 13:18
@timriley this is the next chapter in ROM evolution
Andrew Kozin
@nepalez
Apr 25 2016 15:31
@solnic thank you!
Joe Van Dyk
@joevandyk
Apr 25 2016 17:13
looking to start a new project that basically takes http requests, does stuff to it, validates, etc then makes other http requests. any recommendations for a toolset that could help? is dry-web enough?
or trailblazer or hamani?
dan-klasson
@dan-klasson
Apr 25 2016 17:15
@joevandyk can you elaborate on what you mean that it "does stuff to it"?
Joe Van Dyk
@joevandyk
Apr 25 2016 17:15
lol
yeah, it converts data to different formats depending on sorta complex biz logic, could make requests to other system as part of that
in this case i don’t expect the database to be a big component in the app, if it is at all.
dan-klasson
@dan-klasson
Apr 25 2016 17:20
well sounds like a perfect case of a bunch of service objects
Piotr Solnica
@solnic
Apr 25 2016 17:22
@joevandyk atm dry-web is very alpha, if you’re ok with that then I’d be nice if you gave it a go
also, it only supports roda atm, but we’re gonna add other routing front-ends soon
ie dry-web-hanami
Joe Van Dyk
@joevandyk
Apr 25 2016 17:23
there’s no UI right now btw, just json
dan-klasson
@dan-klasson
Apr 25 2016 17:23
@solnic sure. i wouldn't mind recommend that too. but his question is not framework specific right?
Joe Van Dyk
@joevandyk
Apr 25 2016 17:24
@dan-klasson i’m asking what framework people recommend ;)
or libs or whatever
i haven’t kept up in the last few years
dan-klasson
@dan-klasson
Apr 25 2016 17:25
@joevandyk oh, well that is a good question.
Piotr Solnica
@solnic
Apr 25 2016 17:25
I don’t recommend frameworks, I don’t like frameworks :)
Joe Van Dyk
@joevandyk
Apr 25 2016 17:26
set of cohesive libraries then
w/ generators hopefully
dan-klasson
@dan-klasson
Apr 25 2016 17:26
@joevandyk if you want cohesive libraries, you're in the right channel
Piotr Solnica
@solnic
Apr 25 2016 17:26
I’d defo recommend trying out roda for the http part
dan-klasson
@dan-klasson
Apr 25 2016 17:28
@joevandyk there is no silver bullet when it comes to dev. it all depends on what you're requirements are. but if i were you i would definitely give weight to what @solnic says
Piotr Solnica
@solnic
Apr 25 2016 17:28
what kind of “formats” do you need to support?
fwiw I’m planning to add a new data transformation lib to dry-* family later this year
I don’t like rom-mapper anymore :)
Joe Van Dyk
@joevandyk
Apr 25 2016 17:29
at first glance i prefer http://hanamirb.org/guides/actions/overview/ over roda i think
@solnic imagine taking an ebay product in their api format and converting that to what amazon needs for their api
and what bing needs
so could be taking something in some weird xml format, applying biz logic, then send to whatever json format another service needs
i like hanami’s actions more than roda (at first glance) because it’s easy to see how to structure the code / actions
on a team i think having the convention is important
Piotr Solnica
@solnic
Apr 25 2016 17:33
I like roda routing tree because you need to look at just one place to see what your app is doing on the http side
vs jumping between router dsl and action files
the way we use roda is that http-specific code lives in the routing trees, everything else is core app APIs
so basically http part of the whole system becomes an extension on top of the core app
I mean, that’s how it works in dry-web
Joe Van Dyk
@joevandyk
Apr 25 2016 17:34
hm
Piotr Solnica
@solnic
Apr 25 2016 17:34
I feel like this is something many people are still missing
dan-klasson
@dan-klasson
Apr 25 2016 17:36
@solnic sure, i like that too. but that's not what he is specifically asking for
how weird is the xml, and how complicated is the business logic?
Piotr Solnica
@solnic
Apr 25 2016 17:38
for complex data transformations you could look into functional approach with transproc (it’s the backend for rom)
Joe Van Dyk
@joevandyk
Apr 25 2016 17:44
@solnic didn’t that get changed to dry-transaction?
Piotr Solnica
@solnic
Apr 25 2016 17:45
nope, dry-transaction is for composing business transactions with explicit error handling
Joe Van Dyk
@joevandyk
Apr 25 2016 17:46
is transproc going to be put into dry-*?
Piotr Solnica
@solnic
Apr 25 2016 17:48
I’d like that, yes
we’re actually thinking about a dry-fp project with various functional APIs that many projects can rely on
there’s a big portion of transproc that could be moved there
then transproc could become a collection of data-transformation functions that are composable
and I’d like to extend it with more advanced features, like type-safety and guarded transformations with various fallback and error handling mechanisms
Nikita Shilnikov
@flash-gordon
Apr 25 2016 22:05
@timriley I think I found something dry-rb/dry-transaction#19 :)
Tim Riley
@timriley
Apr 25 2016 22:16
@flash-gordon ah wow, nice work! Thanks :)
Gabriel Gayan Fanta
@ggayan
Apr 25 2016 22:35

Hello folks, I wonder if there is a recommended (or better) way for validating related values in dry-validations, e.g.:

schema = Dry::Validation.Form do
  key(:a).required(:int?, gteq?: 0)
  key(:b).required(:int?)
  rule(:b_gt_a) do
    value(:b).gt?(value(:a))
  end
end

result = schema.call(params)

I noticed that the validation message is plain, for example, if I pass {a: 0, b: 0}, the schema says that b must be greater than 0, but it would be really helpful for the client to know that it must be greater than a

Tim Riley
@timriley
Apr 25 2016 22:44
@ggayan that’s just the default message for that kind of validation. You can override it with your own errors.b_gt_a error message i18n or YML file key
Here’s an example where I’ve just done it locally to the schema (not the best approach for widespread usage, but easy for me to test in isolation):
schema = Dry::Validation.Form do
  configure do
    def self.messages
      Dry::Validation::Messages.default.merge(
        en: { errors: { b_gt_a: 'b must be greater than a' } }
      )
    end
  end

  key(:a).required(:int?, gteq?: 0)
  key(:b).required(:int?)
  rule(:b_gt_a) do
    value(:b).gt?(value(:a))
  end
end

result = schema.call({a: 0, b: 0})
result.messages
# => {:b_gt_a=>["b must be greater than a"]}
Tim Riley
@timriley
Apr 25 2016 22:55
http://dry-rb.org/gems/dry-validation/error-messages/ has lots of info about error messages, FYI :)
Gabriel Gayan Fanta
@ggayan
Apr 25 2016 22:56
great, so the rule name can be used to modify the message
thanks!
Tim Riley
@timriley
Apr 25 2016 22:56
Yep!
@nepalez what in particular were you planning to release with dry-initializer 0.1.0? the Mixin change?
Tim Riley
@timriley
Apr 25 2016 23:02
If so, I think it’s OK to wait just a bit longer...
Tim Riley
@timriley
Apr 25 2016 23:08
@nepalez I was going to leave a few more comments on that PR, but it’s already merged! I’ll just do them in new issues, then
Andrew Kozin
@nepalez
Apr 25 2016 23:35
@timriley Yeah, it would be nice
Piotr Solnica
@solnic
Apr 25 2016 23:51
@ggayan you also want to write rule(b_gt_a: [:a, :b]) { |a, b| b.gt?(a) } which will make sure it’s applied only when both values are valid ints and b is gteq 0