-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
displaying ERD by modules #156
Comments
rails-erd is primarily focused on graphing the ActiveRecord relationships between models, but there's no reason it couldn't expand to display controller and/or view relationships! First step, I think, would be to figure out what sort of data structure would best represent these connections, and get that working - are there existing hooks to relate these object to each other, if they're not ActiveRecord related (ie |
I was not exact enough, currently controler and view are not very for example: I have some modules and some models in each: app/models/accounts.rb there are relations between models in different modules, e.g.: class Game::Server < ActiveRecord::Base I would like to have Game models (classes) grouped in subgraph called Game, how could I save also Graphviz .dot source? I could for example make thanks Jano On Wed, Jul 8, 2015 at 4:36 PM, Kerri Miller notifications@github.com
|
AH! Apologies for not understanding. Yes, I think this would be a good to offer, perhaps as a command line option. |
Hello, I created a Ruby script snippet (part of bigger solution beyond the scope of rails-erd) to accomplish this task: system "bin/rake erd filetype=dot"
system 'dot erd.dot -Tpdf > erd.pdf'
erd_dot_contents = File.read('erd.dot')
models_array = erd_dot_contents.split(/(\s|<|>|\"m_|\")+/)
models_array = models_array.find_all{|item| item =~ /::/ }
modules_array = []
models_array.each_with_index do |item,index|
item = item.split('::')
modules_array.push(item[0])
end
modules_array.uniq!.sort!
modules_array.each do |module_name|
#erd_dot_contents.gsub!(//,"")
erd_dot_contents.gsub!(/^node\[( shape)/,"node[ style=filled, color=yellow,\\1")
erd_dot_contents.gsub!(/^(edge\[)/,"splines=ortho;\n\\1")
erd_dot_contents.gsub!(/(^\"m_#{module_name}::.*?)(((^\"m_)(?!#{module_name}))|((^\s+\"m_)(.*)))/m,"subgraph cluster_#{module_name} { fontcolor=red; fontsize=20; label=#{module_name}; style=filled; fillcolor=lawngreen; pencolor=transparent; \\1}\n\\2")
end
File.open('erd_modular.dot', "w") { |file| file.puts erd_dot_contents }
system 'dot erd_modular.dot -Tpdf > erd_modular.pdf' Here is how model looks like before and after modification of source dot-file by this snippet: Feel free to use (public domain). Caveats (ugly points):
I am OK with current state of this implementation, but anybody is welcome to improve it further, or maybe incorporate modular output as command-line option in rails-erd. Or drop me a line here, if you'll find some bugs or will have further improvement ideas. Jan Ostrochovsky |
+1 |
AWESOME! <3 for sharing this.. I'll see if I can work this into 1.5 (which wow, is looking like a big release!) |
Hello,
I am building an application divided into several modules (models, views, controllers - all in separate modules/subdirectories). It could be very nice to have option to generate model diagram grouped by modules - entities from each modules in its own "box", but still interconnected correctly, and optionally, filter what to generate also by modules (for having separate sub-ERD for each module separately).
Graphviz has this option and implements it by subgraphing, examples:
http://www.graphviz.org/content/fdpclust
http://www.graphviz.org/content/cluster
Do you plan to add such feature in near future? If no, I could try to do some extension, if you would give me some hints for "best practise", how to incorporate it into your great gem, and provide it to you and the community.
Thanks in advance.
Jano
The text was updated successfully, but these errors were encountered: