These are chat archives for dry-rb/chat

20th
Apr 2016
Tim Riley
@timriley
Apr 20 2016 00:35

@coop How’s this read?

(Technically, these examples are entities rather than strict value types, because we include the record IDs in their attributes, which you'd expect to be the key indicator of equality. However, in practice, Dry::Types::Struct instances still check for equality across all attributes, and in our apps we only ever instantiate these objects from known-good database data, which means they still behave effectively as value objects. So let's continue!)

Tim Cooper
@coop
Apr 20 2016 00:49
That clears it up.
Tim Riley
@timriley
Apr 20 2016 00:49
Cool, and thanks for the discussion!
Tim Cooper
@coop
Apr 20 2016 00:50
@timriley do you ever mutate these and write them back to the database? And when I say “mutate” I’m talking about returning a new value object with the changed attributes.
Tim Riley
@timriley
Apr 20 2016 00:51
Nope, we just work with hashes when we’re persisting changes. Get a params hash from a form, adjust as necessary in an “operation” object, run it through validation schema, pass it to a ROM command.
Tim Cooper
@coop
Apr 20 2016 00:51
From your example I could imagine something: changed_article = article.with_title(“my new title”) and then pass changed_article to the DB.
Ah ok.
Tim Riley
@timriley
Apr 20 2016 00:51
Yeah. I think a lot of this will be clearer once I can start to piece a few things together.
But I’m trying to avoid 6,000 word articles ;)
Tim Cooper
@coop
Apr 20 2016 00:51
:P
The idea of hashes is fine, we do something similar for event sourcing, each aggregate keeps list of events to persist to the database which are effectively an array of hashes.
We wrote so much code that is similar to dry-types.
Tim Riley
@timriley
Apr 20 2016 00:56
heh
Tim Cooper
@coop
Apr 20 2016 00:58
All of our events are typed… We enforce types when constructing events. I’ve tried substituting for dry-t and dry-v but it’s quite a lot of work. It will be worth it because dry-t and dry-v integrate so nicely, we’ll be able to delete a lot of code at the end.
Tim Riley
@timriley
Apr 20 2016 00:58
Cool, that’ll be nice to get in place :)
Andy Holland
@AMHOL
Apr 20 2016 14:20
hanami/validations#98
Fran Worley
@fran-worley
Apr 20 2016 15:07
@AMHOL Some sound arguments, it's just a shame that there can't be some kind of consensus amongst rails alternative ruby 'frameworks'.
Andy Holland
@AMHOL
Apr 20 2016 15:08
@fran-worley Yeah, the point about not being able to wrap the API was the only real valid argument IMO, but each to their own I guess
Fran Worley
@fran-worley
Apr 20 2016 15:09
@AMHOL I can kind of see the argument for having lots of dependencies but if it keeps code DRYer then why wouldn't you...
Andy Holland
@AMHOL
Apr 20 2016 15:10
Yeah, I think the adding more gems argument is a non-issue
Fran Worley
@fran-worley
Apr 20 2016 15:10
I'd rather have 30 small dependencies that use each other than 5 large ones that have to re-implement common functionality. I just appreciate that others don't agree.
Andy Holland
@AMHOL
Apr 20 2016 15:10
Unless those gems make changes to the runtime environment
:+1: * :100:
Fran Worley
@fran-worley
Apr 20 2016 15:11
Yeah. Also the point about the wrapable API, isn't this being addressed to some degree by the discussions on custom input processors and Error handlers
and surely there is nothing to stop you writing your own macros to reintroduce the validates :title, :presence type syntax ?
Simon Schmid
@sled
Apr 20 2016 15:12
I'm currently working on something like dry-activemodels, basically composes the errors and output of a schema to an activemodel
(error messages, output hash) => activemodel and (full type) => activemodel
some simple delegations
but getting attribute translations and form builder compatibility :)
Andy Holland
@AMHOL
Apr 20 2016 15:14
Well you could build an entirely custom API and make use of the AST in theory, but I think Luca would rather spend the time implementing a similar validation library from scratch, rather than go to that effort and have the underlying dependencies too
Be interesting to see what Piotr thinks when he gets back though, I'm not all that familiar with dry-validation myself
Simon Schmid
@sled
Apr 20 2016 15:20
I think the only external gem dependency of dry-* is the Kleisli gem
Andy Holland
@AMHOL
Apr 20 2016 15:23
Also concurrent-ruby
Simon Schmid
@sled
Apr 20 2016 15:24
yep concurrent-ruby is a beast ;)
Andy Holland
@AMHOL
Apr 20 2016 15:25
It is indeed, I preferred thread-safe TBH
But again, people don't want too many dependencies, so lets have a gem for utitility classes, a gem for managing concurrency and a gem for active anything
I can't wait to see what Tim does with https://github.com/icelab/dry-web-skeleton tho, hopefully will be able to get the full stack running on top of dry and rom soon
Fran Worley
@fran-worley
Apr 20 2016 15:31
It would be good to hear Piotr's opinion but I remember him saying a while ago that his vision for Macros was to enable people to build their own. I know that there was talk a while ago of building something into Reform to make the migration to Dry-V easier.
Andy Holland
@AMHOL
Apr 20 2016 15:35
Oh cool, I guess I missed that
Fran Worley
@fran-worley
Apr 20 2016 15:37
I could be wrong and I know that at this stage it's not been explored to its full potential but that combined with custom processors for inputs and errors would in theory allow you to 'wrap' the library.
Tim Riley
@timriley
Apr 20 2016 20:08
I think Piotr and Luca may have different opinions on the importance of validation.
I can see Luca's opinion on the API stability front. It's something he's decided to take on, with hanami being a "one stop shop"/all-encompassing solution for developers, something they can rely on above all else.
I guess it's a bit different to how an app using e.g. dry-web or other non-frameworks is put together, where you decide to use whichever gems you want, and then learn/use them directly and keep on top of any API changes they may (or may not) ever need.
(I know that's possible with hanami too, but in offering a full range of functionality as an in-house option, I'd imagine the majority of hanami users would follow that path)
Tim Riley
@timriley
Apr 20 2016 20:14
Anyway, the improvements to their validation system look nice! Even if they cover similar ground to dry-v.
I'll release a dry-web gem release today and try to get some minimal docs in our icelab skeleton, @AMHOL :)
I also want to think about what constitutes a viable minimum skeleton too, something perhaps less opinionated than ours (which comes out of the box with things like a background job runner, etc., things that people might not necessarily want).
On dependencies, they're not something people should be afraid of, especially the right type of dependencies :)
Andrew Kozin
@nepalez
Apr 20 2016 20:41
@timriley thanks! with my rungnish writing a post is too time-consuming challenge. I'd postpone it to the weekend
Tim Riley
@timriley
Apr 20 2016 20:54
@nepalez no worries, take your time :) BTW, if you need a hand with proof-reading/minor editing, I'm happy to help.