grape: Organization with blocks of methods
Is there a simple way, to organize the methods with blocks for code folding, organization, etc?
What I’m thinking of using a short version of the example in the README, but wrapping methods and blocks in group blocks:
module Twitter
class API < Grape::API
version 'v1', using: :header, vendor: 'twitter'
format :json
prefix :api
resource :statuses do
group :public_timeline do
desc 'Return a public timeline.'
get :public_timeline do
Status.limit(20)
end
end
group :home_timeline do
desc 'Return a personal timeline.'
get :home_timeline do
authenticate!
current_user.statuses.limit(20)
end
end
group :status do
desc 'Return a status.'
params do
requires :id, type: Integer, desc: 'Status id.'
end
route_param :id do
get do
Status.find(params[:id])
end
end
end
end
end
end
I’m finding the only way I can get this right now is to use Ruby’s open classes, and then having a separate definition for each one. It feels weird for desc and params to not be block based, but rather order based.
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 4
- Comments: 16 (4 by maintainers)
endpointsounds ok to me, but naming is hard 😃