Use a class method to declare a CSV task #317
Merged
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.
In #302 we went with a new subclass, which we refactored to a module to be included in a Task.
We got feedback in #302 (comment) but we can't really change the behavior only based on data from the Run (a CSV file being present), since we need to know something about the class to show the input which results in a CSV file being updated. The class itself needs to somehow declare that it supports CSV.
Rafael pointed out that we shouldn't use
include
as an API for changing behavior to the classes, we discussed that on Slack but we missed the mark with #313 when we went instead with a superclass, as explained in #310 (comment).So instead this PR uses a class method on Task, doesn't require the Task authors to include a module or inherit from a different class. They simply call
csv_collection
. I'm open to feedback about the name, but the idea with this one is that it defines acollection
like a Task author would do for you, so there some parallel between defining a methodcollection
and callingcsv_collection
on the class.Using a class method opens up features like being able to choose whether the CSV should have headers, changing the column separator, using converters, etc. as arguments to the method call that could be passed in to CSV.new.
Internally this still includes a module into the class rather than adding conditionals to
collection
andcount
and adding thecsv_content
attribute to the receiver.