intridea/grape — pull request #101 by evansj (2011-12-14 10:47:10+00:00)
Title: Root keys for entity representations

Here is initial support for specifying root keys for entity representations.

You can do this:

```ruby
module API::Entities
class User < Grape::Entity
root 'users', 'user'
end
end

module API
class Users < Grape::API

# this will render { "users": [ {"id":"1"}, {"id":"2"} ] }
get '/users' do
@users = User.all
present @users, :with => API::Entities::User
end

# this will render { "user": {"id":"1"} }
get '/users/:id' do
@user = User.find(params[:id])
present @user, :with => API::Entities::User
end
end
end
```

I could write an auto mode that would allow you to just specify 'root' with no arguments in the Entity class, but I'd have to add a dependency on something like [linguistics](http://deveiate.org/projects/Linguistics/wiki/English) or [activesupport](http://as.rubyonrails.org/classes/ActiveSupport/Inflector.html) so I could pluralize the class name properly. What do you think?