Class: Dbwatcher::Services::MermaidSyntaxBuilder
- Inherits:
-
Object
- Object
- Dbwatcher::Services::MermaidSyntaxBuilder
- Includes:
- Logging
- Defined in:
- lib/dbwatcher/services/mermaid_syntax_builder.rb
Overview
Builder for generating validated Mermaid diagram syntax
Provides methods for building different types of Mermaid diagrams with syntax validation, error checking, and consistent formatting.
Defined Under Namespace
Classes: SyntaxValidationError, UnsupportedDiagramTypeError
Constant Summary collapse
- SUPPORTED_DIAGRAM_TYPES =
Supported Mermaid diagram types
%w[erDiagram classDiagram flowchart graph].freeze
- MAX_CONTENT_LENGTH =
Maximum content length to prevent memory issues
100_000
Instance Method Summary collapse
-
#build_class_diagram_from_dataset(dataset, options = {}) ⇒ String
Build class diagram from dataset.
-
#build_empty_class_diagram(message) ⇒ String
Build empty class diagram with message.
-
#build_empty_diagram(message, diagram_type) ⇒ String
Build empty diagram of specified type.
-
#build_empty_erd(message) ⇒ String
Build empty ERD diagram with message.
-
#build_empty_flowchart(message) ⇒ String
Build empty flowchart diagram with message.
-
#build_erd_diagram_from_dataset(dataset, options = {}) ⇒ String
(also: #build_erd_diagram)
Build ERD diagram from dataset.
-
#build_erd_diagram_with_tables(entities, options = {}) ⇒ String
Build ERD diagram with isolated tables.
-
#build_flowchart_diagram_from_dataset(dataset, options = {}) ⇒ String
(also: #build_flowchart_diagram)
Build flowchart diagram from dataset.
-
#build_flowchart_with_nodes(entities, options = {}) ⇒ String
Build flowchart diagram with isolated nodes.
-
#initialize(config = {}) ⇒ MermaidSyntaxBuilder
constructor
Initialize builder.
Methods included from Logging
#debug_enabled?, #log_debug, #log_error, #log_info, #log_warn
Constructor Details
#initialize(config = {}) ⇒ MermaidSyntaxBuilder
Initialize builder
34 35 36 37 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 34 def initialize(config = {}) @config = config @logger = config[:logger] || Rails.logger end |
Instance Method Details
#build_class_diagram_from_dataset(dataset, options = {}) ⇒ String
Build class diagram from dataset
57 58 59 60 61 62 63 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 57 def build_class_diagram_from_dataset(dataset, = {}) log_debug("Building class diagram from dataset with #{dataset.entities.size} entities and " \ "#{dataset.relationships.size} relationships") builder = MermaidSyntax::ClassDiagramBuilder.new(@config.merge()) builder.build_from_dataset(dataset) end |
#build_empty_class_diagram(message) ⇒ String
Build empty class diagram with message
100 101 102 103 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 100 def build_empty_class_diagram() builder = MermaidSyntax::ClassDiagramBuilder.new(@config) builder.build_empty() end |
#build_empty_diagram(message, diagram_type) ⇒ String
Build empty diagram of specified type
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 111 def build_empty_diagram(, diagram_type) case diagram_type when "erDiagram", "erd" build_empty_erd() when "classDiagram", "class" build_empty_class_diagram() when "flowchart", "graph" build_empty_flowchart() else raise UnsupportedDiagramTypeError, "Unsupported diagram type: #{diagram_type}" end end |
#build_empty_erd(message) ⇒ String
Build empty ERD diagram with message
82 83 84 85 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 82 def build_empty_erd() builder = MermaidSyntax::ErdBuilder.new(@config) builder.build_empty() end |
#build_empty_flowchart(message) ⇒ String
Build empty flowchart diagram with message
91 92 93 94 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 91 def build_empty_flowchart() builder = MermaidSyntax::FlowchartBuilder.new(@config) builder.build_empty() end |
#build_erd_diagram_from_dataset(dataset, options = {}) ⇒ String Also known as: build_erd_diagram
Build ERD diagram from dataset
44 45 46 47 48 49 50 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 44 def build_erd_diagram_from_dataset(dataset, = {}) log_debug("Building ERD diagram from dataset with #{dataset.entities.size} entities and " \ "#{dataset.relationships.size} relationships") builder = MermaidSyntax::ErdBuilder.new(@config.merge()) builder.build_from_dataset(dataset) end |
#build_erd_diagram_with_tables(entities, options = {}) ⇒ String
Build ERD diagram with isolated tables
129 130 131 132 133 134 135 136 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 129 def build_erd_diagram_with_tables(entities, = {}) log_debug("Building ERD diagram with #{entities.size} isolated tables") dataset = Dbwatcher::Services::DiagramData::Dataset.new entities.each { |entity| dataset.add_entity(entity) } build_erd_diagram_from_dataset(dataset, ) end |
#build_flowchart_diagram_from_dataset(dataset, options = {}) ⇒ String Also known as: build_flowchart_diagram
Build flowchart diagram from dataset
70 71 72 73 74 75 76 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 70 def build_flowchart_diagram_from_dataset(dataset, = {}) log_debug("Building flowchart diagram from dataset with #{dataset.entities.size} entities and " \ "#{dataset.relationships.size} relationships") builder = MermaidSyntax::FlowchartBuilder.new(@config.merge()) builder.build_from_dataset(dataset) end |
#build_flowchart_with_nodes(entities, options = {}) ⇒ String
Build flowchart diagram with isolated nodes
143 144 145 146 147 148 149 150 |
# File 'lib/dbwatcher/services/mermaid_syntax_builder.rb', line 143 def build_flowchart_with_nodes(entities, = {}) log_debug("Building flowchart diagram with #{entities.size} isolated nodes") dataset = Dbwatcher::Services::DiagramData::Dataset.new entities.each { |entity| dataset.add_entity(entity) } build_flowchart_diagram_from_dataset(dataset, ) end |