seancribbs/webmachine-ruby — Issue #14: Declarative style?
Author: jamis
Created: 2011-10-24 03:01:34+00:00
State: open
Labels: feature

This is something I'm baking into my side-project, but I figured I'd run it by you to see if you thought it might fit in Webmachine directly. The idea is that declaring a method name in content_types_provided, and then declaring the method elsewhere, seems like an unfortunately large disconnect. (Same with content_types_accepted.) So what I've got is a set of macros:

```ruby
class SampleResource < Resource
when_client_wants "text/html" do
# ...
end

when_client_wants "application/json", "text/x-json", "application/jsonrequest" do
# ...
end

when_client_provides "application/xml", "application/x-xml", "text/xml" do
# ...
end

when_client_provides "application/json", "text/x-json", "application/jsonrequest" do
# ...
end
end
```

It's built on top of the existing content_types_accepted and content_types_provided callbacks, so it's still possible to declare those mappings in the existing way. Thoughts?