apotonick/roar — pull request #34 by statonjr (2012-08-06 15:38:47+00:00)
Title: JSON HAL array links

I updated the test to more closely follow the example in the HAL specification:

http://tools.ietf.org/html/draft-kelly-json-hal-00#section-6

If the href of a link is an Array, then the representer returns an array of link objects per the HAL spec (http://tools.ietf.org/html/draft-kelly-json-hal-03#section-4.1.1):

```ruby
link :upsell do
upsells # upsells is an Array of Products
end

# => {\"upsell\":[ProductRepresenter,ProductRepresenter]}
```

Note that each Product in the `upsells` array should specify how to represent itself. I added a new `as` option to the `property` method that allows a representer to specify how its value should be represented:

```ruby
@product = Product.new(:id => 423, :name => "FP01", :title => "Flower Pot")

ProductRepresenter = Module.new do
include Roar::Representer::JSON::HAL
property :id, :from => :href, :as => "/products/?"
property :name
property :title
end

# => {\"href\":\"/products/423\",\"name\":\"FP01\",\"title\":\"Flower Pot\"}
```

The `as` option modifies the value of the property in the representation by swapping out the "?" for the value of the property. In the example above, the value of the `id` property gets transformed from 423 to "/products/423".

[Fixes #33]