Class: KubeDSL::Validations::ObjectValidator

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, opts) ⇒ ObjectValidator

Returns a new instance of ObjectValidator.



117
118
119
120
# File 'lib/kube-dsl/validations.rb', line 117

def initialize(field_name, opts)
  @field_name = field_name
  @kind_of = opts.fetch(:kind_of)
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



115
116
117
# File 'lib/kube-dsl/validations.rb', line 115

def field_name
  @field_name
end

#kind_ofObject (readonly)

Returns the value of attribute kind_of.



115
116
117
# File 'lib/kube-dsl/validations.rb', line 115

def kind_of
  @kind_of
end

Instance Method Details

#validate(obj, errors, nesting) ⇒ Object



122
123
124
125
126
# File 'lib/kube-dsl/validations.rb', line 122

def validate(obj, errors, nesting)
  unless obj.nil? || obj.is_a?(kind_of)
    errors.add([*nesting, field_name].join('.'), "'#{obj.class.name}', expected '#{kind_of.name}'")
  end
end