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.



77
78
79
# File 'lib/kube-dsl/validations.rb', line 77

def initialize(format)
  @format = format
end

Instance Attribute Details

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

#klassesObject



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

Returns:

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