Last active
August 29, 2015 14:02
-
-
Save limhoff-r7/5e478466635bb4a8b2e6 to your computer and use it in GitHub Desktop.
Rails initializer tsort, dot digraph and png generation
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
dot -o initializers.png -T png initializers.dot |
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
# arrows will point to dependencies | |
File.open('initializers.dot', 'w') do |f| | |
f.puts 'digraph initializers {' | |
Rails.application.initializers.each do |initializer| | |
if initializer.after | |
f.puts %Q{ "#{initializer.name}" -> "#{initializer.after}"} | |
end | |
# print all node, even if unconnected | |
unless initializer.after || initializer.before | |
f.puts %Q{ "#{initializer.name}"} | |
end | |
if initializer.before | |
f.puts %Q{ "#{initializer.before}" -> "#{initializer.name}"} | |
end | |
end | |
f.puts '}' | |
end |
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
File.open('initializers.txt', 'w') do |f| | |
Rails.application.initializers.tsort.each do |initializer| | |
f.puts "#{initializer.name} from #{initializer.instance_variable_get(:@context).class.name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment