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

Use Grape formatter syntax instead of monkey-patching. #6

Merged
merged 2 commits into from
Dec 20, 2012

Conversation

dblock
Copy link
Member

@dblock dblock commented Dec 17, 2012

This will work with the next release of Grape. We have refactored formatters in order to enable complete control of output by external libraries without having to monkey-patch Grape. This is hopefully a bit cleaner.

The updated syntax is now as follows:

formatter :json, Grape::Formatter::Rabl

The formatter implementation will fallback to Grape's JSON formatter.

See ruby-grape/grape#44 as well.


```ruby
get "/user/:id", :rabl => "user.rabl" do
@user = User.fond(params[:id])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be User.find?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, fixed.

@dblock dblock mentioned this pull request Dec 18, 2012
@LTe
Copy link
Member

LTe commented Dec 20, 2012

@dblock thanks!

LTe added a commit that referenced this pull request Dec 20, 2012
Use Grape formatter syntax instead of monkey-patching.
@LTe LTe merged commit 51594f9 into ruby-grape:master Dec 20, 2012
@guilherme
Copy link

isn't strange to assume the default formmater is the JSON formatter? instead of the user defined formatter?

@dblock
Copy link
Member Author

dblock commented Oct 31, 2013

@guilherme I am not sure I understand the question, could you please elaborate? Thx.

@guilherme
Copy link

i've misunderstand this:

formatter :json, Grape::Formatter::Rabl

it means that the formatter for JSON is Grape::Formatter::Rabl, if its not possible to use it it will fallback to the default.

I was thinking about it would be possible to do something:

formatter :xml, Grape::Formatter::Rabl

In this case the fallback would be the xml default formatter, but it doesnt make any sense.

sorry for taking your time.

@dblock dblock deleted the grape-formatter branch June 3, 2015 13:39
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.

4 participants