Search code examples
ruby-on-railsmethodsresque

Improve code where passing many params to a method


I have a Resque job that requires 5 params from my controller. I know it isn't great to be passing that many params to a method so I was wondering what would be a good way to improve upon it.

Here is what the job call looks like in the controller:

Resque.enqueue(ExporterJob,"Games",date_range_array,params[:game_code],country[:id],current_user.email)


Solution

  • If you had numerous jobs to all of which you would pass this many arguments, then theoretically you could create some game exporter object which is JSON serializable and would encapsulate all the arguments as attributes, but that just seems a bit of an overhead for one job.

    Passing too many arguments could be a smell of too much coupling, but if you are certain that the design is OK, then I can't think of a way how you could improve this - just leave it as it is. :)