padrino/padrino-framework — pull request #1733 by goncalvesjoao (2014-08-05 22:46:25+00:00)
Title: introducing :collection and :member options to simplify the use of :map

Hi guys!
First of all. Thanks for all the great work, I'm loving padrino so far and its a must for quickly bootstrapping new micro-service projects.

I've been trying to simply my controllers' code in order to please the almighty codeclimate god and for readability purposes I realised that in some cases, the use of 'collection' and 'member' for routes (like rails) might make sense.

Here's a old controller of mine:
```ruby
module V0
module Medicines

COLLECTION_URL = "v0/medicines"

MEMBER_URL = "#{COLLECTION_URL}/:id"

MedicationLocker::App.controllers COLLECTION_URL do

get :index do
...
end

get :prescribed_by_medic, map: "#{COLLECTION_URL}/prescribed_by_medic/:medic_id" do
...
end

get :show, map: MEMBER_URL do
...
end

post :bulk_create, map: "#{COLLECTION_URL}/bulk_create" do
...
end

post :create, map: COLLECTION_URL do
...
end

put :update, map: MEMBER_URL do
...
end

put :update_chronic_state, map: "#{MEMBER_URL}/chronic_state" do
...
end

delete :stop_treatment, map: "#{MEMBER_URL}/stop_treatment" do
...
end

delete :destroy, map: MEMBER_URL do
...
end

end

end
end
```

and the new version with 'collection' and 'member' options

```ruby
module V0
module Medicines

MedicationLocker::App.controllers "v0/medicines" do

get :index do
...
end

get :prescribed_by_medic, collection: "prescribed_by_medic/:medic_id" do
...
end

get :show, member: "" do
...
end

post :bulk_create, collection: "bulk_create" do
...
end

post :create, collection: "" do
...
end

put :update, member: "" do
...
end

put :update_chronic_state, member: "chronic_state" do
...
end

delete :stop_treatment, member: "stop_treatment" do
...
end

delete :destroy, member: "" do
...
end

end

end
end
```

Both versions will lead to
```
Application: MedicationLocker::App
URL REQUEST PATH
(:v0/medicines, :index) GET /v0/medicines
(:v0/medicines, :prescribed_by_medic) GET /v0/medicines/prescribed_by_medic/:medic_id
(:v0/medicines, :show) GET /v0/medicines/:id
(:v0/medicines, :bulk_create) POST /v0/medicines/bulk_create
(:v0/medicines, :create) POST /v0/medicines
(:v0/medicines, :update) PUT /v0/medicines/:id
(:v0/medicines, :update_chronic_state) PUT /v0/medicines/:id/chronic_state
(:v0/medicines, :stop_treatment) DELETE /v0/medicines/:id/stop_treatment
(:v0/medicines, :destroy) DELETE /v0/medicines/:id
```

The new changes are quite simple and I've also added tests for them.
All original tests are green and so do the new ones.

I believe this might be useful for others and it would make my day to contribute my '50cents' to padrino.

PS: I haven't change the version number nor the documentation about these new changes, don't wanna mess anything up.