Class: KubeDSL::ResourceMeta
- Inherits:
-
Object
- Object
- KubeDSL::ResourceMeta
- Includes:
- StringHelpers
- Defined in:
- lib/kube-dsl/resource_meta.rb
Constant Summary
Constants included from StringHelpers
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#serialize_handlers ⇒ Object
readonly
Returns the value of attribute serialize_handlers.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #external? ⇒ Boolean
-
#initialize(ref, inflector, serialize_handlers) ⇒ ResourceMeta
constructor
A new instance of ResourceMeta.
- #to_rbi ⇒ Object
- #to_ruby ⇒ Object
Methods included from StringHelpers
#capitalize, #underscore, #unkeywordify
Constructor Details
#initialize(ref, inflector, serialize_handlers) ⇒ ResourceMeta
Returns a new instance of ResourceMeta.
9 10 11 12 13 14 |
# File 'lib/kube-dsl/resource_meta.rb', line 9 def initialize(ref, inflector, serialize_handlers) @ref = ref @inflector = inflector @serialize_handlers = serialize_handlers @fields = {} end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/kube-dsl/resource_meta.rb', line 7 def fields @fields end |
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
7 8 9 |
# File 'lib/kube-dsl/resource_meta.rb', line 7 def inflector @inflector end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
7 8 9 |
# File 'lib/kube-dsl/resource_meta.rb', line 7 def ref @ref end |
#serialize_handlers ⇒ Object (readonly)
Returns the value of attribute serialize_handlers.
7 8 9 |
# File 'lib/kube-dsl/resource_meta.rb', line 7 def serialize_handlers @serialize_handlers end |
Instance Method Details
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/kube-dsl/resource_meta.rb', line 20 def empty? fields.size.zero? end |
#external? ⇒ Boolean
16 17 18 |
# File 'lib/kube-dsl/resource_meta.rb', line 16 def external? false end |
#to_rbi ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kube-dsl/resource_meta.rb', line 51 def to_rbi level = ref.ruby_namespace.size - 1 lines = [ "# typed: strict", '', *ref.ruby_namespace.flat_map.with_index do |mod, idx| indent("module #{mod}", idx) end, *indent("class #{ref.kind} < ::KubeDSL::DSLObject", level + 1), *indent("extend KubeDSL::ValueFields::ClassMethods", level + 2), *indent("extend KubeDSL::Validations::ClassMethods", level + 2), *indent("include KubeDSL::ValueFields::InstanceMethods", level + 2), '', *indent( 'T::Sig::WithoutRuntime.sig {', ' returns(', ' T::Hash[Symbol, T.any(String, Integer, Float, T::Boolean, T::Array[T.untyped], T::Hash[Symbol, T.untyped])]', ' )', '}', 'def serialize; end', level + 2 ), '', *indent( 'T::Sig::WithoutRuntime.sig { returns(Symbol) }', 'def kind_sym; end', level + 2 ), '', *fields_to_rbi(level + 2), *indent('end', level + 1), # class *level.downto(0).flat_map do |idx| indent('end', idx) end ] lines.join("\n") end |
#to_ruby ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kube-dsl/resource_meta.rb', line 24 def to_ruby level = ref.ruby_namespace.size - 1 lines = [ "# typed: true", '', *ref.ruby_namespace.flat_map.with_index do |mod, idx| indent("module #{mod}", idx) end, *indent("class #{ref.kind} < ::KubeDSL::DSLObject", level + 1), *fields_to_ruby(level + 2), *validations(level + 2), *serialize_method(level + 2), *indent( 'def kind_sym', " :#{underscore(ref.kind)}", 'end', level + 2 ), *indent('end', level + 1), # class *level.downto(0).flat_map do |idx| indent('end', idx) end ] lines.join("\n") end |