Class: Dbwatcher::Services::MermaidSyntax::ClassDiagramBuilder

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

Overview

Builder for Class Diagrams in Mermaid syntax

Generates Mermaid class diagram syntax from a standardized dataset with support for attributes, methods, and relationships with labels.

Examples:

builder = ClassDiagramBuilder.new(show_methods: true)
content = builder.build_from_dataset(dataset)
# => "classDiagram
#     class User {
#         +string name
#         +orders()
#     }
#     User --> Order : orders"

Instance Method Summary collapse

Methods included from ClassDiagramHelper

#add_attributes_overflow_message, #add_section_divider, #format_attribute_line, #format_class_name, #format_method_line

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 class diagram with message

Parameters:

  • message (String)

    message to display

Returns:

  • (String)

    Mermaid class diagram content



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_builder.rb', line 54

def build_empty(message)
  sanitized_message = sanitize_text(message)
  [
    "classDiagram",
    "    direction #{diagram_direction}",
    "    class EmptyState {",
    "        +string message",
    "    }",
    "    note for EmptyState \"#{sanitized_message}\""
  ].join("\n")
end

#build_from_dataset(dataset) ⇒ String

Build class diagram content from dataset

Parameters:

Returns:

  • (String)

    Mermaid class diagram content



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_builder.rb', line 29

def build_from_dataset(dataset)
  lines = ["classDiagram"]
  lines << "    direction #{diagram_direction}"

  # Add class definitions with attributes and methods
  dataset.entities.each_value do |entity|
    lines += build_class_definition(entity)
  end

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

  lines.join("\n")
end