Skip to content
This repository

Inconsistent rendering API? #338

Closed
mattiassvedhem opened this Issue · 6 comments

3 participants

Mattias Svedhem David Sommers Nathan Esquenazi
Mattias Svedhem

Is there any reason why the arguments order is switched for the format specific methods?

Rabl::Renderer.json(@post, 'posts/show')
Rabl::Renderer.new('posts/show', @post, :view_path => 'app/views', :format => 'hash').render
David Sommers
Collaborator

Yeah, I didn't like that either when I was last looking at the code. The problem was an internal method had an optional argument at the end so it was needed.

For .json
For .new

See how .new's object is optionally set to nil. But the (object, source) argument order of .json are both required.

Why that order? I don't know, I didn't accept the PR but now we're stuck with it.

If @nesquena has any ideas as to the details, I'd be enlightened.

Too bad we can't create another initializer. The easiest hack/fix would be to replace the current initializer with just *args and interpret the number of arguments being used. If args.size > 1, then it's "old school". Otherwise a single hash is the "new way". Then we can just pick any order you want. Like I said, its a complete hack to allow better CoP but at the cost of a few ugly lines in the initializer.

I'll let @nesquena pick this one apart.

David Sommers
Collaborator

Since there's no immediate solution proposed, I'll close it. We can open a new issue with code attached if we have a solution.

Nathan Esquenazi
Owner

Yeah I claim full responsibility for not catching that when I accepted the pull request. The reordering of parameters in that way does seem pretty inconsistent. I think we are stuck with it for the time being but we can likely correct it in time for an API breaking 1.0 release #216

Nathan Esquenazi
Owner

Oh and thanks for digging into that david, I suspect that optional param there is probably what encouraged Ivan to swap the parameters. But I think we could keep the ordering consistent and achieve that in a different way.

Mattias Svedhem

Hi @nesquena, awesome, looking forward to 1.0, do you have any goal date for releasing it?

Nathan Esquenazi
Owner

I was actually planning to start on it more seriously in the next couple months. I'd love to have something for people to play with (preview release) by January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.