Class: KubeDSL::ResourceMeta

Inherits:
Object
  • Object
show all
Includes:
StringHelpers
Defined in:
lib/kube-dsl/resource_meta.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(ref, inflector) ⇒ ResourceMeta

Returns a new instance of ResourceMeta.



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

def initialize(ref, inflector)
  @ref = ref
  @inflector = inflector
  @fields = {}
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#inflectorObject (readonly)

Returns the value of attribute inflector.



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

def inflector
  @inflector
end

#refObject (readonly)

Returns the value of attribute ref.



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

def ref
  @ref
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  fields.size.zero?
end

#external?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/kube-dsl/resource_meta.rb', line 13

def external?
  false
end

#to_rubyObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kube-dsl/resource_meta.rb', line 21

def to_ruby
  ''.tap do |str|
    str << "module #{ref.ruby_namespace.join('::')}\n"
    str << "  class #{ref.kind} < ::KubeDSL::DSLObject\n"
    str << fields_to_ruby
    str << "\n"
    str << validations
    str << "\n"
    str << serialize_method
    str << "\n"
    str << "    def kind_sym\n"
    str << "      :#{underscore(ref.kind)}\n"
    str << "    end\n"
    str << "  end\n"
    str << "end\n"
  end
end