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



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

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.



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

def field_name
  @field_name
end

#listObject (readonly)

Returns the value of attribute list.



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

def list
  @list
end

Instance Method Details

#validate(obj, errors, nesting) ⇒ Object



158
159
160
161
162
# File 'lib/kube-dsl/validations.rb', line 158

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