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.
Constant Summary collapse
- WARNING_SCORE_PENALTY =
5- ERROR_SCORE_PENALTY =
10- SLOW_PARSING_THRESHOLD =
60- MAX_ERRORS_FOR_VALID =
5- PARSING_OPTION_KEYS =
%i[validate include_diagrams resolve_references].freeze
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_attributes, #all_classes, #all_diagrams, #ancestors_of, #associations_index, #associations_of, #classes_in_package, #classes_index, #descendants_of, #diagrams_in_package, #diagrams_index, #export_to_package, #find_attribute, #find_class, #find_classes_by_stereotype, #find_diagram, #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, #statistics, #subtypes_of, #supertype_of, #validate
Methods included from Lutaml::UmlRepository::Repository::Deprecated
#export, #find_associations, #find_children, #find_diagrams, #search_classes
Constructor Details
#initialize(document:, indexes: nil, transformation_engine: nil, transformation_metadata: {}) ⇒ RepositoryEnhanced
Initialize enhanced repository
- ModelTransformations::TransformationEngine, nil
-
Custom engine
Metadata from transformation process
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 48 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
35 36 37 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 35 def transformation_engine @transformation_engine end |
#transformation_metadata ⇒ Hash (readonly)
Returns Transformation metadata.
38 39 40 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 38 def @transformation_metadata end |
Class Method Details
.apply_preset(_engine, preset) ⇒ void
This method returns an undefined value.
Apply configuration preset
Engine to configure
305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 305 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
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 201 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
322 323 324 325 326 327 328 329 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 322 def self.() .slice(*PARSING_OPTION_KEYS).tap do |parsed| if parsed.key?(:validate) parsed[:validate_output] = parsed.delete(:validate) end end end |
.extract_transformation_metadata(engine, file_path) ⇒ Hash
Extract transformation metadata from engine
Transformation engine
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 337 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
127 128 129 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 127 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)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 73 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
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 136 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
118 119 120 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 118 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.
109 110 111 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 109 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
291 292 293 294 295 296 297 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 291 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
193 194 195 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 193 def self.supported_extensions ModelTransformations.engine.supported_extensions end |
.supports_file?(file_path) ⇒ Boolean
Check if repository supports a file format
186 187 188 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 186 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
217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 217 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
175 176 177 178 179 180 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 175 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
273 274 275 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 273 def register_parser(extension, parser_class) @transformation_engine.register_parser(extension, parser_class) end |
#statistics_enhanced ⇒ Hash
Get comprehensive statistics including transformation info
253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 253 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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 155 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.class.method_defined?(: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
281 282 283 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 281 def update_configuration(config) @transformation_engine.configuration = config end |
#validate_enhanced ⇒ Hash
Validate with enhanced error reporting
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 234 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 |