Class: Kontena::Cli::Apps::YAML::Validations::CustomValidators::ExtendsValidator
- Inherits:
-
HashValidator::Validator::Base
- Object
- HashValidator::Validator::Base
- Kontena::Cli::Apps::YAML::Validations::CustomValidators::ExtendsValidator
- Defined in:
- lib/kontena/cli/apps/yaml/custom_validators/extends_validator.rb
Instance Method Summary collapse
-
#initialize ⇒ ExtendsValidator
constructor
A new instance of ExtendsValidator.
- #validate(key, value, validations, errors) ⇒ Object
Constructor Details
#initialize ⇒ ExtendsValidator
Returns a new instance of ExtendsValidator.
3 4 5 |
# File 'lib/kontena/cli/apps/yaml/custom_validators/extends_validator.rb', line 3 def initialize super('valid_extends') end |
Instance Method Details
#validate(key, value, validations, errors) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kontena/cli/apps/yaml/custom_validators/extends_validator.rb', line 7 def validate(key, value, validations, errors) unless value.is_a?(String) || value.is_a?(Hash) errors[key] = 'extends must be string or hash' return end if value.is_a?(Hash) extends_validation = { 'service' => 'string' } extends_validation['file'] = HashValidator.optional('string') if value['file'] extends_validation['stack'] = HashValidator.optional('string') if value['stack'] HashValidator.validator_for(extends_validation).validate(key, value, extends_validation, errors) end end |