Class: Lutaml::Xsd::Validation::ValidationConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/validation/validation_configuration.rb

Overview

ValidationConfiguration manages validation behavior settings

This class loads and manages all configuration settings for XML validation. It supports loading from YAML files, Hash objects, or using sensible defaults.

Examples:

Load from YAML file

config = ValidationConfiguration.from_file("config/validation.yml")

Create from Hash

config = ValidationConfiguration.new({
  strict_mode: true,
  stop_on_first_error: false
})

Use defaults

config = ValidationConfiguration.default

Constant Summary collapse

DEFAULT_CONFIG_PATH =

Default configuration file path

File.join(
  __dir__, "..", "..", "..", "..", "config", "validation.yml"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash = {}) ⇒ ValidationConfiguration

Initialize configuration from hash

Parameters:

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

    Configuration settings



36
37
38
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 36

def initialize(config_hash = {})
  @config_hash = config_hash
end

Instance Attribute Details

#config_hashObject (readonly)

Returns the value of attribute config_hash.



26
27
28
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 26

def config_hash
  @config_hash
end

Class Method Details

.defaultValidationConfiguration

Load default configuration

Returns:



59
60
61
62
63
64
65
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 59

def self.default
  if File.exist?(DEFAULT_CONFIG_PATH)
    from_file(DEFAULT_CONFIG_PATH)
  else
    new(default_config_hash)
  end
end

.default_config_hashHash

Default configuration hash

Returns:

  • (Hash)


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 226

def self.default_config_hash
  {
    "validation" => {
      "strict_mode" => true,
      "stop_on_first_error" => false,
      "max_errors" => 100,
      "features" => {
        "validate_types" => true,
        "validate_attributes" => true,
        "validate_occurrences" => true,
        "validate_identity_constraints" => true,
        "validate_facets" => true,
        "validate_content_models" => true,
        "validate_namespaces" => true,
      },
      "error_reporting" => {
        "include_xpath" => true,
        "include_line_number" => true,
        "include_suggestions" => true,
        "colorize" => true,
        "verbosity" => "normal",
      },
      "schema_resolution" => {
        "allow_network" => true,
        "cache_schemas" => true,
        "cache_dir" => "tmp/schema_cache",
        "network_timeout" => 30,
      },
    },
  }
end

.from_file(path) ⇒ ValidationConfiguration

Load configuration from YAML file

Parameters:

  • path (String)

    Path to YAML configuration file

Returns:

Raises:



45
46
47
48
49
50
51
52
53
54
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 45

def self.from_file(path)
  yaml_content = YAML.load_file(path)
  new(yaml_content)
rescue Errno::ENOENT => e
  raise ConfigurationError,
        "Configuration file not found: #{path} (#{e.message})"
rescue Psych::SyntaxError => e
  raise ConfigurationError,
        "Invalid YAML in configuration file: #{path} (#{e.message})"
end

Instance Method Details

#allow_network?Boolean

Check if network access is allowed for schema resolution

Returns:

  • (Boolean)


139
140
141
142
143
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 139

def allow_network?
  get_nested(
    "validation", "schema_resolution", "allow_network"
  ) != false
end

#cache_dirString

Get schema cache directory

Returns:

  • (String)


156
157
158
159
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 156

def cache_dir
  get_nested("validation", "schema_resolution", "cache_dir") ||
    "tmp/schema_cache"
end

#cache_schemas?Boolean

Check if schemas should be cached

Returns:

  • (Boolean)


148
149
150
151
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 148

def cache_schemas?
  get_nested("validation", "schema_resolution",
             "cache_schemas") != false
end

#colorize_output?Boolean

Check if colorized output is enabled

Returns:

  • (Boolean)


107
108
109
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 107

def colorize_output?
  get_nested("validation", "error_reporting", "colorize") != false
end

#feature_enabled?(feature) ⇒ Boolean

Check if a validation feature is enabled

Parameters:

  • feature (Symbol)

    Feature name (e.g., :validate_types)

Returns:

  • (Boolean)


92
93
94
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 92

def feature_enabled?(feature)
  get_nested("validation", "features", feature.to_s) != false
end

#include_line_number?Boolean

Check if line numbers should be included in errors

Returns:

  • (Boolean)


121
122
123
124
125
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 121

def include_line_number?
  get_nested(
    "validation", "error_reporting", "include_line_number"
  ) != false
end

#include_suggestions?Boolean

Check if suggestions should be included in errors

Returns:

  • (Boolean)


130
131
132
133
134
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 130

def include_suggestions?
  get_nested(
    "validation", "error_reporting", "include_suggestions"
  ) != false
end

#include_xpath?Boolean

Check if XPath should be included in errors

Returns:

  • (Boolean)


114
115
116
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 114

def include_xpath?
  get_nested("validation", "error_reporting", "include_xpath") != false
end

#max_errorsInteger

Get maximum number of errors to collect

Returns:

  • (Integer)


84
85
86
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 84

def max_errors
  get_nested("validation", "max_errors") || 100
end

#network_timeoutInteger

Get network timeout for schema fetching

Returns:

  • (Integer)

    Timeout in seconds



164
165
166
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 164

def network_timeout
  get_nested("validation", "schema_resolution", "network_timeout") || 30
end

#stop_on_first_error?Boolean

Check if validation should stop on first error

Returns:

  • (Boolean)


77
78
79
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 77

def stop_on_first_error?
  get_nested("validation", "stop_on_first_error") || false
end

#strict_mode?Boolean

Check if strict mode is enabled

Returns:

  • (Boolean)


70
71
72
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 70

def strict_mode?
  get_nested("validation", "strict_mode") || false
end

#to_hHash

Convert configuration to hash

Returns:

  • (Hash)


171
172
173
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 171

def to_h
  deep_dup(@config_hash)
end

#verbositySymbol

Get error reporting verbosity level

Returns:

  • (Symbol)

    :minimal, :normal, :verbose, or :debug



99
100
101
102
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 99

def verbosity
  level = get_nested("validation", "error_reporting", "verbosity")
  (level || "normal").to_sym
end