add .parameters and .parameters! methods for input parameters expectations on call #112
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Сurrently, you can never be sure, what parameters will be specified in the
context
on call. I need to grep forcall
invocations across the project or look through the entire interactor carefully forcontext.foo
things to understand what are the input variables.We use interactors quite often and now have an internal convention to declare parameters like this:
thus, it is very easy to see what do we need to specify to make this interactor working without deep understanding of its contents.
I think that this is a good practice, and perhaps there should be a method to do this.
This PR introduces two new methods:
.parameters
- simply defines specified delegators to thecontext
. So, previous example would look like this:.parameters!
- does essentially the same, but adds a before hook that will fail the context if any of specified params is missing.I see that there are some related issues (#92, #67, #109) and even a PR (#82) which evolved to a separate gem (https://github.com/jonstokes/troupe).
To be honest, I was lazy enough not to read all of those threads from beginning to end 😄. So, maybe this solution has been already discussed and rejected for some reasons.
I'm not sure about the name of this methods, but it looks as a very simple solution that will stick well with lightness if interactors.