Class: KubeDSL::Validations::PresenceValidator

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, presence) ⇒ PresenceValidator

Returns a new instance of PresenceValidator.



27
28
29
30
# File 'lib/kube-dsl/validations.rb', line 27

def initialize(field_name, presence)
  @field_name = field_name
  @presence = presence
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



25
26
27
# File 'lib/kube-dsl/validations.rb', line 25

def field_name
  @field_name
end

#presenceObject (readonly)

Returns the value of attribute presence.



25
26
27
# File 'lib/kube-dsl/validations.rb', line 25

def presence
  @presence
end

Instance Method Details

#validate(obj, errors, nesting) ⇒ Object



32
33
34
35
36
# File 'lib/kube-dsl/validations.rb', line 32

def validate(obj, errors, nesting)
  if presence && obj_empty?(obj)
    errors.add([*nesting, field_name].join('.'), 'is required')
  end
end