crepe / jsonite

A tiny, HAL-compliant JSON presenter for your Ruby APIs.
28 stars 2 forks source link

Add `:allow_nil` option for embedded documents #7

Closed stephencelis closed 10 years ago

stephencelis commented 10 years ago

Right now, the following fails:

embed :last_document, with: DocumentPresenter

Because it tries to present nil with DocumentPresenter.

This should be configurable, e.g.:

embed :last_document, with: DocumentPresenter, allow_nil: true

In fact, we may want this to be the default behavior? Maybe not, though (explicitness might be better since one-to-one relationships are rarer).

Combine this with #6 and you can make sure your API shows an embedded one-to-one relationship only if it exists. This really feels like the intelligent default, though, so we may need to play around with how we configure these options.