5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/puppet/parser/functions/plugin_dir.rb', line 5
newfunction(
:plugin_dir,
type: :rvalue,
doc: <<-EOS,
Extracts the end plugin directory of the name
@return String
EOS
) do |arguments|
raise(Puppet::ParseError, 'plugin_dir(): No arguments given') if arguments.empty?
raise(Puppet::ParseError, "plugin_dir(): Too many arguments given (#{arguments.size})") if arguments.size > 2
raise(Puppet::ParseError, 'plugin_dir(): Requires string as first argument') unless arguments[0].is_a?(String)
plugin_name = arguments[0]
items = plugin_name.split('/')
return items[0] if items.count == 1
plugin = items[1]
endname = if plugin.include?('-') if plugin.start_with?('elasticsearch-')
plugin.gsub('elasticsearch-', '')
elsif plugin.start_with?('es-')
plugin.gsub('es-', '')
else
plugin
end
else
plugin
end
return endname
end
|