Skip to content

Instantly share code, notes, and snippets.

@y-yagi
Last active February 10, 2017 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-yagi/6fa1ba7a9bd9bab852082d24b8c84577 to your computer and use it in GitHub Desktop.
Save y-yagi/6fa1ba7a9bd9bab852082d24b8c84577 to your computer and use it in GitHub Desktop.
target_module = "ActionDispatch"
filepath = Rails.root.join("doc", target_module.tableize).to_s
ignore_classes = [Kernel, BasicObject]
Graph("G", "digraph") do
classes = ObjectSpace.each_object(Class).select { |k| "#{k}".match /#{target_module}/ }
global layout:'fdp'
nodes style:'filled', colorscheme:'purd6'
classes.each do |klass|
tree, mods = klass.ancestors.select { |k| "#{k}".match /#{target_module}/ }.group_by { |anc| anc.is_a? Class }.map { |_, k| k.reverse }
tree = tree.map.with_index { |k, i| [k, i] }
if tree.count == 1
node tree.first[0].to_id, label:tree.first[0]
else
tree.each_cons(2) do |(a, ai), (b, bi)|
a_id, b_id = [a, b].map(&:to_id)
route a_id => b_id
node a_id, label:a
node b_id, label:b
end
end
mods = [] unless mods
mods.each do |mod|
mod_id = mod.to_id
route mod_id => klass.to_id
node mod_id, label:mod, shape:'box'
end
end
save filepath, :png
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment