intridea/grape — pull request #278 by panarom (2012-11-21 00:05:39+00:00)
Title: Refactor formatter_for to accommodate custom response types

I wanted grape to be able to respond to requests in Microsoft Excel format. I was able to add a new content type to the resource with little trouble, but in order to respond to the request appropriately I ended up adding, in my code, a lambda expression to Grape::Middleware::Base::Formats::Formatters to call :to_xlsx on my object. I observed the pattern in encode_text & encode_xml and thought it would be useful to generalize that into formatter_for.
If there's a better way/reason not to do this, let me know.
thanks,
-matt