Class: KubeDSL::KeyValueFieldRes

Inherits:
Object
  • Object
show all
Includes:
StringHelpers
Defined in:
lib/kube-dsl/key_value_field_res.rb

Constant Summary

Constants included from StringHelpers

StringHelpers::RUBY_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringHelpers

#capitalize, #underscore, #unkeywordify

Constructor Details

#initialize(name, res, type, required) ⇒ KeyValueFieldRes

Returns a new instance of KeyValueFieldRes.



10
11
12
13
14
15
# File 'lib/kube-dsl/key_value_field_res.rb', line 10

def initialize(name, res, type, required)
  @name = name
  @res = res
  @type = type
  @required = required
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/kube-dsl/key_value_field_res.rb', line 6

def name
  @name
end

#requiredObject (readonly) Also known as: required?

Returns the value of attribute required.



6
7
8
# File 'lib/kube-dsl/key_value_field_res.rb', line 6

def required
  @required
end

#resObject (readonly)

Returns the value of attribute res.



6
7
8
# File 'lib/kube-dsl/key_value_field_res.rb', line 6

def res
  @res
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/kube-dsl/key_value_field_res.rb', line 6

def type
  @type
end

Instance Method Details

#fields_to_rbi(_inflector) ⇒ Object



23
24
25
26
27
28
# File 'lib/kube-dsl/key_value_field_res.rb', line 23

def fields_to_rbi(_inflector)
  [
    "T::Sig::WithoutRuntime.sig { params(block: T.nilable(T.proc.void)).returns(::KubeDSL::KeyValueFields) }",
    "def #{underscore(name)}(&block); end"
  ]
end

#fields_to_ruby(_inflector) ⇒ Object



17
18
19
20
21
# File 'lib/kube-dsl/key_value_field_res.rb', line 17

def fields_to_ruby(_inflector)
  [
    "key_value_field(:#{underscore(name)}, format: :#{type})"
  ]
end

#serialize_call(_inflector) ⇒ Object



36
37
38
# File 'lib/kube-dsl/key_value_field_res.rb', line 36

def serialize_call(_inflector)
  "#{underscore(name)}.serialize"
end

#validations(_inflector) ⇒ Object



30
31
32
33
34
# File 'lib/kube-dsl/key_value_field_res.rb', line 30

def validations(_inflector)
  [].tap do |result|
    result << "validates :#{underscore(name)}, kv: { value_format: :#{type} }, presence: #{required? ? 'true' : 'false'}"
  end
end