Module: Kubes::Compiler::Dsl::Core::Files

Included in:
Syntax::ConfigMap, Syntax::Secret
Defined in:
lib/kubes/compiler/dsl/core/files.rb

Instance Method Summary collapse

Instance Method Details

#current_dirObject



22
23
24
25
26
# File 'lib/kubes/compiler/dsl/core/files.rb', line 22

def current_dir
  resources_line = caller.find { |l| l.include?('.kubes/resources') }
  path = resources_line.split(':').first
  File.dirname(path) # IE: /full/path/.kubes/resources
end

#files(*list) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/kubes/compiler/dsl/core/files.rb', line 3

def files(*list)
  dir = current_dir
  list.each do |file|
    path = "#{dir}/#{file}"
    load_data_from_file(path)
  end
end

#load_data_from_file(path) ⇒ Object



11
12
13
14
15
16
# File 'lib/kubes/compiler/dsl/core/files.rb', line 11

def load_data_from_file(path)
  parser = Kubes::Compiler::Dsl::Core::Parser.new(path)
  items = parser.parse
  items.transform_values! { |v| base64(v) } if secret_class?
  data(items)
end

#secret_class?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/kubes/compiler/dsl/core/files.rb', line 18

def secret_class?
  self.class == Kubes::Compiler::Dsl::Syntax::Secret
end