Skip to content

Commit d4048fb

Browse files
committed
Add a function to update / regenerate deprecated shims
In order to move existing unamespaced functions to the stdlib namespace (#1346) without breaking backwards compatibility, we need some compatibility shims. They will all look-like the same, so add a rake task to regenerate them if we need to update them.
1 parent b3f473f commit d4048fb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,33 @@ EOM
8888
end
8989
end
9090

91+
desc 'Regenerate the deprecated unamespaced shims'
92+
task :regenerate_unamespaced_shims do
93+
Dir['lib/puppet/functions/*.rb'].each do |filename|
94+
content = File.read(filename)
95+
96+
unless content =~ /@summary DEPRECATED. Use the namespaced function/
97+
warn("#{filename} does not look like a deprecation shim (skipping)")
98+
next
99+
end
100+
101+
function_name = File.basename(filename, '.rb')
102+
103+
File.write(filename, <<~CODE)
104+
# frozen_string_literal: true
105+
106+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
107+
108+
# @summary DEPRECATED. Use the namespaced function [`stdlib::#{function_name}`](#stdlib#{function_name}) instead.
109+
Puppet::Functions.create_function(:#{function_name}) do
110+
dispatch :deprecation_gen do
111+
repeated_param 'Any', :args
112+
end
113+
def deprecation_gen(*args)
114+
call_function('deprecation', '#{function_name}', 'This method is deprecated, please use stdlib::#{function_name} instead.')
115+
call_function('stdlib::#{function_name}', *args)
116+
end
117+
end
118+
CODE
119+
end
120+
end

lib/puppet/functions/has_interface_with.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
35
# @summary DEPRECATED. Use the namespaced function [`stdlib::has_interface_with`](#stdlibhas_interface_with) instead.
46
Puppet::Functions.create_function(:has_interface_with) do
57
dispatch :deprecation_gen do

0 commit comments

Comments
 (0)