Class: Lutaml::Xsd::Validation::ValidationConfiguration
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Validation::ValidationConfiguration
- 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.
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
Default configuration file path
File.join( __dir__, "..", "..", "..", "..", "config", "validation.yml" )
Instance Attribute Summary collapse
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
Class Method Summary collapse
-
.default ⇒ ValidationConfiguration
Load default configuration.
-
.default_config_hash ⇒ Hash
Default configuration hash.
-
.from_file(path) ⇒ ValidationConfiguration
Load configuration from YAML file.
Instance Method Summary collapse
-
#allow_network? ⇒ Boolean
Check if network access is allowed for schema resolution.
-
#cache_dir ⇒ String
Get schema cache directory.
-
#cache_schemas? ⇒ Boolean
Check if schemas should be cached.
-
#colorize_output? ⇒ Boolean
Check if colorized output is enabled.
-
#feature_enabled?(feature) ⇒ Boolean
Check if a validation feature is enabled.
-
#include_line_number? ⇒ Boolean
Check if line numbers should be included in errors.
-
#include_suggestions? ⇒ Boolean
Check if suggestions should be included in errors.
-
#include_xpath? ⇒ Boolean
Check if XPath should be included in errors.
-
#initialize(config_hash = {}) ⇒ ValidationConfiguration
constructor
Initialize configuration from hash.
-
#max_errors ⇒ Integer
Get maximum number of errors to collect.
-
#network_timeout ⇒ Integer
Get network timeout for schema fetching.
-
#stop_on_first_error? ⇒ Boolean
Check if validation should stop on first error.
-
#strict_mode? ⇒ Boolean
Check if strict mode is enabled.
-
#to_h ⇒ Hash
Convert configuration to hash.
-
#verbosity ⇒ Symbol
Get error reporting verbosity level.
Constructor Details
#initialize(config_hash = {}) ⇒ ValidationConfiguration
Initialize configuration from hash
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_hash ⇒ Object (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
.default ⇒ ValidationConfiguration
Load default configuration
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_hash ⇒ Hash
Default configuration 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
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.})" rescue Psych::SyntaxError => e raise ConfigurationError, "Invalid YAML in configuration file: #{path} (#{e.})" end |
Instance Method Details
#allow_network? ⇒ Boolean
Check if network access is allowed for schema resolution
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_dir ⇒ String
Get schema cache directory
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
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
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
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
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
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
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_errors ⇒ Integer
Get maximum number of errors to collect
84 85 86 |
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 84 def max_errors get_nested("validation", "max_errors") || 100 end |
#network_timeout ⇒ Integer
Get network timeout for schema fetching
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
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
70 71 72 |
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 70 def strict_mode? get_nested("validation", "strict_mode") || false end |
#to_h ⇒ Hash
Convert configuration to hash
171 172 173 |
# File 'lib/lutaml/xsd/validation/validation_configuration.rb', line 171 def to_h deep_dup(@config_hash) end |
#verbosity ⇒ Symbol
Get error reporting verbosity level
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 |