Module: PDK::Validate

Defined in:
lib/pdk/validate.rb,
lib/pdk/validate/validator.rb,
lib/pdk/validate/validator_group.rb,
lib/pdk/validate/invokable_validator.rb,
lib/pdk/validate/internal_ruby_validator.rb,
lib/pdk/validate/ruby/ruby_validator_group.rb,
lib/pdk/validate/yaml/yaml_validator_group.rb,
lib/pdk/validate/external_command_validator.rb,
lib/pdk/validate/tasks/tasks_name_validator.rb,
lib/pdk/validate/yaml/yaml_syntax_validator.rb,
lib/pdk/validate/puppet/puppet_epp_validator.rb,
lib/pdk/validate/ruby/ruby_rubocop_validator.rb,
lib/pdk/validate/tasks/tasks_validator_group.rb,
lib/pdk/validate/puppet/puppet_lint_validator.rb,
lib/pdk/validate/puppet/puppet_validator_group.rb,
lib/pdk/validate/puppet/puppet_syntax_validator.rb,
lib/pdk/validate/metadata/metadata_validator_group.rb,
lib/pdk/validate/metadata/metadata_syntax_validator.rb,
lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb,
lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb,
lib/pdk/validate/metadata/metadata_json_lint_validator.rb,
lib/pdk/validate/control_repo/environment_conf_validator.rb,
lib/pdk/validate/control_repo/control_repo_validator_group.rb

Defined Under Namespace

Modules: ControlRepo, Metadata, Puppet, Ruby, Tasks, YAML Classes: ExternalCommandValidator, InternalRubyValidator, InvokableValidator, ParseOutputError, Validator, ValidatorGroup

Class Method Summary collapse

Class Method Details

.invoke_validators_by_name(context, names, parallel = false, options = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pdk/validate.rb', line 67

def self.invoke_validators_by_name(context, names, parallel = false, options = {})
  instances = names.select { |name| validator_names.include?(name) }
                   .map { |name| validator_hash[name].new(context, options) }
                   .select(&:valid_in_context?)
                   .each(&:prepare_invoke!)
  report = PDK::Report.new

  # Nothing to validate then nothing to do.
  return [0, report] if instances.empty?

  require 'pdk/cli/exec_group'
  exec_group = PDK::CLI::ExecGroup.create(
    format('Validating module using %{num_of_threads} threads', num_of_threads: instances.count),
    { parallel: parallel },
    options
  )

  instances.each do |validator|
    exec_group.register do
      validator.invoke(report)
    end
  end

  [exec_group.exit_code, report]
end

.validator_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pdk/validate.rb', line 55

def self.validator_hash
  # TODO: This isn't the most performant... But with only 6 items, it's fine
  @validator_hash ||= [
    ControlRepo::ControlRepoValidatorGroup,
    ::MetadataValidatorGroup,
    Puppet::PuppetValidatorGroup,
    Ruby::RubyValidatorGroup,
    Tasks::TasksValidatorGroup,
    YAML::YAMLValidatorGroup
  ].to_h { |klass| [klass.new.name, klass] }.freeze
end

.validator_namesObject



50
51
52
# File 'lib/pdk/validate.rb', line 50

def self.validator_names
  validator_hash.keys
end

.validatorsObject



46
47
48
# File 'lib/pdk/validate.rb', line 46

def self.validators
  validator_hash.values
end