Class: KubeDSL::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/kube-dsl/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(*args, **kwargs)
  @builder = Builder.new(*args, **kwargs)
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



3
4
5
# File 'lib/kube-dsl/generator.rb', line 3

def builder
  @builder
end

Instance Method Details

#generateObject



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

def generate
  generate_resource_files
  generate_autoload_files
  generate_entrypoint_file
end

#generate_autoload_filesObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/kube-dsl/generator.rb', line 28

def generate_autoload_files
  builder.each_autoload_file do |path, ruby_code|
    if File.exist?(path)
      puts "Skipping #{path} because it already exists"
    else
      puts "Writing #{path}"
      File.write(path, ruby_code)
    end
  end
end

#generate_entrypoint_file(&block) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/kube-dsl/generator.rb', line 39

def generate_entrypoint_file(&block)
  if File.exist?(builder.entrypoint_path)
    puts "Skipping #{builder.entrypoint_path} because it already exists"
  else
    puts "Writing #{builder.entrypoint_path}"
    File.write(builder.entrypoint_path, builder.entrypoint(&block))
  end
end

#generate_resource_filesObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kube-dsl/generator.rb', line 15

def generate_resource_files
  builder.each_resource do |res|
    FileUtils.mkdir_p(File.dirname(res.ref.ruby_autoload_path))

    if File.exist?(res.ref.ruby_autoload_path)
      puts "Skipping #{res.ref.ruby_autoload_path} because it already exists"
    else
      puts "Writing #{res.ref.ruby_autoload_path}"
      File.write(res.ref.ruby_autoload_path, res.to_ruby)
    end
  end
end