Module: AbideDataProcessor::Parser::Validation
- Included in:
- ProcessorObject, ResourceDataParser
- Defined in:
- lib/abide-data-processor/parser.rb
Overview
This module handles data validation for the CIS data parser
Instance Method Summary collapse
-
#array_of_hashes?(value) ⇒ Boolean
Checks if the value is an Array of Hashes.
-
#not_nil_or_empty?(value) ⇒ Boolean
Checks if the value is not nil or empty.
-
#validate_control_maps(control_maps) ⇒ Array
Validates the control_maps parameter and either raises an ArgumentError or returns the control_maps parameter.
-
#validate_hiera_data(hiera_data) ⇒ Hash
Validates the hiera_data parameter and either raises an ArgumentError or returns the hiera_data parameter.
Instance Method Details
#array_of_hashes?(value) ⇒ Boolean
Checks if the value is an Array of Hashes.
67 68 69 |
# 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 |
#not_nil_or_empty?(value) ⇒ Boolean
Checks if the value is not nil or empty.
60 61 62 |
# File 'lib/abide-data-processor/parser.rb', line 60 def not_nil_or_empty?(value) !value.nil? && !value.empty? end |
#validate_control_maps(control_maps) ⇒ Array
Validates the control_maps parameter and either raises an ArgumentError or returns the control_maps parameter.
49 50 51 52 53 54 55 |
# 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 |
#validate_hiera_data(hiera_data) ⇒ Hash
Validates the hiera_data parameter and either raises an ArgumentError or returns the hiera_data parameter.
35 36 37 38 39 40 41 42 43 |
# 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 |