Class: KubeManifest::Describer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kube_manifest/describe.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDescriber

Returns a new instance of Describer.



79
80
81
# File 'lib/kube_manifest/describe.rb', line 79

def initialize
  @describers = []
end

Instance Attribute Details

#describersObject

Returns the value of attribute describers.



77
78
79
# File 'lib/kube_manifest/describe.rb', line 77

def describers
  @describers
end

Class Method Details

.append(klass, defaults, block) ⇒ Object



83
84
85
# File 'lib/kube_manifest/describe.rb', line 83

def self.append(klass, defaults, block)
  self.instance.describers.append([klass, defaults, block])
end

.describe!Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/kube_manifest/describe.rb', line 87

def self.describe!
  self.instance.describers.each do |pair|
    klass, defaults, block = pair

    ::KubeManifest.define_singleton_method klass.name.split('::').last do |**args, &blk|
      ::KubeManifest::Context.new(klass, args, &blk)
    end

    unless defaults.empty?
      klass.define_method(:initialize) do |**kwargs|
        super(**kwargs)
        defaults.each_pair do |key, value|
          instance_variable_set("@#{key}", value)
        end
      end
    end

    describer = ::KubeManifest::Describe.new(klass)
    defaults.each_pair do |key, value|
      describer.send(key.to_sym, value)
    end
    describer.instance_eval(&block) if block
  end
  self.instance.describers.clear
end