Class: RailsFlowMap::PlantUMLFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_flow_map/formatters/plantuml_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(graph) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails_flow_map/formatters/plantuml_formatter.rb', line 3

def format(graph)
  lines = ["@startuml"]
  lines << "!define MODEL_COLOR #FFCCFF"
  lines << "!define CONTROLLER_COLOR #CCCCFF"
  lines << "!define ACTION_COLOR #CCFFCC"
  lines << ""
  
  # Group nodes by type
  models = graph.nodes_by_type(:model)
  controllers = graph.nodes_by_type(:controller)
  actions = graph.nodes_by_type(:action)
  
  # Add models
  unless models.empty?
    lines << "package \"Models\" <<Database>> {"
    models.each do |node|
      lines << "  class #{sanitize_id(node.name)} <<Model>> {"
      lines << "    .."
      lines << "  }"
    end
    lines << "}"
    lines << ""
  end
  
  # Add controllers and their actions
  unless controllers.empty?
    lines << "package \"Controllers\" <<Frame>> {"
    controllers.each do |controller|
      lines << "  class #{sanitize_id(controller.name)} <<Controller>> {"
      
      # Find actions for this controller
      controller_actions = graph.edges
        .select { |e| e.from == controller.id && e.type == :has_action }
        .map { |e| graph.find_node(e.to) }
        .compact
      
      controller_actions.each do |action|
        lines << "    +#{action.name}()"
      end
      
      lines << "  }"
    end
    lines << "}"
    lines << ""
  end
  
  # Add relationships
  graph.edges.each do |edge|
    next if edge.type == :has_action  # Skip controller-action relationships
    
    from_node = graph.find_node(edge.from)
    to_node = graph.find_node(edge.to)
    
    next unless from_node && to_node
    
    relationship = format_relationship(edge, from_node, to_node)
    lines << relationship if relationship
  end
  
  lines << ""
  lines << "@enduml"
  
  lines.join("\n")
end