-
Notifications
You must be signed in to change notification settings - Fork 74
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
Use superclass for CSV method #313
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or whether we wanted to introduce a class-level method like csv_task? instead.
What I don't like about things like csv_task?
is that now we have to define it in Task which should not care about CsvTask at all. I think respond_to?
is fine.
Yeah, that was my reasoning as well - I don't think the parent class should have to know anything about its subclasses and the specialized behaviour they provide. I'm keen on sticking to our use of |
If I'm not mistaken, if @task.respond_to?(:csv_content=)
@task.csv_content = @run.csv_file.download
end If that's it, would it make sense to define a generic hook/callback method on # task.rb
class Task
def before_perform(_run)
end
end
# csv_task.rb
class CsvTask < Task
def before_perform(run)
self.csv_content = run.csv_file.download
super
end
end This could alternatively be implemented as an ActiveSupport::Callback. |
It could make sense, but then we would give too much API to Task writers, which don't want to. We provide CsvTask and TaskJob, so I think even if not ideal, it's fine to have some knowledge between them. |
Providing a callback on Task is pretty neat! But yeah, as Étienne mentioned, the tradeoff is making Task aware of Run, which we want to avoid. It's not the prettiest to use |
b2efbb8
to
bd825ce
Compare
Change the implementation of
CsvTask
to be a class from which application Tasks can inherit from, instead of a mixin.It was unclear to me whether we're okay keeping the use of
respond_to?(csv_content=)
inTaskJob
when settingcsv_content
on a Task:maintenance_tasks/app/jobs/maintenance_tasks/task_job.rb
Lines 59 to 62 in d583546
Or whether we wanted to introduce a class-level method like
csv_task?
instead. Let me know!