Class: Lutaml::ModelTransformations::Configuration
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Lutaml::ModelTransformations::Configuration
- Defined in:
- lib/lutaml/model_transformations/configuration.rb
Overview
Configuration service for model transformations using external YAML configuration.
This class follows the Dependency Inversion Principle by allowing external configuration instead of hardcoded behavior. It uses lutaml-model for structured YAML parsing and validation.
Defined Under Namespace
Classes: ErrorHandling, FormatDetection, ParserConfig, TransformationOptions
Class Method Summary collapse
-
.create_default_configuration ⇒ Configuration
Create default configuration when no config file exists.
-
.default_config_path ⇒ String
Get default configuration file path.
-
.load(config_path = nil) ⇒ Configuration
Load configuration from YAML file.
Instance Method Summary collapse
-
#content_sniffing_enabled? ⇒ Boolean
Check if content sniffing is enabled.
-
#enabled_formats ⇒ Array<String>
Get all enabled format names.
-
#enabled_parsers ⇒ Array<ParserConfig>
Get list of enabled parsers, sorted by priority.
-
#error_handling ⇒ ErrorHandling
Get error handling configuration with defaults.
-
#fallback_parser ⇒ String?
Get fallback parser when format detection fails.
-
#file_extension_detection_enabled? ⇒ Boolean
Check if file extension detection is enabled.
-
#format_enabled?(format) ⇒ Boolean
Check if a format is enabled.
-
#merge(other) ⇒ Configuration
Merge with another configuration (this takes precedence).
-
#parser_config_for(format) ⇒ ParserConfig?
Get parser configuration by format name.
-
#parser_config_for_extension(extension) ⇒ ParserConfig?
Get parser configuration by file extension.
-
#supported_extensions ⇒ Array<String>
Get all supported file extensions.
-
#transformation_options ⇒ TransformationOptions
Get transformation options with defaults.
Class Method Details
.create_default_configuration ⇒ Configuration
Create default configuration when no config file exists
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 145 def create_default_configuration new.tap do |config| config.version = "1.0" config.description = "Default Model Transformations Configuration" # Default parsers config.parsers = [ create_xmi_parser_config, create_qea_parser_config, ] # Default options config. = TransformationOptions.new config.format_detection = FormatDetection.new config.error_handling = ErrorHandling.new end end |
.default_config_path ⇒ String
Get default configuration file path
138 139 140 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 138 def default_config_path File.("../../../config/model_transformations.yml", __dir__) end |
.load(config_path = nil) ⇒ Configuration
Load configuration from YAML file
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 123 def load(config_path = nil) config_path ||= default_config_path unless File.exist?(config_path) # Create default configuration if none exists return create_default_configuration end yaml_content = File.read(config_path) from_yaml(yaml_content) end |
Instance Method Details
#content_sniffing_enabled? ⇒ Boolean
Check if content sniffing is enabled
250 251 252 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 250 def content_sniffing_enabled? format_detection&.use_content_sniffing == true end |
#enabled_formats ⇒ Array<String>
Get all enabled format names
236 237 238 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 236 def enabled_formats enabled_parsers.map(&:format) end |
#enabled_parsers ⇒ Array<ParserConfig>
Get list of enabled parsers, sorted by priority
199 200 201 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 199 def enabled_parsers parsers&.select(&:enabled)&.sort_by { |p| -p.priority } || [] end |
#error_handling ⇒ ErrorHandling
Get error handling configuration with defaults
278 279 280 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 278 def error_handling @error_handling ||= ErrorHandling.new end |
#fallback_parser ⇒ String?
Get fallback parser when format detection fails
264 265 266 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 264 def fallback_parser format_detection&.fallback_parser end |
#file_extension_detection_enabled? ⇒ Boolean
Check if file extension detection is enabled
257 258 259 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 257 def file_extension_detection_enabled? format_detection&.use_file_extension == true end |
#format_enabled?(format) ⇒ Boolean
Check if a format is enabled
228 229 230 231 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 228 def format_enabled?(format) parser = parser_config_for(format) parser&.enabled == true end |
#merge(other) ⇒ Configuration
Merge with another configuration (this takes precedence)
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 286 def merge(other) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength merged = self.class.new # Basic attributes merged.version = version || other.version merged.description = description || other.description # Merge parsers (this config takes precedence) merged.parsers = merge_parsers(other.parsers) # Use this config's options, fallback to other merged. = || other. merged.format_detection = format_detection || other.format_detection merged.error_handling = error_handling || other.error_handling merged end |
#parser_config_for(format) ⇒ ParserConfig?
Get parser configuration by format name
207 208 209 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 207 def parser_config_for(format) parsers&.find { |p| p.format == format.downcase } end |
#parser_config_for_extension(extension) ⇒ ParserConfig?
Get parser configuration by file extension
215 216 217 218 219 220 221 222 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 215 def parser_config_for_extension(extension) normalized_ext = extension.downcase unless normalized_ext.start_with?(".") normalized_ext = ".#{normalized_ext}" end enabled_parsers.find { |p| p.handles_extension?(normalized_ext) } end |
#supported_extensions ⇒ Array<String>
Get all supported file extensions
243 244 245 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 243 def supported_extensions enabled_parsers.filter_map(&:extension) end |
#transformation_options ⇒ TransformationOptions
Get transformation options with defaults
271 272 273 |
# File 'lib/lutaml/model_transformations/configuration.rb', line 271 def @transformation_options ||= TransformationOptions.new end |