Class: UML::ClassDiagram

Inherits:
Object
  • Object
show all
Includes:
Graphviz
Defined in:
lib/uml/class_diagram.rb

Overview

Generates dot representation out of program execution.

Starts with information gathering as soon as it is created.

TODO Parser in to_dot who checks double directed association and substitutes with undirected.

TODO When cluster_packages is true, module is printed as subgraph and node.

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ ClassDiagram

Configuration options:

show_private_methods

If true, includes private instance methods in Nodes.

Default is false.

show_protected_methods

If true, includes protected instance methods in Nodes.

Default is false.

show_public_methods

If true, includes public instance methods in Nodes.

Default is true.

cluster_packages

If true, namespaces are clustered into a package-like representation.

Graphviz can’t plot UML-package with tab, so there is just the package name in the top-left corner of a box. Defaults to false.

exclude

Array which contains information for classes to exclude from graph.

Can contain regular expressions, strings, symbols, or Constants.

Defaults to empty Array.

include

Array which contains information for desired classes.

Can contain regular expressions, strings, symbols, or Constants.

Defaults to empty Array.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uml/class_diagram.rb', line 40

def initialize(config = {})
  @config = {
    :show_private_methods   => false,
    :show_protected_methods => false,
    :show_public_methods    => true,
    :cluster_packages       => false,
    :exclude                => [],
    :include                => []
  }.update(config)
  
  @graph = Graph.new('digraph', 'class_diagram')
  @graph.default_node_attributes[:shape]      = 'record'
  @graph.default_graph_attributes[:labelloc]  = 't'
  @graph.default_graph_attributes[:labeljust] = 'l'
  
  @tracer = LowlevelBacktracer.instance
  @tracer.add_observer self
end

Instance Method Details

#include(klass) ⇒ Object

Manually add a klass with its included modules and superclasses to graph.

klass has to be accepted by configuration options.



67
68
69
# File 'lib/uml/class_diagram.rb', line 67

def include(klass)
  generate_node_with_supers(inheritance(klass))
end

#to_dotObject

Returns a dot representation of gathered information



60
61
62
# File 'lib/uml/class_diagram.rb', line 60

def to_dot
  @graph.to_dot
end

#update(event, tracer) ⇒ Object

:nodoc:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/uml/class_diagram.rb', line 71

def update(event, tracer) # :nodoc:
  return if event != :call
   
  right = tracer.call_stack[-1]
  return if not accepted(right[:klass])

  left = called_by_interesting(tracer.call_stack)
 
  include(right[:klass])
  if left
    include(left[:klass])
    @graph.edges[[left[:klass], right[:klass]]] ||= Dependency.new(left[:klass], right[:klass]) if left[:klass] != right[:klass]
  end
end