Class: KubeDSL::ObjectFieldRes

Inherits:
Object
  • Object
show all
Includes:
StringHelpers
Defined in:
lib/kube-dsl/object_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) ⇒ ObjectFieldRes

Returns a new instance of ObjectFieldRes.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/kube-dsl/object_field_res.rb', line 5

def name
  @name
end

#resObject (readonly)

Returns the value of attribute res.



5
6
7
# File 'lib/kube-dsl/object_field_res.rb', line 5

def res
  @res
end

Instance Method Details

#fields_to_ruby(_inflector) ⇒ Object



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

def fields_to_ruby(_inflector)
  [
    "object_field(:#{ruby_safe_name}) { #{res.ref.ruby_namespace.join('::')}::#{res.ref.kind}.new }"
  ]
end

#serialize_call(_inflector) ⇒ Object



25
26
27
# File 'lib/kube-dsl/object_field_res.rb', line 25

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

#validations(_inflector) ⇒ Object



18
19
20
21
22
23
# File 'lib/kube-dsl/object_field_res.rb', line 18

def validations(_inflector)
  [].tap do |result|
    ruby_type = [*res.ref.ruby_namespace, res.ref.kind].join('::')
    result << "validates :#{ruby_safe_name}, object: { kind_of: #{ruby_type} }"
  end
end