module Roar::JSON::HAL::Resources
Public Instance Methods
from_hash(hash, *)
click to toggle source
Calls superclass method
# File lib/roar/json/hal.rb, line 71 def from_hash(hash, *) hash.fetch("_embedded", []).each { |name, fragment| hash[name] = fragment } super end
to_hash(*)
click to toggle source
Calls superclass method
# File lib/roar/json/hal.rb, line 57 def to_hash(*) super.tap do |hash| embedded = {} representable_attrs.find_all do |dfn| name = dfn[:as] ? dfn[:as].(nil) : dfn.name # DISCUSS: should we simplify that in Representable? next unless dfn[:embedded] and fragment = hash.delete(name) embedded[name] = fragment end hash["_embedded"] = embedded if embedded.any? hash["_links"] = hash.delete("_links") if hash["_links"] # always render _links after _embedded. end end