Class: KubeDSL::Validations::KeyValueValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/kube-dsl/validations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name, options = {}) ⇒ KeyValueValidator

Returns a new instance of KeyValueValidator.



134
135
136
137
# File 'lib/kube-dsl/validations.rb', line 134

def initialize(field_name, options = {})
  @field_name = field_name
  @format_validator ||= FormatValidator.new(options[:value_format])
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



132
133
134
# File 'lib/kube-dsl/validations.rb', line 132

def field_name
  @field_name
end

#format_validatorObject (readonly)

Returns the value of attribute format_validator.



132
133
134
# File 'lib/kube-dsl/validations.rb', line 132

def format_validator
  @format_validator
end

Instance Method Details

#validate(obj, errors, nesting) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/kube-dsl/validations.rb', line 139

def validate(obj, errors, nesting)
  obj.kv_pairs.each_pair do |k, v|
    unless format_validator.valid?(v)
      errors.add(
        [*nesting, field_name].join('.'),
        "expected element '#{k}' to be a #{format_validator.klasses.map(&:to_s).join(', ')}, got #{v.class.name}")
    end
  end
end