Class: PDK::Generate::Function
Instance Attribute Summary
Attributes inherited from PuppetObject
#context, #object_name, #options
Instance Method Summary
collapse
#can_run?, #check_preconditions, #module_name, #non_template_files, #run, #spec_only?, #stage_change, #stage_changes, #templates, #update_manager_instance, #with_templates
Constructor Details
#initialize(*_args) ⇒ Function
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/pdk/generate/function.rb', line 6
def initialize(*_args)
super
object_name_parts = @object_name.split('::')
@object_name = if object_name_parts.first == module_name
object_name
else
[module_name, object_name].join('::')
end
end
|
Instance Method Details
#friendly_name ⇒ Object
17
18
19
|
# File 'lib/pdk/generate/function.rb', line 17
def friendly_name
'Function'.freeze
end
|
#template_data ⇒ Object
41
42
43
44
45
|
# File 'lib/pdk/generate/function.rb', line 41
def template_data
func_name = object_name.split('::').last
namespace = object_name.split('::')[0...-1].join('::')
{ name: object_name, func_name: func_name, namespace: namespace }
end
|
#template_files ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/pdk/generate/function.rb', line 21
def template_files
func_name_parts = object_name.split('::')
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..-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
|