Last active
February 10, 2017 01:19
-
-
Save y-yagi/6fa1ba7a9bd9bab852082d24b8c84577 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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