Method: PDK::Generate::Function#template_files

Defined in:
lib/pdk/generate/function.rb

#template_filesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pdk/generate/function.rb', line 21

def template_files
  # Calculate the function tests name
  func_name_parts = object_name.split('::')
  # Drop the module name if the object name contains multiple parts
  func_name_parts.delete_at(0) if func_name_parts.length > 1
  files = {
    File.join('functions', 'function_spec.erb') => "#{File.join('spec', 'functions', *func_name_parts)}_spec.rb"
  }
  return files if spec_only?

  func_name_parts = object_name.split('::')[1..]
  template_file = File.join('functions', "#{options[:type]}_function.erb")

  files[template_file] = if options[:type].eql?('v4')
                           "#{File.join('lib', 'puppet', 'functions', module_name, *func_name_parts)}.rb"
                         else
                           "#{File.join('functions', *func_name_parts)}.pp"
                         end
  files
end