Class: AbideDevUtils::CEM::Validate::Strings::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/validate/strings.rb

Overview

Holds various validation methods for a AbideDevUtils::Ppt::Strings object

Instance Method Summary collapse

Constructor Details

#initialize(puppet_strings = nil, **opts) ⇒ Validator

Returns a new instance of Validator.



22
23
24
25
26
27
28
29
# File 'lib/abide_dev_utils/cem/validate/strings.rb', line 22

def initialize(puppet_strings = nil, **opts)
  unless puppet_strings.nil? || puppet_strings.is_a?(AbideDevUtils::Ppt::Strings)
    raise ArgumentError, 'If puppet_strings is supplied, it must be a AbideDevUtils::Ppt::Strings object'
  end

  puppet_strings = AbideDevUtils::Ppt::Strings.new(**opts) if puppet_strings.nil?
  @puppet_strings = puppet_strings
end

Instance Method Details

#validateHash

Associate validators with each Puppet Strings object and calls #validate on each

Returns:

  • (Hash)

    Hash of validation results



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/abide_dev_utils/cem/validate/strings.rb', line 33

def validate
  AbideDevUtils::Ppt::Strings::REGISTRY_TYPES.each_with_object({}) do |rtype, hsh|
    next unless rtype.to_s.start_with?('puppet_') && @puppet_strings.respond_to?(rtype)

    hsh[rtype] = @puppet_strings.send(rtype).map do |item|
      item.validator = validator_for(item)
      item.validate
      validation_output(item)
    end
  end
end