Class: Roar::JSON::HAL::Links::Representer
- Inherits:
-
Representable::Decorator
- Object
- Representable::Decorator
- Roar::JSON::HAL::Links::Representer
- Includes:
- Representable::JSON::Collection
- Defined in:
- lib/roar/json/hal.rb
Overview
Represents all links for “_links”: [Hyperlink, [Hyperlink, Hyperlink]]
Instance Method Summary collapse
Instance Method Details
#from_hash(hash, *args) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/roar/json/hal.rb', line 147 def from_hash(hash, *args) collection = hash.collect do |rel, value| # "self" => [{"href": "//"}, ] or "self" => {"href": "//"} value.is_a?(Array) ? value.collect { |link| link.merge("rel"=>rel) } : value.merge("rel"=>rel) end super(collection) # [{rel=>self, href=>//}, ..] or {rel=>self, href=>//} end |
#to_hash(options) ⇒ Object
143 144 145 |
# File 'lib/roar/json/hal.rb', line 143 def to_hash() super.inject({}) { |links, hash| links.merge!(hash) } # [{ rel=>{}, rel=>[{}, {}] }] end |