Class: Kontena::Cli::Apps::YAML::Validations::CustomValidators::AffinitiesValidator
- Inherits:
-
HashValidator::Validator::Base
- Object
- HashValidator::Validator::Base
- Kontena::Cli::Apps::YAML::Validations::CustomValidators::AffinitiesValidator
- Defined in:
- lib/kontena/cli/apps/yaml/custom_validators/affinities_validator.rb
Instance Method Summary collapse
-
#initialize ⇒ AffinitiesValidator
constructor
A new instance of AffinitiesValidator.
- #validate(key, value, validations, errors) ⇒ Object
Constructor Details
#initialize ⇒ AffinitiesValidator
Returns a new instance of AffinitiesValidator.
3 4 5 |
# File 'lib/kontena/cli/apps/yaml/custom_validators/affinities_validator.rb', line 3 def initialize super('valid_affinities') end |
Instance Method Details
#validate(key, value, validations, errors) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kontena/cli/apps/yaml/custom_validators/affinities_validator.rb', line 7 def validate(key, value, validations, errors) unless value.is_a?(Array) errors[key] = 'affinity must be array' return end invalid_formats = value.find_all { |a| !a.match(/(?<=\!|\=)=/) } if invalid_formats.count > 0 errors[key] = "affinity contains invalid formats: #{invalid_formats.join(', ')}" end end |