Class: Kontena::Cli::Stacks::YAML::Validations::CustomValidators::BuildValidator

Inherits:
HashValidator::Validator::Base
  • Object
show all
Defined in:
lib/kontena/cli/stacks/yaml/custom_validators/build_validator.rb

Instance Method Summary collapse

Constructor Details

#initializeBuildValidator

Returns a new instance of BuildValidator.



3
4
5
# File 'lib/kontena/cli/stacks/yaml/custom_validators/build_validator.rb', line 3

def initialize
  super('stacks_valid_build')
end

Instance Method Details

#validate(key, value, validations, errors) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kontena/cli/stacks/yaml/custom_validators/build_validator.rb', line 7

def validate(key, value, validations, errors)
  unless value.is_a?(String) || value.is_a?(Hash)
    errors[key] = 'build must be string or hash'
    return
  end
  if value.is_a?(Hash)
    build_validation = {
      'context' => 'string',
      'dockerfile' => HashValidator.optional('string'),
      'args' => HashValidator.optional(-> (value) { value.is_a?(Array) || value.is_a?(Hash) })
    }
    HashValidator.validator_for(build_validation).validate(key, value, build_validation, errors)
  end
end