module YARD::Medoosa
Enhance YARD
documentation by generating class diagrams
Public Instance Methods
add_clusters(graph, all_nodes, namespace)
click to toggle source
@param graph [Graphviz::Graph] @param all_nodes [Hash{String => Graphviz::Node}] (filled by the method) @param namespace [YARD::CodeObjects::NamespaceObject]
# File lib/yard/medoosa.rb, line 20 def add_clusters(graph, all_nodes, namespace) href = namespace.path.gsub("::", "/") + ".html" n = graph.add_node(namespace.path, label: namespace.name, shape: "box", href: href) all_nodes[namespace.path] = n children = module_children(namespace) return if children.empty? sg = graph.add_subgraph(cluster: true) sg.attributes[:name] = namespace.path sg.attributes[:label] = namespace.name children.each do |c| add_clusters(sg, all_nodes, c) end end
generate_medoosa(basepath)
click to toggle source
@param basepath Where the YARD
output goes
# File lib/yard/medoosa.rb, line 37 def generate_medoosa(basepath) YARD::Registry.load! g = Graphviz::Graph.new all_nodes = {} module_children(YARD::Registry.root).each do |ns_object| add_clusters(g, all_nodes, ns_object) end YARD::Registry.all(:class).each do |code_object| sup = YARD::Registry.resolve(nil, code_object.superclass) next if sup.nil? n = all_nodes.fetch(code_object.path) n_sup = all_nodes.fetch(sup.path) n_sup.connect(n, arrowtail: "onormal", dir: "back") end base_fn = "#{basepath}/medoosa-nesting" File.open("#{base_fn}.f.dot", "w") do |f| g.dump_graph(f) end system "unflatten -l5 -c5 -o#{base_fn}.dot #{base_fn}.f.dot" system "dot -Tpng -o#{base_fn}.png #{base_fn}.dot" system "dot -Tsvg -o#{base_fn}.svg #{base_fn}.dot" "#{base_fn}.svg" end
module_children(namespace)
click to toggle source
# File lib/yard/medoosa.rb, line 8 def module_children(namespace) namespace.children.find_all do |code_object| case code_object when YARD::CodeObjects::ModuleObject, YARD::CodeObjects::ClassObject true end end end