Class: Lutaml::UmlRepository::RepositoryEnhanced

Inherits:
Repository
  • Object
show all
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.

Examples:

Enhanced XMI parsing

repo = RepositoryEnhanced.from_model("model.xmi")

Enhanced QEA parsing

repo = RepositoryEnhanced.from_model("model.qea")

With custom configuration

config = ModelTransformations::Configuration.load("my_config.yml")
repo = RepositoryEnhanced.from_model("model.qea", config: config)

Instance Attribute Summary collapse

Attributes inherited from Repository

#document, #indexes, #metadata

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • document (Lutaml::Uml::Document)

    The UML document

  • indexes (Hash, nil) (defaults to: nil)

    Pre-built indexes

  • transformation_engine (defaults to: nil)
  • transformation_metadata (Hash) (defaults to: {})


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_engineModelTransformations::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_metadataHash (readonly)

Returns Transformation metadata.

Returns:

  • (Hash)

    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

Parameters:



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

Parameters:

  • file_path (String)

    Path to analyze

Returns:

  • (String, nil)

    Detected format name or nil



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

Parameters:

  • options (Hash)

    Repository options

Returns:

  • (Hash)

    Parsing 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.extract_parsing_options(options) # rubocop:disable Metrics/MethodLength
  parsing_options = {}

  # Map repository options to parsing options
  if options.key?(:validate)
    parsing_options[:validate_output] =
      options[:validate]
  end
  if options.key?(:include_diagrams)
    parsing_options[:include_diagrams] =
      options[:include_diagrams]
  end
  if options.key?(:resolve_references)
    parsing_options[:resolve_references] =
      options[:resolve_references]
  end

  parsing_options
end

.extract_transformation_metadata(engine, file_path) ⇒ Hash

Extract transformation metadata from engine

Transformation engine

Parameters:

Returns:

  • (Hash)

    Transformation metadata



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

Parameters:

  • file_path (String)

    Path to model file

  • options (Hash) (defaults to: {})

    Loading options

Returns:



122
123
124
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 122

def self.from_file_enhanced(file_path, options = {})
  from_model(file_path, options)
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)

Parameters:

  • model_path (String)

    Path to the model file

  • options (Hash) (defaults to: {})

    Parsing and repository options

Options Hash (options):

  • :config (ModelTransformations::Configuration)
  • :validate (Boolean)

    Validate model after parsing

  • :lazy (Boolean)

    Enable lazy loading

  • :preset (Symbol)

    Use configuration preset

Returns:



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, options = {}) # rubocop:disable Metrics/MethodLength
  # Setup transformation engine with custom config if provided
  engine = setup_transformation_engine(options)

  # Apply preset if specified
  apply_preset(engine, options[:preset]) if options[:preset]

  # Parse model using unified transformation system
  document = engine.parse(model_path, extract_parsing_options(options))

  # Build indexes
  indexes = options[: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 options[:validate]

  enhanced_repo
end

.from_package_enhanced(lur_path, _options = {}) ⇒ RepositoryEnhanced

Load from LUR package with transformation metadata

Parameters:

  • lur_path (String)

    Path to LUR package

  • options (Hash)

    Loading options

Returns:



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, _options = {}) # 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

Parameters:

  • qea_path (String)

    Path to QEA file

  • options (Hash) (defaults to: {})

    Options for parsing

Returns:



113
114
115
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 113

def self.from_qea_enhanced(qea_path, options = {})
  from_model(qea_path, options.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.

Parameters:

  • xmi_path (String)

    Path to XMI file

  • options (Hash) (defaults to: {})

    Options for parsing

Returns:



104
105
106
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 104

def self.from_xmi_enhanced(xmi_path, options = {})
  from_model(xmi_path, options.merge(format_hint: :xmi))
end

.setup_transformation_engine(options) ⇒ ModelTransformations::TransformationEngine

Setup transformation engine with custom configuration

Parameters:

  • options (Hash)

    Setup options

Returns:



286
287
288
289
290
291
292
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 286

def self.setup_transformation_engine(options)
  if options[:config]
    ModelTransformations::TransformationEngine.new(options[:config])
  else
    ModelTransformations.engine
  end
end

.supported_extensionsArray<String>

Get list of supported file extensions

Returns:

  • (Array<String>)

    Supported 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

Parameters:

  • file_path (String)

    Path to check

Returns:

  • (Boolean)

    true if format is supported



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

Parameters:

  • output_path (String)

    Path for output file

  • options (Hash) (defaults to: {})

    Export options



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, options = {})
  # Include transformation metadata in export
  enhanced_options = options.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, enhanced_options)
end

#parsing_historyArray<Hash>

Get parsing history for the source file

Returns:

  • (Array<Hash>)

    Parsing history entries



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

Parameters:

  • extension (String)

    File extension

  • parser_class (Class)

    Parser class



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_enhancedHash

Get comprehensive statistics including transformation info

Returns:

  • (Hash)

    Enhanced statistics



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_infoHash

Get transformation statistics and metadata

Returns:

  • (Hash)

    Comprehensive transformation information



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

Parameters:



276
277
278
# File 'lib/lutaml/uml_repository/repository_enhanced.rb', line 276

def update_configuration(config)
  @transformation_engine.configuration = config
end

#validate_enhancedHash

Validate with enhanced error reporting

Returns:

  • (Hash)

    Enhanced validation results



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