Skip to content
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

Add support for CSV format to RABL #262

Closed
wants to merge 1 commit into from
Closed

Conversation

gvieira
Copy link

@gvieira gvieira commented Jun 5, 2012

I know CSV is not a proper tree structure as JSON, XML and PList, anyway I needed to export data to CSV in a project that was already using RABL and I thought it would be great to use the same engine.

It uses the ruby's built-in CSV engine but it can also use FasterCSV and any other engine that provides a generate method.

I have also added a csv_options that accepts a hash and passes it to generate method, so people can set their own column and row separators, as much as other many options (see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html#method-c-new).

(Based on #153)

@databyte
Copy link
Collaborator

databyte commented Jun 5, 2012

I see a couple formatting tweaks and I'll let @nesquena look over it as well.

Question, what happens if someone nests multiple levels of values such as a node within a child?

Also FasterCSV is now in standard lib, so CSV in Ruby 1.9 is actually FasterCSV: https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L14

@gvieira
Copy link
Author

gvieira commented Jun 5, 2012

Hi,

Thanks for your reply!
Regarding to the formatting tweaks, I understand your point and I really would like to see your and @nesquena comments. I'm just starting working with ruby and it would be great to know what you guys would do, so I could learn and make it better.

Actually, I don't really like what happen when I use nested multiple levels of values. It just convert the content to string.
For now, I just ignored this situation, since I don't know exactly how to respond to it. Let me know if you have any ideas and I'll be happy to adjust it.

Regarding to FasterCSV, I heard it but I couldn't really understand. So does this mean I do support FasterCSV and do not CSV? Great! (As I said before, I'm a ruby newbie!)

Please let me know if you guys have any suggestions. I would be happy to make it better!

@shingara
Copy link
Contributor

can be good to have this format.

@databyte
Copy link
Collaborator

databyte commented Aug 6, 2012

I'm going to close out this request. It's a neat idea to add more flexibility to RABL but I think it goes against its primary purpose since the conversion to CSV will lose so much of the nesting that JSON and XML use.

In the case of others that need an API for CSV, I recommend https://github.com/tatey/conformist

@databyte databyte closed this Aug 6, 2012
@nesquena
Copy link
Owner

nesquena commented Aug 6, 2012

I agree, I think CSV is inherently too limited for use as a rabl serialization option. Good idea though, do love to support as many formats that make sense for complex data.

@gvieira
Copy link
Author

gvieira commented Aug 6, 2012

No problem man! I really understand your point and completely agree with you. For sure CSV does not fit well for complex cases, anyway it worked for my simple structure! :)

Thanks for your attention!

@kmcphillips
Copy link

You could pull this into a geml 'rabl-csv'.

@nesquena
Copy link
Owner

Definitely, I would encourage that. I was thinking of doing that at some point for many of the other formats as well (i.e Plist). Perhaps make RABL easily pluggable to new formats in the future.

@kmcphillips
Copy link

Yeah. I realize that CSV is not a complex/nested format but I was mostly interested in it to move the CSV generation out of models and into .rabl views.

@gvieira
Copy link
Author

gvieira commented Nov 29, 2012

Nice to hear from you about this old pull request. I'm still using it and I agree it is a great idea to have a rabl-csv gem.

I'm going to study about how to do it and soon we are going to have it.

P.S.: Feel free to point me any direction on how to achieve this.

@ghost
Copy link

ghost commented Oct 8, 2013

@gvieira anything ever come of the gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants