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

Instance Method Details

#array_of_hashes?(value) ⇒ Boolean

Checks if the value is an Array of Hashes.

Parameters:

  • value (Any)

    The value to be checked.

Returns:

  • (Boolean)

    True if the value is an Array of Hashes, false otherwise.



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.

Parameters:

  • value (Any)

    The value to be checked.

Returns:

  • (Boolean)

    True if the value is not nil or empty, false otherwise.



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.

Parameters:

  • control_maps (Array)

    The control maps to be parsed.

Returns:

  • (Array)

    The control maps to be parsed.

Raises:

  • (ArgumentError)

    If the control_maps parameter is not a non-empty Array of Hashes.



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.

Parameters:

  • hiera_data (Hash)

    The Hiera data to be parsed.

Returns:

  • (Hash)

    The Hiera data to be parsed.

Raises:

  • (ArgumentError)

    If the hiera_data parameter is not a non-empty Hash.



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