Module: Henitai::ConfigurationValidator::Scalars

Defined in:
lib/henitai/configuration_validator/scalars.rb,
sig/configuration_validator.rbs

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

Instance Method Summary collapse

Class Method Details

.describe_array_type(value) ⇒ Object



161
162
163
164
165
166
# File 'lib/henitai/configuration_validator/scalars.rb', line 161

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



52
53
54
55
56
57
58
# File 'lib/henitai/configuration_validator/scalars.rb', line 52

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_checkpoint_every(value) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/henitai/configuration_validator/scalars.rb', line 114

def validate_checkpoint_every(value)
  return if value.nil?
  return if value.is_a?(Integer) && value.positive?

  Rules.configuration_error(
    "Invalid configuration value for reports.checkpoint_every: expected Integer > 0, got #{value.inspect}"
  )
end

.validate_checkpoint_interval(value) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/henitai/configuration_validator/scalars.rb', line 123

def validate_checkpoint_interval(value)
  return if value.nil?
  return if value.is_a?(Numeric) && value.positive?

  Rules.configuration_error(
    "Invalid configuration value for reports.checkpoint_interval: expected positive Numeric, got #{value.inspect}"
  )
end

.validate_ignore_patterns(value) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/henitai/configuration_validator/scalars.rb', line 76

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.message}"
    )
  end
end

.validate_max_flaky_retries(value) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/henitai/configuration_validator/scalars.rb', line 87

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_max_log_bytes(value) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/henitai/configuration_validator/scalars.rb', line 96

def validate_max_log_bytes(value)
  return if value.nil?
  return if value.is_a?(Integer) && value.positive?

  Rules.configuration_error(
    "Invalid configuration value for mutation.max_log_bytes: expected Integer > 0, got #{value.inspect}"
  )
end

.validate_max_timeout(value) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/henitai/configuration_validator/scalars.rb', line 105

def validate_max_timeout(value)
  return if value.nil?
  return if value.is_a?(Numeric) && value.positive?

  Rules.configuration_error(
    "Invalid configuration value for mutation.max_timeout: expected positive Numeric, 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



60
61
62
63
64
65
# File 'lib/henitai/configuration_validator/scalars.rb', line 60

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



153
154
155
156
157
158
159
# File 'lib/henitai/configuration_validator/scalars.rb', line 153

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



132
133
134
135
136
137
138
139
140
# File 'lib/henitai/configuration_validator/scalars.rb', line 132

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



142
143
144
145
146
147
148
149
150
151
# File 'lib/henitai/configuration_validator/scalars.rb', line 142

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



67
68
69
70
71
72
73
74
# File 'lib/henitai/configuration_validator/scalars.rb', line 67

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



43
44
45
46
47
48
49
50
# File 'lib/henitai/configuration_validator/scalars.rb', line 43

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

.validate_timeout_multiplier(value) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/henitai/configuration_validator/scalars.rb', line 33

def validate_timeout_multiplier(value)
  return if value.nil?
  return if value.is_a?(Numeric) && value.positive?

  Rules.configuration_error(
    "Invalid configuration value for mutation.timeout_multiplier: " \
    "expected positive Numeric, got #{value.inspect}"
  )
end

Instance Method Details

#self?.describe_array_typeString

Parameters:

  • (Object)

Returns:

  • (String)


50
# File 'sig/configuration_validator.rbs', line 50

def self?.describe_array_type: (untyped) -> String

#self?.validate_booleanvoid

This method returns an undefined value.

Parameters:

  • (Object)
  • (String)


42
# File 'sig/configuration_validator.rbs', line 42

def self?.validate_boolean: (untyped, String) -> void

#self?.validate_ignore_patternsvoid

This method returns an undefined value.

Parameters:

  • (Object)


45
# File 'sig/configuration_validator.rbs', line 45

def self?.validate_ignore_patterns: (untyped) -> void

#self?.validate_max_flaky_retriesvoid

This method returns an undefined value.

Parameters:

  • (Object)


46
# File 'sig/configuration_validator.rbs', line 46

def self?.validate_max_flaky_retries: (untyped) -> void

#self?.validate_operatorvoid

This method returns an undefined value.

Parameters:

  • (Object)


39
# File 'sig/configuration_validator.rbs', line 39

def self?.validate_operator: (untyped) -> void

#self?.validate_optional_stringvoid

This method returns an undefined value.

Parameters:

  • (Object)
  • (String)


43
# File 'sig/configuration_validator.rbs', line 43

def self?.validate_optional_string: (untyped, String) -> void

#self?.validate_sampling_completenessvoid

This method returns an undefined value.

Parameters:

  • (Hash[Symbol, untyped])


49
# File 'sig/configuration_validator.rbs', line 49

def self?.validate_sampling_completeness: (Hash[Symbol, untyped]) -> void

#self?.validate_sampling_ratiovoid

This method returns an undefined value.

Parameters:

  • (Object)


47
# File 'sig/configuration_validator.rbs', line 47

def self?.validate_sampling_ratio: (untyped) -> void

#self?.validate_sampling_strategyvoid

This method returns an undefined value.

Parameters:

  • (Object)


48
# File 'sig/configuration_validator.rbs', line 48

def self?.validate_sampling_strategy: (untyped) -> void

#self?.validate_string_arrayvoid

This method returns an undefined value.

Parameters:

  • (Object)
  • (String)


44
# File 'sig/configuration_validator.rbs', line 44

def self?.validate_string_array: (untyped, String) -> void

#self?.validate_thresholdvoid

This method returns an undefined value.

Parameters:

  • (Object)
  • (String)


41
# File 'sig/configuration_validator.rbs', line 41

def self?.validate_threshold: (untyped, String) -> void

#self?.validate_timeoutvoid

This method returns an undefined value.

Parameters:

  • (Object)


40
# File 'sig/configuration_validator.rbs', line 40

def self?.validate_timeout: (untyped) -> void