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.
75 76 77 |
# File 'lib/kube-dsl/validations.rb', line 75 def initialize(format) @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
73 74 75 |
# File 'lib/kube-dsl/validations.rb', line 73 def format @format end |
Instance Method Details
#klasses ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/kube-dsl/validations.rb', line 83 def klasses @klasses ||= case format when :string, :byte [String] when :integer [Integer] when :boolean [TrueClass, FalseClass] else raise "format '#{format}' not recognized" end end |
#valid?(obj) ⇒ Boolean
79 80 81 |
# File 'lib/kube-dsl/validations.rb', line 79 def valid?(obj) klasses.any? { |k| obj.nil? || obj.is_a?(k) } end |