Class: KubeDSL::Validations::KeyValueValidator
- Inherits:
-
Object
- Object
- KubeDSL::Validations::KeyValueValidator
- Defined in:
- lib/kube-dsl/validations.rb
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#format_validator ⇒ Object
readonly
Returns the value of attribute format_validator.
Instance Method Summary collapse
-
#initialize(field_name, options = {}) ⇒ KeyValueValidator
constructor
A new instance of KeyValueValidator.
- #validate(obj, errors, nesting) ⇒ Object
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, = {}) @field_name = field_name @format_validator ||= FormatValidator.new([:value_format]) end |
Instance Attribute Details
#field_name ⇒ Object (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_validator ⇒ Object (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 |