Topic: drying up export to csv code.

I have a functionality whereby the application can respond_to a complex report report in csv,pdf format.

In cases where the number of rows returned by the query exceeds 1000 lines, the job gets queued to a background process where the user recieves a mail with the report attached, to reduce load on the mongrels.

currently the view logic for csv's  are being generated in the models! - which I am refactoring out, but I dont want to keep the same kind of inline ruby code for multiple erb's - html, csv, pdf's etc ...

My question is where do I put this code so this can be leveraged by multiple views - html, csv ... as well as the background process. Im just not sure how to do it in the best possible way. Any help appreciated. Let me know if I need to provide more information.

Thanks!

Re: drying up export to csv code.

Provide the code you want refactored.

Re: drying up export to csv code.

Im sorry, I'm told I cant post code from the app .. I understand this makes it extremely difficult to help me, but I have restrictions like that. Sorry.

Re: drying up export to csv code.

Difficult to know in the abstract, but can you provide a to_CSV and a to_pdf method somewhere that can be called from your views?

Re: drying up export to csv code.

spacefugitive wrote:

Im sorry, I'm told I cant post code from the app .. I understand this makes it extremely difficult to help me, but I have restrictions like that. Sorry.

I underdstand, after all I only wanted you to post it so I could steal your awesome sauce.

Re: drying up export to csv code.

haha ... the 'sauce' in question makes everyone here sick. This one method  is about 1200 lines of bad bad bad code ... i seriously wish I could post.

Re: drying up export to csv code.

Sorry I was in a grumpy mood. I will share the tip that made my code a million times better. Short methods. I aim to get my methods 4 lines or less. I can live with 6, especially if there is an if statement. Easier to test and more readable. Use descriptive names to name your methods.

Of course sometimes I don't get it there (quite) but at least by aiming for it I get my code as modular and reusable as possible and get my test coverage as high as possible as easily as possible.

Re: drying up export to csv code.

thanks, I think I havent been able to explain my problem clearly enough ... I will try to do a better write-up with an example sometime in the weekend and post.

thanks again!