Class: KubeDSL::ArrayFieldRes
- Inherits:
-
Object
- Object
- KubeDSL::ArrayFieldRes
- Includes:
- RbiHelpers, StringHelpers
- Defined in:
- lib/kube-dsl/array_field_res.rb
Constant Summary
Constants included from RbiHelpers
Constants included from StringHelpers
Instance Attribute Summary collapse
-
#elem_res ⇒ Object
readonly
Returns the value of attribute elem_res.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
(also: #required?)
readonly
Returns the value of attribute required.
Instance Method Summary collapse
- #fields_to_rbi(inflector) ⇒ Object
- #fields_to_ruby(inflector) ⇒ Object
-
#initialize(name, required, elem_res) ⇒ ArrayFieldRes
constructor
A new instance of ArrayFieldRes.
- #serialize_call(inflector) ⇒ Object
- #validations(inflector) ⇒ Object
Methods included from RbiHelpers
Methods included from StringHelpers
#capitalize, #underscore, #unkeywordify
Constructor Details
#initialize(name, required, elem_res) ⇒ ArrayFieldRes
Returns a new instance of ArrayFieldRes.
11 12 13 14 15 |
# File 'lib/kube-dsl/array_field_res.rb', line 11 def initialize(name, required, elem_res) @name = name @required = required @elem_res = elem_res end |
Instance Attribute Details
#elem_res ⇒ Object (readonly)
Returns the value of attribute elem_res.
7 8 9 |
# File 'lib/kube-dsl/array_field_res.rb', line 7 def elem_res @elem_res end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/kube-dsl/array_field_res.rb', line 7 def name @name end |
#required ⇒ Object (readonly) Also known as: required?
Returns the value of attribute required.
7 8 9 |
# File 'lib/kube-dsl/array_field_res.rb', line 7 def required @required end |
Instance Method Details
#fields_to_rbi(inflector) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kube-dsl/array_field_res.rb', line 24 def fields_to_rbi(inflector) [ 'T::Sig::WithoutRuntime.sig {', ' params(', ' elem_name: T.nilable(Symbol),', " block: T.nilable(T.proc.returns(#{rbi_type_for(ruby_type)}))", " ).returns(T::Array[#{rbi_type_for(ruby_type)}])", '}', "def #{plural_name(inflector)}(elem_name = nil, &block); end" ] end |
#fields_to_ruby(inflector) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/kube-dsl/array_field_res.rb', line 17 def fields_to_ruby(inflector) [ "array_field(:#{underscore(inflector.singularize(name))})"\ " { #{elem_res.ref.ruby_namespace.join('::')}::#{elem_res.ref.kind}.new }" ] end |
#serialize_call(inflector) ⇒ Object
42 43 44 |
# File 'lib/kube-dsl/array_field_res.rb', line 42 def serialize_call(inflector) "#{plural_name(inflector)}.map(&:serialize)" end |
#validations(inflector) ⇒ Object
36 37 38 39 40 |
# File 'lib/kube-dsl/array_field_res.rb', line 36 def validations(inflector) [].tap do |result| result << "validates :#{plural_name(inflector)}, array: { kind_of: #{ruby_type} }, presence: #{required? ? 'true' : 'false'}" end end |