Class: KubeDSL::FieldRes

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

Constant Summary

Constants included from RbiHelpers

RbiHelpers::TYPE_MAP

Constants included from StringHelpers

StringHelpers::RUBY_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RbiHelpers

#rbi_type_for

Methods included from StringHelpers

#capitalize, #underscore, #unkeywordify

Constructor Details

#initialize(name, type, required) ⇒ FieldRes

Returns a new instance of FieldRes.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/kube-dsl/field_res.rb', line 7

def name
  @name
end

#requiredObject (readonly) Also known as: required?

Returns the value of attribute required.



7
8
9
# File 'lib/kube-dsl/field_res.rb', line 7

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/kube-dsl/field_res.rb', line 7

def type
  @type
end

Instance Method Details

#fields_to_rbi(inflector) ⇒ Object



21
22
23
24
25
26
# File 'lib/kube-dsl/field_res.rb', line 21

def fields_to_rbi(inflector)
  [
    "T::Sig::WithoutRuntime.sig { params(val: T.nilable(#{rbi_type_for(@type)})).returns(T.nilable(#{rbi_type_for(@type)})) }",
    "def #{ruby_safe_name}(val = nil); end"
  ]
end

#fields_to_ruby(_inflector) ⇒ Object



17
18
19
# File 'lib/kube-dsl/field_res.rb', line 17

def fields_to_ruby(_inflector)
  ["value_field :#{ruby_safe_name}"]
end

#serialize_call(_inflector) ⇒ Object



34
35
36
# File 'lib/kube-dsl/field_res.rb', line 34

def serialize_call(_inflector)
  ruby_safe_name
end

#validations(_inflector) ⇒ Object



28
29
30
31
32
# File 'lib/kube-dsl/field_res.rb', line 28

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