Class: KubeDSL::FieldRes

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

Returns a new instance of FieldRes.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#requiredObject (readonly) Also known as: required?

Returns the value of attribute required.



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

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#fields_to_ruby(_inflector) ⇒ Object



15
16
17
# File 'lib/kube-dsl/field_res.rb', line 15

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

#serialize_call(_inflector) ⇒ Object



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

def serialize_call(_inflector)
  ruby_safe_name
end

#validations(_inflector) ⇒ Object



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

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