Class: Lutaml::UmlRepository::RepositoryEnhanced
- Inherits:
-
Repository
- Object
- Repository
- Lutaml::UmlRepository::RepositoryEnhanced
- Defined in:
- lib/lutaml/uml_repository/repository_enhanced.rb
Overview
Enhanced Repository with unified model transformation support.
This class extends the original Repository to support the new unified model transformation system, providing seamless integration with XMI, QEA, and future format parsers.
The enhanced repository follows SOLID principles and provides backward compatibility with existing code while enabling new transformation capabilities.
Instance Attribute Summary collapse
-
#transformation_engine ⇒ ModelTransformations::TransformationEngine
readonly
The transformation engine.
-
#transformation_metadata ⇒ Hash
readonly
Transformation metadata.
Attributes inherited from Repository
#document, #indexes, #metadata
Class Method Summary collapse
-
.apply_preset(_engine, preset) ⇒ void
Apply configuration preset.
-
.detect_format(file_path) ⇒ String?
Detect format for a file.
-
.extract_parsing_options(options) ⇒ Hash
Extract parsing options from repository options.
-
.extract_transformation_metadata(engine, file_path) ⇒ Hash
Extract transformation metadata from engine.
-
.from_file_enhanced(file_path, options = {}) ⇒ RepositoryEnhanced
Auto-detect and load from file with enhanced capabilities.
-
.from_model(model_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from any supported model format.
-
.from_package_enhanced(lur_path, _options = {}) ⇒ RepositoryEnhanced
Load from LUR package with transformation metadata.
-
.from_qea_enhanced(qea_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from QEA.
-
.from_xmi_enhanced(xmi_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from XMI with legacy compatibility.
-
.setup_transformation_engine(options) ⇒ ModelTransformations::TransformationEngine
Setup transformation engine with custom configuration.
-
.supported_extensions ⇒ Array<String>
Get list of supported file extensions.
-
.supports_file?(file_path) ⇒ Boolean
Check if repository supports a file format.
Instance Method Summary collapse
-
#export_to_package_enhanced(output_path, options = {}) ⇒ void
Export with enhanced metadata.
-
#initialize(document:, indexes: nil, transformation_engine: nil, transformation_metadata: {}) ⇒ RepositoryEnhanced
constructor
Initialize enhanced repository.
-
#parsing_history ⇒ Array<Hash>
Get parsing history for the source file.
-
#register_parser(extension, parser_class) ⇒ void
Register custom parser with the transformation engine.
-
#statistics_enhanced ⇒ Hash
Get comprehensive statistics including transformation info.
-
#transformation_info ⇒ Hash
Get transformation statistics and metadata.
-
#update_configuration(config) ⇒ void
Update transformation engine configuration.
-
#validate_enhanced ⇒ Hash
Validate with enhanced error reporting.
Methods inherited from Repository
#all_classes, #all_diagrams, #ancestors_of, #associations_index, #associations_of, #classes_in_package, #classes_index, #descendants_of, #diagrams_in_package, #diagrams_index, #export, #export_to_package, #find_associations, #find_children, #find_class, #find_classes_by_stereotype, #find_diagram, #find_diagrams, #find_package, from_file, from_file_cached, from_file_lazy, from_package, from_package_lazy, from_xmi, from_xmi_lazy, #list_packages, #marshal_dump, #marshal_load, #package_tree, #packages_index, #qualified_name_for, #query, #query!, #search, #search_classes, #statistics, #subtypes_of, #supertype_of, #validate
Constructor Details
#initialize(document:, indexes: nil, transformation_engine: nil, transformation_metadata: {}) ⇒ RepositoryEnhanced
Initialize enhanced repository
- ModelTransformations::TransformationEngine, nil
-
Custom engine
Metadata from transformation process
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 43 def initialize( document:, indexes: nil, transformation_engine: nil, transformation_metadata: {} ) super(document: document, indexes: indexes) @transformation_engine = transformation_engine || ModelTransformations.engine @transformation_metadata = .freeze end |
Instance Attribute Details
#transformation_engine ⇒ ModelTransformations::TransformationEngine (readonly)
The transformation engine
30 31 32 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 30 def transformation_engine @transformation_engine end |
#transformation_metadata ⇒ Hash (readonly)
Returns Transformation metadata.
33 34 35 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 33 def @transformation_metadata end |
Class Method Details
.apply_preset(_engine, preset) ⇒ void
This method returns an undefined value.
Apply configuration preset
Engine to configure
300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 300 def self.apply_preset(_engine, preset) # This would apply preset configurations from the YAML config # For now, this is a placeholder for future implementation case preset when :fast # Apply fast parsing settings when :comprehensive # Apply comprehensive parsing settings when :production # Apply production settings end end |
.detect_format(file_path) ⇒ String?
Detect format for a file
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 196 def self.detect_format(file_path) parser_class = ModelTransformations.engine.detect_parser(file_path) return nil unless parser_class # Create temporary instance to get format name temp_parser = parser_class.new temp_parser.format_name rescue StandardError nil end |
.extract_parsing_options(options) ⇒ Hash
Extract parsing options from repository options
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 317 def self.() # rubocop:disable Metrics/MethodLength = {} # Map repository options to parsing options if .key?(:validate) [:validate_output] = [:validate] end if .key?(:include_diagrams) [:include_diagrams] = [:include_diagrams] end if .key?(:resolve_references) [:resolve_references] = [:resolve_references] end end |
.extract_transformation_metadata(engine, file_path) ⇒ Hash
Extract transformation metadata from engine
Transformation engine
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 343 def self.(engine, file_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity # Get the most recent transformation for this file history = engine.history_for_file(file_path) latest = history.last if latest { source_file: file_path, source_format: latest[:parser]&.format_name, parsed_at: latest[:timestamp], parser: latest[:parser]&.class&.name, parsing_duration: latest[:duration], success: latest[:success], warnings: latest[:parser]&.warnings || [], errors: latest[:parser]&.errors || [], } else { source_file: file_path, parsed_at: Time.now, } end end |
.from_file_enhanced(file_path, options = {}) ⇒ RepositoryEnhanced
Auto-detect and load from file with enhanced capabilities
122 123 124 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 122 def self.from_file_enhanced(file_path, = {}) from_model(file_path, ) end |
.from_model(model_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from any supported model format
This method auto-detects the format and uses the appropriate parser from the unified transformation system.
Custom configuration (:fast, :comprehensive, :production)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 68 def self.from_model(model_path, = {}) # rubocop:disable Metrics/MethodLength # Setup transformation engine with custom config if provided engine = setup_transformation_engine() # Apply preset if specified apply_preset(engine, [:preset]) if [:preset] # Parse model using unified transformation system document = engine.parse(model_path, ()) # Build indexes indexes = [:lazy] ? nil : IndexBuilder.build_all(document) # Create enhanced repository enhanced_repo = new( document: document, indexes: indexes, transformation_engine: engine, transformation_metadata: (engine, model_path), ) # Validate if requested enhanced_repo.validate if [:validate] enhanced_repo end |
.from_package_enhanced(lur_path, _options = {}) ⇒ RepositoryEnhanced
Load from LUR package with transformation metadata
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 131 def self.from_package_enhanced(lur_path, = {}) # rubocop:disable Metrics/MethodLength # Load using original method but wrap in enhanced repository original_repo = from_package(lur_path) new( document: original_repo.document, indexes: original_repo.indexes, transformation_metadata: { source_file: lur_path, source_format: "LUR Package", loaded_at: Time.now, loader: "Enhanced Package Loader", }, ) end |
.from_qea_enhanced(qea_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from QEA
113 114 115 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 113 def self.from_qea_enhanced(qea_path, = {}) from_model(qea_path, .merge(format_hint: :qea)) end |
.from_xmi_enhanced(xmi_path, options = {}) ⇒ RepositoryEnhanced
Build enhanced repository from XMI with legacy compatibility
This method provides backward compatibility with the original from_xmi method while using the new transformation system internally.
104 105 106 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 104 def self.from_xmi_enhanced(xmi_path, = {}) from_model(xmi_path, .merge(format_hint: :xmi)) end |
.setup_transformation_engine(options) ⇒ ModelTransformations::TransformationEngine
Setup transformation engine with custom configuration
286 287 288 289 290 291 292 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 286 def self.setup_transformation_engine() if [:config] ModelTransformations::TransformationEngine.new([:config]) else ModelTransformations.engine end end |
.supported_extensions ⇒ Array<String>
Get list of supported file extensions
188 189 190 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 188 def self.supported_extensions ModelTransformations.engine.supported_extensions end |
.supports_file?(file_path) ⇒ Boolean
Check if repository supports a file format
181 182 183 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 181 def self.supports_file?(file_path) ModelTransformations.engine.supports_file?(file_path) end |
Instance Method Details
#export_to_package_enhanced(output_path, options = {}) ⇒ void
This method returns an undefined value.
Export with enhanced metadata
212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 212 def export_to_package_enhanced(output_path, = {}) # Include transformation metadata in export = .merge( transformation_metadata: @transformation_metadata, engine_info: { engine_class: @transformation_engine.class.name, supported_formats: @transformation_engine.supported_extensions, configuration_version: @transformation_engine.configuration.version, }, ) export_to_package(output_path, ) end |
#parsing_history ⇒ Array<Hash>
Get parsing history for the source file
170 171 172 173 174 175 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 170 def parsing_history source_file = @transformation_metadata[:source_file] return [] unless source_file @transformation_engine.history_for_file(source_file) end |
#register_parser(extension, parser_class) ⇒ void
This method returns an undefined value.
Register custom parser with the transformation engine
268 269 270 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 268 def register_parser(extension, parser_class) @transformation_engine.register_parser(extension, parser_class) end |
#statistics_enhanced ⇒ Hash
Get comprehensive statistics including transformation info
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 248 def statistics_enhanced base_stats = statistics transformation_stats = { source_format: @transformation_metadata[:source_format], parsing_duration: @transformation_metadata[:parsing_duration], parser_used: @transformation_metadata[:parser], transformation_warnings: @transformation_metadata[:warnings]&.size || 0, transformation_errors: @transformation_metadata[:errors]&.size || 0, } base_stats.merge(transformation_stats: transformation_stats) end |
#transformation_info ⇒ Hash
Get transformation statistics and metadata
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 150 def transformation_info # rubocop:disable Metrics/MethodLength base_info = { source_file: @transformation_metadata[:source_file], source_format: @transformation_metadata[:source_format], parsed_at: @transformation_metadata[:parsed_at], parser: @transformation_metadata[:parser], transformation_engine: @transformation_engine.class.name, } # Add engine statistics if available if @transformation_engine.respond_to?(:statistics) base_info[:engine_statistics] = @transformation_engine.statistics end base_info end |
#update_configuration(config) ⇒ void
This method returns an undefined value.
Update transformation engine configuration
276 277 278 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 276 def update_configuration(config) @transformation_engine.configuration = config end |
#validate_enhanced ⇒ Hash
Validate with enhanced error reporting
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 229 def validate_enhanced # rubocop:disable Metrics/MethodLength base_validation = validate # Add transformation-specific validation transformation_validation = validate_transformation_quality { base_validation: base_validation, transformation_validation: transformation_validation, overall_valid: base_validation.valid? && transformation_validation[:valid], recommendations: generate_recommendations(base_validation, transformation_validation), } end |