These are chat archives for dry-rb/chat

6th
Apr 2016
Tim Riley
@timriley
Apr 06 2016 00:29
dry-trasnaction v0.6.0 is released!
It has a big new feature - custom step adapters: http://dry-rb.org/gems/dry-transaction/custom-step-adapters/
I’ll be announcing in a blog post tomorrow :)
Andy Holland
@AMHOL
Apr 06 2016 00:46
Nice one :)
Benjamin Klotz
@tak1n
Apr 06 2016 05:10
nice :clap:
John Backus
@backus
Apr 06 2016 07:22
I felt like Martin Luther writing up dry-rb/dry-types#72
tl;dr: Dry::Types::Struct.constructor_type is the Virtus of dry-types
Piotr Solnica
@solnic
Apr 06 2016 07:28
Struct behaviour was originaly designed to work with ROM relations and mappers. So I wanted to make sure all data was fetched, but I didn't care about additional keys that were used for joining or whatever else
John Backus
@backus
Apr 06 2016 07:29
Makes sense
As I mentioned in the issue
Piotr Solnica
@solnic
Apr 06 2016 07:29
And I never liked changing constructor behavior using this macro. I added it because people complained :P
John Backus
@backus
Apr 06 2016 07:29
heh
Well I think that the keys should just be treated like types
Piotr Solnica
@solnic
Apr 06 2016 07:30
I will read 72 when I'm in the office. On mobile atm
John Backus
@backus
Apr 06 2016 07:30
kk
Nikita Shilnikov
@flash-gordon
Apr 06 2016 07:38
@backus :+1: it seems we're gone too far trying to address all possible issues with different constructors
John Backus
@backus
Apr 06 2016 07:45
Agree
Piotr Solnica
@solnic
Apr 06 2016 08:21
Well, I only wanted to address 3 use cases I had in rom and dry-validation
Andrew Kozin
@nepalez
Apr 06 2016 09:04
@solnic hi! (I'm back again)
What is our policy for publishing to rubygems? dry-initializer is waiting for release, but I'm not sure whether to publish it from my account, or somehow else
Piotr Solnica
@solnic
Apr 06 2016 09:06
@nepalez hey, good to see you back
I wanted to discuss dry-initializer vs dry-constructor vs dry-types’ structs and what we’re doing with these projects, and what our intentions are. I’m actually concerned that we’re gonna create some confusion around these 3 projects
ie I would hate to see people using dry-initializer as a virtus replacement because I’m much more interested in shifting people towards dry-types heh
furthermore I was hoping to use dry-initializer instead of custom-made Options APIs that we have in both ROM and some dry-* libs
Nikita Shilnikov
@flash-gordon
Apr 06 2016 09:09
@solnic I completely understand your intentions but people will continue to ask questions about default/missing keys and type constraints if we wouldn't make it obvious how to configure desired behavior
Piotr Solnica
@solnic
Apr 06 2016 09:09
but it seems like dry-initializer scope is way bigger
@flash-gordon well, we are sorting it out in dry-types, esp with @backus chiming in it should be simpler now as more people are collaborating and we all want to make things right
@flash-gordon what was your use case with dry-initializer?
replacing virtus’ or something similar?
Andrew Kozin
@nepalez
Apr 06 2016 09:18
Well. This project was exctracted by me from @marshall-lee dry-function. Its scope was to replace virtus by something more efficient and safe.
Piotr Solnica
@solnic
Apr 06 2016 09:19
ok, so we’re having an interesting conflict of interest here, because I created dry-types hoping to move people away from the virtus’ approach :/
Andrew Kozin
@nepalez
Apr 06 2016 09:20
its type system backs of dry-types, but allows simple PORO types as well
Nikita Shilnikov
@flash-gordon
Apr 06 2016 09:20
@solnic are you asking me about dry-types or @nepalez about dry-initializer? :) I currently use it for models with ROM. But don't worry about me I already resolved all issues that I had :)
Piotr Solnica
@solnic
Apr 06 2016 09:21
I gotta think it through, I mean I’m not against having dry-initializer in dry-rb ecosystem, don’t get me wrong. I just want to avoid confusion. We’re creating a new ecosystem with different philosophy than typical rails-like APIs, so we need to make sure things are clear from the start.
Andrew Kozin
@nepalez
Apr 06 2016 09:22
We discussed with @marshall-lee the dependencies between dry-initializer and dry-types. We decided that dry-types should be core thing and dry-initializer to work on top of it
Piotr Solnica
@solnic
Apr 06 2016 09:22
@AMHOL @timriley could you chime in please? ^
Andrew Kozin
@nepalez
Apr 06 2016 09:23
The only thing dry-initializer does is... well... initialization ;)
It heavily uses new ruby 2.2+ hash arguments to make initialization as fast as possible
Tim Riley
@timriley
Apr 06 2016 09:24
Hi there. I'll be able to read over this in an hour or so :)
Andrew Kozin
@nepalez
Apr 06 2016 09:25
And as @solnic mentioned above, a part of dry-initializer is about extraction of options from rom-support
@flash-gordon if you use dry-initializer, notice that at the end I removed plain defaults from it, leaving default: -> { ... } syntax only
this was done to avoid unintentional mutability of default variables after assignment
and waiting for this update is the only reason I didn't released 0.0.1 before
Nikita Shilnikov
@flash-gordon
Apr 06 2016 09:28
@nepalez currently I don't use it
Piotr Solnica
@solnic
Apr 06 2016 09:32
@nepalez yeah I was hoping to use dry-initializer in rom and other places instead of rom-support stuff, in fact, I want to REMOVE rom-support and replace it with dry-* libs
recommended reading about ruby/elixir/ecto/ar/rails/dry-rb/trailblazer etc
Benjamin Klotz
@tak1n
Apr 06 2016 10:59
@solnic pretty exciting read :+1:
Piotr Solnica
@solnic
Apr 06 2016 11:04
@nepalez I’ve been looking at dry-initializer readme and I see way too much overlap between dry-initializer and dry-constructor AND dry-types. We should address this somehow
ie default option should be dropped IMO and you should just define a type with default value, like in dry-types structs
also really mixed feelings about :writer option
best to remove this, people can add writers themselves, or even add a custom extension to support this
less code to maintain, esp that we all don’t use writers
Andrew Kozin
@nepalez
Apr 06 2016 11:07
@solnic Thank you! I'll see it at the evening. @marshall-lee what do you think about it? ^^
Piotr Solnica
@solnic
Apr 06 2016 11:07
now, param and option are fantastic, I can use exactly this in many many places
attr_hash is also too much for me, and it creates confusion that these type of objects are hash mappers at the same time
Tim Riley
@timriley
Apr 06 2016 11:17
I think these changes would certainly make the library feel clearer and more approachable.
As well as fit in better with the existing ecosystem of dry-rb gems.
Piotr Solnica
@solnic
Apr 06 2016 11:22
yes, we gotta make it fit better, feels too detached right now, and api feels too big
oh and would be cool if it could use dry-constructor
we need dry-constructor in dry-auto_inject
or maybe we need dry-initializer in dry-auto_inject?! geez
Andrew Kozin
@nepalez
Apr 06 2016 11:24

I'm agree about attr_hash, and will remove it today. Concerning defaults, I feel I have to know more about dry-types. I'll reed it and make a decision.

Still not sure about reader and writer. From the one hand, I'm agree - initializer is a separate feature. But from the other, I look at the initializer as an instance dependency injector, and would prefer those dependencies to be readable. Maybe it makes sense to keep reader and drop writer

Piotr Solnica
@solnic
Apr 06 2016 11:25
reader should stay, enabled by default
writer is awful ;)
default types are trivial to use: Types::String.default(“foo”)
Andrew Kozin
@nepalez
Apr 06 2016 11:27
plain assignment? hmm... I need to check if it mutation-safe
whatever, I agree: we should not to multiply defaults
Piotr Solnica
@solnic
Apr 06 2016 13:26
@guizmaii hey, sorry for not replying yesterday, day was kinda rough for me. Anyhow, I wouldn’t recommend using AR models as values in a plain ruby struct, the intention is that these objects are very simple, and AR objects is the opposite of simple :)
@guizmaii and thank you for your kind words <3
Piotr Solnica
@solnic
Apr 06 2016 13:37
@Bounga still here?
Nicolas Cavigneaux
@Bounga
Apr 06 2016 14:00
@solnic Yes
Soumya Ray
@soumyaray
Apr 06 2016 14:05

Hi everyone, I'm unclear on the difference between Dry::Types::Struct and Dry::Types::Value -- what features does one have that the other doesn't? The documentation is clear on their similarity but not their differences!

You can define value objects which will behave like structs and have equality methods too

Piotr Solnica
@solnic
Apr 06 2016 14:05
oops, this is outdated doc
now both structs and values have equalizer mixed in, but values are being frozen on initialization
Soumya Ray
@soumyaray
Apr 06 2016 14:06
ahh! got it - thanks. will play with it to let it sink in :) BTW, the documentation was on: http://dry-rb.org/gems/dry-types/struct-and-value/
Nicolas Cavigneaux
@Bounga
Apr 06 2016 14:15
@solnic Did you find out what was wrong?
Piotr Solnica
@solnic
Apr 06 2016 14:16
@Bounga first of all, schema syntax won’t work with “models”
it’s designed to work with hashes exclusively
in fact schema applies hash? predicate automatically
if your intention is to validate a model with attr readers, we have attr DSL instead of key
support for models is worse than hashes, I should warn you about that
in general I recommend using hashes, not models
for embedded models, you can nest attr DSL, it should work
in the near future we should introduce something like attr(:foo).model { … }
Nicolas Cavigneaux
@Bounga
Apr 06 2016 14:21
I think I'm feeding schema.call with a hash (with nested hash). Not sure to understand the problem
Piotr Solnica
@solnic
Apr 06 2016 14:21
oh, sorry, so you are using hashes
for some reason I thought you’re using entities with attr readers
Nicolas Cavigneaux
@Bounga
Apr 06 2016 14:22
it illustrates my problem
Piotr Solnica
@solnic
Apr 06 2016 14:23
wait, so type is not a hash
Nicolas Cavigneaux
@Bounga
Apr 06 2016 14:23
As you can see, I'm feeding the call with a hash
You're right, in this case, this is not. But in fact in my real code I have a to_hashmethod that creates a hash (with nested hashes) to feed the callmethod
as you can see, the Entity.new only uses strings and a hash.
Piotr Solnica
@solnic
Apr 06 2016 16:00
@Bounga seems like a bug :(
Piotr Solnica
@solnic
Apr 06 2016 16:06
#<#<Class:0x007fa07a81cbb8>:0x007fa07a8a5b98 @rule_compiler=#…. this is so awful, I gotta do something about that
Benjamin Klotz
@tak1n
Apr 06 2016 16:16
@solnic what was kinda weird for me was that I could only use binding.pry in the custom predicates I defined.
I quite like pry driven development when discovering a new lib

for example:

require 'dry/validation'
require 'pry'

SCHEMA = Dry::Validation.Schema do
  binding.pry
end

also doing some puts in there or smth else never executes, so I doubt that the block is actually ever executed? :D

Piotr Solnica
@solnic
Apr 06 2016 16:18
@tak1n huh?
Benjamin Klotz
@tak1n
Apr 06 2016 16:18
test.rb:5:in `block in <main>': undefined method `pry' for #<Dry::Validation::Schema::Rule:0x0056432b6dd048> (NoMethodError)
        from /home/benny/Dev/onlim/adapter/.gem/ruby/2.3.0/gems/dry-validation-0.7.3/lib/dry/validation.rb:23:in `instance_exec'
        from /home/benny/Dev/onlim/adapter/.gem/ruby/2.3.0/gems/dry-validation-0.7.3/lib/dry/validation.rb:23:in `Schema'
        from test.rb:4:in `<main>'

shell returned 1
Piotr Solnica
@solnic
Apr 06 2016 16:18
the dsl is a basic object
use byebug instead
Benjamin Klotz
@tak1n
Apr 06 2016 16:19
or
require 'dry/validation'
require 'pry'

SCHEMA = Dry::Validation.Schema do
  puts 'hi'
end
Piotr Solnica
@solnic
Apr 06 2016 16:19
::Kernel.byebug
the dsl context is a basic object, these methods are not available
Benjamin Klotz
@tak1n
Apr 06 2016 16:19
kk
Kernel.puts 'hi' works, thx for that hint :D
is this somewhere documented otherwise I will create some docs stating that
just was somehow surprising for me
Piotr Solnica
@solnic
Apr 06 2016 16:21
it’s not documented
Benjamin Klotz
@tak1n
Apr 06 2016 16:22
k, should this be documented, I mean maybe it was just surprising for me :D
Piotr Solnica
@solnic
Apr 06 2016 16:27
using BasicObject is not a common thing to do
it’s mostly useful for DSLs
Benjamin Klotz
@tak1n
Apr 06 2016 16:27
kk
Piotr Solnica
@solnic
Apr 06 2016 17:15
@Bounga I fixed it in master, you can try it out by installing dry-v from github
François Bernier
@fbernier
Apr 06 2016 19:07

sooo I just wrote this in a Struct class:

 # Hack to make things writable with type checking
     def self.attributes(new_schema)
       super

       new_schema.keys.each do |k|
         define_method("#{k}=") do |value|
           instance_variable_set("@#{k}", self.class.schema[k][value])
         end
       end
     end

:scream:

Piotr Solnica
@solnic
Apr 06 2016 19:07
:runner:
eternal :fire: awaits you
François Bernier
@fbernier
Apr 06 2016 19:08
:D
François Bernier
@fbernier
Apr 06 2016 19:21
:clap:
John Backus
@backus
Apr 06 2016 19:39
yay
FYI
John Backus
@backus
Apr 06 2016 19:57
how long?
(Approximately of course)
Piotr Solnica
@solnic
Apr 06 2016 19:58
@backus not sure tbh, but not too long, few weeks probably
John Backus
@backus
Apr 06 2016 19:58
oh lol k
Piotr Solnica
@solnic
Apr 06 2016 19:59
last time I think I managed to be “away” for like 6 weeks
;(
John Backus
@backus
Apr 06 2016 21:48
wtf?
Piotr Solnica
@solnic
Apr 06 2016 21:50
Exactly. Just rails mindset
Tim Riley
@timriley
Apr 06 2016 21:54
Good morning. I’m going to write a blog post announcing dry-transaction v0.6 and the custom step adapters this morning.
@solnic I hope you have a good break! We’ll miss you.
Piotr Solnica
@solnic
Apr 06 2016 21:59
@timriley thanks
John Backus
@backus
Apr 06 2016 22:36
@solnic my followup comment on #72 (and the discussion in general) is the main thing I want to resolve before you begin your OSS break
Since the outcome decides whether our team will need to build some functionality on top of dry-types for internal use
Piotr Solnica
@solnic
Apr 06 2016 22:37
Yes I want to address this before I "go"
John Backus
@backus
Apr 06 2016 22:39
FWIW, the main thing I care about is being able to have a truly strict struct with dry-types
In that I want to just be able to say "only symbol keys, fail if there are unexpected keys, fail if keys without defaults are omitted"
But I'm adapting my needs to try to recommend more general solutions for the sake of the project
Piotr Solnica
@solnic
Apr 06 2016 22:45
why would you be so strict about keys?
and I’m OK with a super-strict struct
I didn’t have a use-case for that yet but I can see how this could be useful
btw what’s your use case for srsly-strict structs?
@backus ^
John Backus
@backus
Apr 06 2016 22:59
Woop sorry
Well in general it means that a little less magic is happening when I'm initializing a new object and that is attractive to me for the same reasons that any of the anti-magic aspects of dry-rb are attractive to me
I prefer that, if keys are being dropped, it is being done explicitly. Same reason I prefer that a value be explicitly type cast via a declaration in a Dry::Types::Struct as opposed to done automatically for me by something like Active Record
Piotr Solnica
@solnic
Apr 06 2016 23:08
where are you going to have that dropping keys part?
John Backus
@backus
Apr 06 2016 23:08
Then that boils down to two separate motivations.
  1. Developer sanity. In general if I see UnknownAttributeError :foo instead of undefined method 'foo' I'm less likely to spend time tracking down what went wrong because the error is more clear
  1. Catching mistakes handling user input in production. We build APIs and if we process an API request with invalid keys by silently dropping that key on some object initialization then all of the sudden that is behavior that customers might have in their production apps that we can't change without breaking their compatibility
:/ I guess gitter wants to make both of those "1." whatever
Piotr Solnica
@solnic
Apr 06 2016 23:12
markdown
would’ve been 2 if you posted it in one message
John Backus
@backus
Apr 06 2016 23:12
mhm
Piotr Solnica
@solnic
Apr 06 2016 23:12
I get the second 1 ;)
John Backus
@backus
Apr 06 2016 23:13
you messaged in the middle of me typing it up though and I know it is like 1AM for you so I wanted to keep your attention :P
Piotr Solnica
@solnic
Apr 06 2016 23:14
I want to introduce a feature in dry-v where unexpected keys are reported as rule violations
John Backus
@backus
Apr 06 2016 23:14
That would be great
John Backus
@backus
Apr 06 2016 23:15
Once we get to the dry-validation part of our new API, if that didn't exist, I would be nagging about that too :laughing:
Piotr Solnica
@solnic
Apr 06 2016 23:15
I want that myself fwiw
@timriley casting
Tim Riley
@timriley
Apr 06 2016 23:16
@solnic thanks! I appreciate it, given the hour :)
Piotr Solnica
@solnic
Apr 06 2016 23:18
@timriley looks good, great to see it released :)
Tim Riley
@timriley
Apr 06 2016 23:19
Thanks! I’ll make a few little tweaks of my own and publish shortly :)
Piotr Solnica
@solnic
Apr 06 2016 23:23
@timriley since it’s the first post about dry-transaction, maybe a super quick intro in the first paragraph would be good? like what it is etc?
Tim Riley
@timriley
Apr 06 2016 23:24
That’s a good idea.
Tim Riley
@timriley
Apr 06 2016 23:30
dry-transaction is dry-rb's answer to modelling complex business transactions in your applicartions. With dry-transaction, you can arrange multiple processing operations into a linear pipeline, with the output of each step becoming the input of the next.
^ @solnic do you reckon that’s good enough for a throwaway intro?
Piotr Solnica
@solnic
Apr 06 2016 23:31
@timriley :+1: and maybe one more sentence about error handling being 1st class feature
Tim Riley
@timriley
Apr 06 2016 23:31
you’re a 1st class feature
timriley @timriley adds it
Piotr Solnica
@solnic
Apr 06 2016 23:32
:laughing:
Tim Riley
@timriley
Apr 06 2016 23:36
dry-transaction is dry-rb's answer to modelling complex business transactions in your applicartions. With dry-transaction, you can arrange multiple processing operations into a linear pipeline, with the output of each step becoming the input of the next. dry-transaction also elevates error handling to a first-class concern. Any error will halt the flow of operations, and you have powerful APIs for matching and acting on errors.
@solnic cover it well enough?
Piotr Solnica
@solnic
Apr 06 2016 23:39
@timriley :+1:
Tim Riley
@timriley
Apr 06 2016 23:39
woot! Doing this.
Piotr Solnica
@solnic
Apr 06 2016 23:39
just do it
Tim Riley
@timriley
Apr 06 2016 23:51
strangely, my article doesn’t come through when the site is built
Piotr Solnica
@solnic
Apr 06 2016 23:53
@timriley how did you deploy?
Tim Riley
@timriley
Apr 06 2016 23:53
be middleman deploy
Piotr Solnica
@solnic
Apr 06 2016 23:53
it’s middleman deploy
ok
Tim Riley
@timriley
Apr 06 2016 23:54
this issue is showing itself when I just be middleman build locally too
the new article doesn’t get built
Piotr Solnica
@solnic
Apr 06 2016 23:56
@timriley worked for me
deploying
Tim Riley
@timriley
Apr 06 2016 23:57
Thanks :weary:
Piotr Solnica
@solnic
Apr 06 2016 23:58
hmm, don’t see it
Tim Riley
@timriley
Apr 06 2016 23:58
weird, hey? it shows up when I just be middleman and visit the server
Piotr Solnica
@solnic
Apr 06 2016 23:59
maybe gh pages are having issues
wait no, it’s not being built