Module: Dbwatcher::Services::MermaidSyntax::ClassDiagramHelper

Included in:
ClassDiagramBuilder
Defined in:
lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb

Overview

Helper module for ClassDiagramBuilder

Contains formatting methods for class diagram elements

Instance Method Summary collapse

Instance Method Details

#add_attributes_overflow_message(lines, entity) ⇒ Object

Add overflow message for attributes if needed



18
19
20
21
22
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb', line 18

def add_attributes_overflow_message(lines, entity)
  return unless entity.attributes.size > max_attributes

  lines << "        %% ... #{entity.attributes.size - max_attributes} more attributes"
end

#add_section_divider(lines, entity) ⇒ Object

Add section divider if methods will follow



25
26
27
28
29
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb', line 25

def add_section_divider(lines, entity)
  return unless show_methods? && entity.[:methods]&.any?

  lines << "        %% ----------------------"
end

#format_attribute_line(attr) ⇒ Object

Format an attribute for class diagram



11
12
13
14
15
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb', line 11

def format_attribute_line(attr)
  visibility = attr.[:visibility] || "+"
  type = attr.type.to_s.empty? ? "any" : attr.type
  "        #{visibility}#{type} #{attr.name}"
end

#format_class_name(entity_id, dataset) ⇒ Object

Format class name for diagram



39
40
41
42
43
44
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb', line 39

def format_class_name(entity_id, dataset)
  entity_name = dataset.get_entity(entity_id)&.name || entity_id
  display_name = Sanitizer.display_name(entity_name)
  # Use backticks to allow :: in class names for Mermaid
  "`#{display_name}`"
end

#format_method_line(method) ⇒ Object

Format a method for class diagram



32
33
34
35
36
# File 'lib/dbwatcher/services/mermaid_syntax/class_diagram_helper.rb', line 32

def format_method_line(method)
  visibility = method[:visibility] || "+"
  method_name = Sanitizer.method_name(method[:name])
  "        #{visibility}#{method_name}"
end