Class: KubeDSL::Validations::PresenceValidator
- Inherits:
-
Object
- Object
- KubeDSL::Validations::PresenceValidator
- Defined in:
- lib/kube-dsl/validations.rb
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#presence ⇒ Object
readonly
Returns the value of attribute presence.
Instance Method Summary collapse
-
#initialize(field_name, presence) ⇒ PresenceValidator
constructor
A new instance of PresenceValidator.
- #validate(obj, errors, nesting) ⇒ Object
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_name ⇒ Object (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 |
#presence ⇒ Object (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 |