Class: Dbwatcher::Services::MermaidSyntax::FlowchartBuilder

Inherits:
BaseBuilder
  • Object
show all
Defined in:
lib/dbwatcher/services/mermaid_syntax/flowchart_builder.rb

Overview

Builder for Flowchart Diagrams in Mermaid syntax

Generates Mermaid flowchart syntax from a standardized dataset with support for nodes with attributes and edges with labels.

Examples:

builder = FlowchartBuilder.new(show_attributes: true)
content = builder.build_from_dataset(dataset)
# => "flowchart LR\n    User[User<br/>name, email]\n    User -->|has_many| Comment"

Instance Method Summary collapse

Methods inherited from BaseBuilder

#initialize

Methods included from Logging

#debug_enabled?, #log_debug, #log_error, #log_info, #log_warn

Constructor Details

This class inherits a constructor from Dbwatcher::Services::MermaidSyntax::BaseBuilder

Instance Method Details

#build_empty(message) ⇒ String

Build empty flowchart with message

Parameters:

  • message (String)

    message to display

Returns:

  • (String)

    Mermaid flowchart content



43
44
45
46
47
48
49
# File 'lib/dbwatcher/services/mermaid_syntax/flowchart_builder.rb', line 43

def build_empty(message)
  sanitized_message = sanitize_text(message)
  [
    "flowchart #{diagram_direction}",
    "    EmptyState[\"#{sanitized_message}\"]"
  ].join("\n")
end

#build_from_dataset(dataset) ⇒ String

Build flowchart content from dataset

Parameters:

Returns:

  • (String)

    Mermaid flowchart content



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dbwatcher/services/mermaid_syntax/flowchart_builder.rb', line 20

def build_from_dataset(dataset)
  lines = ["flowchart #{diagram_direction}"]

  # Add node definitions
  dataset.entities.each_value do |entity|
    lines << build_flowchart_node(entity)
  end

  # Add relationships
  unless dataset.relationships.empty?
    lines << ""
    dataset.relationships.each do |relationship|
      lines << build_flowchart_relationship(relationship, dataset)
    end
  end

  lines.join("\n")
end