class Diagram
Public Class Methods
new(dir, name)
click to toggle source
Calls superclass method
# File src/diagram.rb, line 7 def initialize dir, name super dir, name, ".dot" end
Public Instance Methods
att_detail(att)
click to toggle source
# File src/diagram.rb, line 82 def att_detail(att) mult = att[:multiplicity] mstring = (mult == ZERO_TO_MANY ? "[*]" : mult == ONE_TO_MANY ? "[1..*]" : mult == SINGLE ? "" : "[#{mult.to_s}]") "#{att[:name]} #{mstring}" end
describe(*models)
click to toggle source
# File src/diagram.rb, line 19 def describe *models FileUtils.mkpath diagram_path FileUtils.mkpath image_path File.open(self.dotfile, "w") do |file| # nodes file.print "strict digraph {\n" transform_metamodel( { before_model: lambda do |model:| file.print "subgraph cluster_#{model} {\n" file.print "node [shape=plaintext margin=0];\n" file.print "label=#{model};\n" end, after_model: lambda do |model:, before:| file.print "}\n" end, before_type: lambda do |type:, depth:, index:, total:| file.print %Q("#{type.typename}" [label=<<table BORDER="1" CELLBORDER="0" CELLSPACING="0"><TH><TD>#{type.typename}</TD></TH>) end, after_type: lambda do |type:, depth:, before:| file.print "</table>" file.print ">];\n" end, attribute: lambda do |id:, val:, depth:, type:, index:, total:| file.print %Q(<TR><TD ALIGN="LEFT">-#{id}</TD></TR>) end, }, *models ) # links transform_metamodel( { before_type: lambda do |type:, depth:, index:, total:| if type.superclass < DataType link(file, type.typename, type.superclass.typename, label: "extends", arrowhead: "none", arrowtail: "normal") end end, :attribute => lambda do |id:, val:, depth: 0, type:, index:, total:| if val[:links] || val[:type] < DataType contains = (val[:type] < DataType) link(file, type.typename, val[:links] ? val[:links].typename : val[:type].typename, label: %Q!#{contains ? "{contains} " : ""}#{val[:name]}!, arrowhead: contains ? "none" : "open", arrowtail: contains ? "diamond" : "none") end end, }, *models ) file.print "}\n" end unless system("dot -Tjpg #{self.dotfile} > #{self.jpgfile}") puts "Error: couldn't create jpeg: #{self.jpgfile}" end end
dotfile()
click to toggle source
# File src/diagram.rb, line 11 def dotfile File.join(diagram_path, "#{self.name}.dot") end
jpgfile()
click to toggle source
# File src/diagram.rb, line 15 def jpgfile File.join(image_path, "#{self.name}.jpg") end
modelname(m)
click to toggle source
# File src/diagram.rb, line 88 def modelname m m.name.gsub(/^#{DataModel.name}::/, "").gsub /::/, "-" end
typename(t)
click to toggle source
# File src/diagram.rb, line 92 def typename t t.name.gsub(/^#{t.domain}::/, "").gsub /::/, "-" end
Private Instance Methods
diagram_path()
click to toggle source
# File src/diagram.rb, line 102 def diagram_path File.join(self.dir, "diagrams") end
image_path()
click to toggle source
# File src/diagram.rb, line 98 def image_path File.join(self.dir, "images") end
link(file, el1, el2, label: el2, arrowhead: nil, arrowtail: nil)
click to toggle source
# File src/diagram.rb, line 106 def link file, el1, el2, label: el2, arrowhead: nil, arrowtail: nil ah = arrowhead ? %Q!arrowhead = "#{arrowhead}"! : "" at = arrowtail ? %Q!arrowtail = "#{arrowtail}"! : "" file.print %Q!"#{el1}" -> "#{el2}" [label="#{label}" #{ah} #{at} ];\n! end