Class: KubeDSL::Validations::FormatValidator
- Inherits:
-
Object
- Object
- KubeDSL::Validations::FormatValidator
- Defined in:
- lib/kube-dsl/validations.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
-
#initialize(format) ⇒ FormatValidator
constructor
A new instance of FormatValidator.
- #klasses ⇒ Object
- #valid?(obj) ⇒ Boolean
Constructor Details
#initialize(format) ⇒ FormatValidator
Returns a new instance of FormatValidator.
77 78 79 |
# File 'lib/kube-dsl/validations.rb', line 77 def initialize(format) @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
75 76 77 |
# File 'lib/kube-dsl/validations.rb', line 75 def format @format end |
Instance Method Details
#klasses ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/kube-dsl/validations.rb', line 85 def klasses @klasses ||= case format when :string, :byte [String] when :integer [Integer] when :number [Integer, Float] when :boolean [TrueClass, FalseClass] else raise "format '#{format}' not recognized" end end |
#valid?(obj) ⇒ Boolean
81 82 83 |
# File 'lib/kube-dsl/validations.rb', line 81 def valid?(obj) klasses.any? { |k| obj.nil? || obj.is_a?(k) } end |