Class: Mxrb::Uml::SequenceDiagram

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/uml/sequence_diagram.rb

Overview

Builds call-chain sequence diagrams from the existing semantic index. rubocop:disable Metrics

Constant Summary collapse

CALLABLE_KINDS =
%i[microflow nanoflow].freeze
MAX_DEPTH =
100

Instance Method Summary collapse

Constructor Details

#initialize(index, root: nil, module_name: nil, depth: 2) ⇒ SequenceDiagram

Returns a new instance of SequenceDiagram.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mxrb/uml/sequence_diagram.rb', line 13

def initialize(index, root: nil, module_name: nil, depth: 2)
  raise ArgumentError, 'choose either root or module_name' if root && module_name
  raise ArgumentError, 'root or module_name is required' unless root || module_name

  @index = index
  @root = root
  @module_name = module_name
  @depth = Integer(depth)
  raise ArgumentError, 'depth must be zero or greater' if @depth.negative?
  raise ArgumentError, "depth cannot exceed #{MAX_DEPTH}" if @depth > MAX_DEPTH

  @edges, @selected = root ? root_graph : module_graph
  @participants = participants
end

Instance Method Details

#to_mermaidObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mxrb/uml/sequence_diagram.rb', line 28

def to_mermaid
  lines = ['sequenceDiagram']
  @participants.each do |artifact|
    lines << %(  participant #{participant_id(artifact)} as #{Support.mermaid_text(artifact.qualified_name)})
  end
  @edges.each do |source, target|
    lines << "  #{participant_id(source)}->>#{participant_id(target)}: call"
  end
  append_mermaid_empty_note(lines) if @edges.empty?
  "#{lines.join("\n")}\n"
end

#to_plantumlObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mxrb/uml/sequence_diagram.rb', line 40

def to_plantuml
  lines = ['@startuml']
  @participants.each do |artifact|
    lines << %(participant "#{Support.plantuml_text(artifact.qualified_name)}" as #{participant_id(artifact)})
  end
  @edges.each do |source, target|
    lines << "#{participant_id(source)} -> #{participant_id(target)} : call"
  end
  lines << 'note "No call relationships found" as MXRB' if @edges.empty?
  lines << '@enduml'
  "#{lines.join("\n")}\n"
end