Method: PDK::Config::IniFileSetting#validate!

Defined in:
lib/pdk/config/ini_file_setting.rb

#validate!(value) ⇒ Object

Verifies that the new setting value is valid in an Ini File

See Also:

  • Setting.validate!


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdk/config/ini_file_setting.rb', line 18

def validate!(value)
  # We're very restrictive here. Realistically Ini files only have string types
  return if value.nil? || value.is_a?(String) || value.is_a?(Integer)
  # The only other valid-ish type is a Hash
  unless value.is_a?(Hash)
    raise ArgumentError, 'The setting %{key} may only be a String or Integer, not %{class}' % {
      key:  qualified_name,
      class: value.class,
    }
  end
  # Any hashes can only have a single String/Integer value
  value.each do |child_name, child_value|
    next if child_value.nil? || child_value.is_a?(String) || child_value.is_a?(Integer)
    raise ArgumentError, 'The setting %{key} may only be a String or Integer, not %{class}' % {
      key:   qualified_name + '.' + child_name,
      class: child_value.class,
    }
  end
end