Module: Henitai::ConfigurationValidator::Scalars
- Defined in:
- lib/henitai/configuration_validator/scalars.rb
Overview
Leaf validators for individual configuration values.
Each method returns silently for an acceptable value or raises Henitai::ConfigurationError via Rules.configuration_error.
Class Method Summary collapse
- .describe_array_type(value) ⇒ Object
- .validate_boolean(value, path) ⇒ Object
- .validate_ignore_patterns(value) ⇒ Object
- .validate_max_flaky_retries(value) ⇒ Object
- .validate_operator(value) ⇒ Object
- .validate_optional_string(value, path) ⇒ Object
- .validate_sampling_completeness(value) ⇒ Object
- .validate_sampling_ratio(value) ⇒ Object
- .validate_sampling_strategy(value) ⇒ Object
- .validate_string_array(value, path) ⇒ Object
- .validate_threshold(value, path) ⇒ Object
- .validate_timeout(value) ⇒ Object
Class Method Details
.describe_array_type(value) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 115 def describe_array_type(value) return value.class.name unless value.is_a?(Array) element_types = value.map { |item| item.class.name }.uniq.join(", ") "Array<#{element_types}>" end |
.validate_boolean(value, path) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 42 def validate_boolean(value, path) return if [true, false].include?(value) Rules.configuration_error( "Invalid configuration value for #{path}: expected true or false, got #{value.inspect}" ) end |
.validate_ignore_patterns(value) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 66 def validate_ignore_patterns(value) Array(value).each do |pattern| Regexp.new(pattern) rescue RegexpError => e Rules.configuration_error( "Invalid configuration value for mutation.ignore_patterns: " \ "invalid regular expression #{pattern.inspect}: #{e.}" ) end end |
.validate_max_flaky_retries(value) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 77 def validate_max_flaky_retries(value) return if value.nil? return if value.is_a?(Integer) && value >= 0 Rules.configuration_error( "Invalid configuration value for mutation.max_flaky_retries: expected Integer >= 0, got #{value.inspect}" ) end |
.validate_operator(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 12 def validate_operator(value) return if value.nil? operator = value.respond_to?(:to_sym) ? value.to_sym : nil return if VALID_OPERATORS.include?(operator) Rules.configuration_error( "Invalid configuration value for mutation.operators: expected one of " \ "#{VALID_OPERATORS.join(', ')}, got #{value.inspect}" ) end |
.validate_optional_string(value, path) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 50 def validate_optional_string(value, path) return if value.nil? return if value.is_a?(String) Rules.configuration_error("Invalid configuration value for #{path}: expected String, got #{value.class}") end |
.validate_sampling_completeness(value) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 107 def validate_sampling_completeness(value) return if value.key?(:ratio) && value.key?(:strategy) Rules.configuration_error( "Invalid configuration value for mutation.sampling: expected both ratio and strategy" ) end |
.validate_sampling_ratio(value) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 86 def validate_sampling_ratio(value) return if value.nil? return if value.is_a?(Numeric) && value >= 0.0 && value <= 1.0 Rules.configuration_error( "Invalid configuration value for mutation.sampling.ratio: " \ "expected Numeric between 0 and 1, got #{value.inspect}" ) end |
.validate_sampling_strategy(value) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 96 def validate_sampling_strategy(value) return if value.nil? strategy = value.respond_to?(:to_sym) ? value.to_sym : nil return if strategy == :stratified Rules.configuration_error( "Invalid configuration value for mutation.sampling.strategy: expected stratified, got #{value.inspect}" ) end |
.validate_string_array(value, path) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 57 def validate_string_array(value, path) return if value.nil? return if value.is_a?(Array) && value.all?(String) Rules.configuration_error( "Invalid configuration value for #{path}: expected Array<String>, got #{describe_array_type(value)}" ) end |
.validate_threshold(value, path) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 33 def validate_threshold(value, path) return if value.is_a?(Integer) && value.between?(0, 100) Rules.configuration_error( "Invalid configuration value for #{path}: expected Integer between 0 and 100, " \ "got #{value.inspect}" ) end |
.validate_timeout(value) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/henitai/configuration_validator/scalars.rb', line 24 def validate_timeout(value) return if value.nil? return if value.is_a?(Numeric) Rules.configuration_error( "Invalid configuration value for mutation.timeout: expected Numeric, got #{value.class}" ) end |