Skip to content

Instantly share code, notes, and snippets.

@jennifersmith
Last active August 29, 2015 14:10
Show Gist options
  • Save jennifersmith/3f22988c52ee46ce10c1 to your computer and use it in GitHub Desktop.
Save jennifersmith/3f22988c52ee46ce10c1 to your computer and use it in GitHub Desktop.
Convert requires into a graph - this is pretty dreadful please can someone do better?
egrep -e "require\s\"([a-z]|_|/)+\"" -o -r lib | ./sniffrequires.rb | dot -Tsvg > /tmp/foo.svg; open /tmp/foo.svg
#!/usr/bin/ruby
puts "digraph {"
$stdin.each do | line |
/lib\/(?<from>(\w|\/)+)(\.rb)?:require \"(?<to>(\w|\/)+)/i =~ line
puts "\t #{from.gsub("/", "_")} -> #{to.gsub("/", "_")}"
end
puts "}"
@jennifersmith
Copy link
Author

Thanks - been gradually refining it as I realised I missed stuff! To be honest it's pretty horrible and if I was going to do it again I would probably use a real grown up parser not regex :D

@jennifersmith
Copy link
Author

To be fair, the parser version is possibly worse :D

https://github.com/jennifersmith/rubygraph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment