module AbideDataProcessor::Parser::Validation
This module handles data validation for the CIS data parser
Public Instance Methods
Checks if the value is an Array of Hashes. @param value [Any] The value to be checked. @return [Boolean] True if the value is an Array of Hashes, false otherwise.
# File lib/abide-data-processor/parser.rb, line 67 def array_of_hashes?(value) value.is_a?(Array) && value.all? { |h| h.is_a?(Hash) } end
Checks if the value is not nil or empty. @param value [Any] The value to be checked. @return [Boolean] True if the value is not nil or empty, false otherwise.
# File lib/abide-data-processor/parser.rb, line 60 def not_nil_or_empty?(value) !value.nil? && !value.empty? end
Validates the control_maps parameter and either raises an ArgumentError or returns the control_maps parameter. @param control_maps [Array] The control maps to be parsed. @return [Array] The control maps to be parsed. @raise [ArgumentError] If the control_maps parameter is not a non-empty Array of Hashes.
# File lib/abide-data-processor/parser.rb, line 49 def validate_control_maps(control_maps) unless not_nil_or_empty?(control_maps) && array_of_hashes?(control_maps) raise ArgumentError, 'control_maps must be a non-nil, non-empty Array of Hashes' end control_maps end
Validates the hiera_data parameter and either raises an ArgumentError or returns the hiera_data parameter. @param hiera_data [Hash] The Hiera data to be parsed. @return [Hash] The Hiera data to be parsed. @raise [ArgumentError] If the hiera_data parameter is not a non-empty Hash.
# File lib/abide-data-processor/parser.rb, line 35 def validate_hiera_data(hiera_data) return hiera_data if hiera_data == :no_params unless not_nil_or_empty?(hiera_data) && hiera_data.is_a?(Hash) raise ArgumentError, 'hiera_data must be a non-nil, non-empty Hash' end hiera_data end