-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call super initialize #97
base: main
Are you sure you want to change the base?
Conversation
Currently, if a class includes `Dry::Transaction` it can't have any functionality relying on parent classes initializers being called because dry transaction doesn't call in its initializer.
This is not a complete solution yet, it currently ignores keyrest-type parameters in the super method. It could also do with some tidying.
@timriley sorry for responding just now, had a pretty busy week. Nice work on the solution, I have to admit I had to go check ruby docs a few times before I fully understood what it is doing and along the way I picked up some very cool meta programming tips I didn't know. :) This will work correctly in most cases. It will not work in the case where parent initializer expects splat keyword arguments ( While I was investigating this solution I was also digging through dry-transaction source code and I noticed that the initializer that gets added in This led me to a different approach. Can you have a look? I pushed it as another commit in my PR: cafd66c This approach is still rough there and of course needs to be cleaned up but all of the specs already pass. If you think that approach is promising I'll be happy to work further on the PR over the coming week to cleanup code and add more specs. It also fixes another issue. The WDYT? |
@radanskoric Really appreciate you exploring further on this one! I certainly understand your motivation for reducing the number of layers of super methods that get called for However, I'd rather like to keep the resolution of dependencies from the container outside the flow of the regular I'd like to consider one alternative thing to make this more consistent with dry-auto_inject: instead of prepending another module which adds default dependency resolution to Is this something you'd be willing to try? |
@timriley I must say that I did not fully understand if you like the approach I suggested in cafd66c or not? :) As for prepending As for doing it in |
@radanskoric Sorry I wasn't clear! What I was trying to say is that I'd like to have it arranged so that the flow of execution in
So this still leaves the job of determining which args to pass to |
Ok, then I understood you correctly. :) I also have an idea of how it could be implemented with this one problem I'm not sure about: My proposed solution works because inside initialize we remove the keys from If initialize gets a full list of actions in
What are your thoughts on this? Also, could you please elaborate on this a bit as I don't understand why you consider that important (and if I won't be able to do a good job implementing this if I don't understand the motivation :) ):
|
This PR builds on @radanskoric's on in #93 and adds the beginning of a solution for determining whether and how to call
super
from insideDry::Transaction::InstanceMethods#initialize
.@radanskoric Thanks for getting this started! How does something like this look to you?
This takes some logic from dry-auto_inject's
kwargs
strategy for determining which args to pass to super. It needs to do something different for finding the actual super#initialize
method, though, since we want to pass through any#initialize
methods provided by dry-transaction itself (e.g. the other on inDry::Transaction::OperationResolver
), but one from an actual superclass.It might actually be possible to use dry-auto_inject itself to handle our work here, instead of doing operation resolution on our own. This may be worth a quick investigation.
Otherwise, there's still some tidying up to do there, but I feel like we're on the right track to respect super initialize methods now. Let me know what you think!