Skip to content

Instantly share code, notes, and snippets.

@blackxored
Created July 28, 2015 19:05
Show Gist options
  • Save blackxored/84a175e58783159d330a to your computer and use it in GitHub Desktop.
Save blackxored/84a175e58783159d330a to your computer and use it in GitHub Desktop.
normalize.each do |attribute, resource_name|
resource_class = find_resource_class(resource_name)
attr = attribute.to_s
if resource_class && resource_class.respond_to?(:find)
denormalize_resource = ->(child_resource) {
resource_class.find(child_resource)
}
results.each do |result|
if result[attr].kind_of?(Array)
result[attr].map!(&denormalize_resource)
else
result[attr] = denormalize_resource.call(result[attribute])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment