Class: Dbwatcher::Services::DiagramTypeRegistry
- Inherits:
-
Object
- Object
- Dbwatcher::Services::DiagramTypeRegistry
- Defined in:
- lib/dbwatcher/services/diagram_type_registry.rb
Overview
Registry for managing diagram types and creating strategy instances
Provides a central registry for all available diagram types with metadata, and factory methods for creating strategy instances.
Defined Under Namespace
Classes: UnknownTypeError
Constant Summary collapse
- DIAGRAM_TYPES =
Built-in diagram types with essential metadata
{ "database_tables" => { strategy_class: "Dbwatcher::Services::DiagramStrategies::ErdDiagramStrategy", analyzer_class: "Dbwatcher::Services::DiagramAnalyzers::ForeignKeyAnalyzer", display_name: "Database Schema", description: "Entity relationship diagram showing database tables and foreign key relationships", mermaid_type: "erDiagram" }, "database_tables_inferred" => { strategy_class: "Dbwatcher::Services::DiagramStrategies::ErdDiagramStrategy", analyzer_class: "Dbwatcher::Services::DiagramAnalyzers::InferredRelationshipAnalyzer", display_name: "Database Schema (Inferred)", description: "Entity relationship diagram with inferred relationships from naming patterns", mermaid_type: "erDiagram" }, "model_associations" => { strategy_class: "Dbwatcher::Services::DiagramStrategies::ClassDiagramStrategy", analyzer_class: "Dbwatcher::Services::DiagramAnalyzers::ModelAssociationAnalyzer", display_name: "Model Associations", description: "Class diagram showing ActiveRecord models with attributes and methods", mermaid_type: "classDiagram" }, "model_associations_flowchart" => { strategy_class: "Dbwatcher::Services::DiagramStrategies::FlowchartDiagramStrategy", analyzer_class: "Dbwatcher::Services::DiagramAnalyzers::ModelAssociationAnalyzer", display_name: "Model Associations (Flowchart)", description: "Flowchart diagram showing model relationships", mermaid_type: "flowchart" } }.freeze
Instance Method Summary collapse
-
#available_types ⇒ Array<String>
Get list of available diagram type keys.
-
#available_types_with_metadata ⇒ Hash
Get available types with metadata.
-
#create_analyzer(type, session) ⇒ Object
Create analyzer instance for given type.
-
#create_strategy(type, dependencies = {}) ⇒ Object
Create strategy instance for given type.
-
#initialize ⇒ DiagramTypeRegistry
constructor
Initialize registry.
-
#type_exists?(type) ⇒ Boolean
Check if a diagram type exists.
-
#type_metadata(type) ⇒ Hash
Get metadata for a specific diagram type.
Constructor Details
#initialize ⇒ DiagramTypeRegistry
Initialize registry
46 47 48 49 50 51 52 53 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 46 def initialize @logger = if defined?(Rails) && Rails.respond_to?(:logger) Rails.logger else require "logger" Logger.new($stdout) end end |
Instance Method Details
#available_types ⇒ Array<String>
Get list of available diagram type keys
58 59 60 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 58 def available_types DIAGRAM_TYPES.keys end |
#available_types_with_metadata ⇒ Hash
Get available types with metadata
65 66 67 68 69 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 65 def DIAGRAM_TYPES.transform_values do |type_config| type_config.except(:strategy_class, :analyzer_class) end end |
#create_analyzer(type, session) ⇒ Object
Create analyzer instance for given type
93 94 95 96 97 98 99 100 101 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 93 def create_analyzer(type, session) type_config = find_type_config(type) analyzer_class = resolve_analyzer_class(type_config[:analyzer_class]) @logger.debug("Creating analyzer for type #{type}: #{analyzer_class.name}") analyzer_class.new(session) rescue StandardError => e raise UnknownTypeError, "Cannot create analyzer for type '#{type}': #{e.}" end |
#create_strategy(type, dependencies = {}) ⇒ Object
Create strategy instance for given type
77 78 79 80 81 82 83 84 85 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 77 def create_strategy(type, dependencies = {}) type_config = find_type_config(type) strategy_class = resolve_strategy_class(type_config[:strategy_class]) @logger.debug("Creating strategy for type #{type}: #{strategy_class.name}") strategy_class.new(dependencies) rescue StandardError => e raise UnknownTypeError, "Cannot create strategy for type '#{type}': #{e.}" end |
#type_exists?(type) ⇒ Boolean
Check if a diagram type exists
107 108 109 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 107 def type_exists?(type) DIAGRAM_TYPES.key?(type) end |
#type_metadata(type) ⇒ Hash
Get metadata for a specific diagram type
116 117 118 119 |
# File 'lib/dbwatcher/services/diagram_type_registry.rb', line 116 def (type) type_config = find_type_config(type) type_config.except(:strategy_class, :analyzer_class) end |