Class: KubeDSL::Validations::InclusionValidator

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) ⇒ InclusionValidator

Returns a new instance of InclusionValidator.



149
150
151
152
# File 'lib/kube-dsl/validations.rb', line 149

def initialize(field_name, opts)
  @field_name = field_name
  @list = opts[:in]
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



147
148
149
# File 'lib/kube-dsl/validations.rb', line 147

def field_name
  @field_name
end

#listObject (readonly)

Returns the value of attribute list.



147
148
149
# File 'lib/kube-dsl/validations.rb', line 147

def list
  @list
end

Instance Method Details

#validate(obj, errors, nesting) ⇒ Object



154
155
156
157
158
# File 'lib/kube-dsl/validations.rb', line 154

def validate(obj, errors, nesting)
  unless list.include?(obj)
    errors.add([*nesting, field_name].join('.'), "is not in #{list.join(', ')}")
  end
end