Last active
August 29, 2015 14:05
-
-
Save bdehamer/6af93687716ff9f4fc38 to your computer and use it in GitHub Desktop.
Format Docker Image Tree for D3.js Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
images = Docker::Image.all(all: 1) | |
nodes = images.each_with_object({}) do |image, memo| | |
memo[image.id] = { | |
id: image.id, | |
name: image.id[0..11], | |
parent_id: image.info['ParentId'], | |
children: [] | |
} | |
end | |
nodes.each do |_, node| | |
next if node[:parent_id] == '' | |
nodes[node[:parent_id]][:children] << node | |
end | |
root = nodes.find do |_, node| | |
node[:parent_id] == '' | |
end | |
respond_with root[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment