Class: KubeDSL::Validations::FormatValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/kube-dsl/validations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#formatObject (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

#klassesObject



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

Returns:

  • (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