Skip to content

Commit 14b4150

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 d79b6d0 commit 14b4150

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Rakefile

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

90+
desc 'Regenerate the deprecated unamespaced shims'
91+
task :regenerate_unamespaced_shims do
92+
Dir['lib/puppet/functions/*.rb'].each do |filename|
93+
content = File.read(filename)
94+
95+
unless content =~ /@summary DEPRECATED. Use the namespaced function/
96+
warn("#{filename} does not look like a deprecation shim (skipping)")
97+
next
98+
end
99+
100+
function_name = File.basename(filename, '.rb')
101+
102+
File.write(filename, <<~CODE)
103+
# frozen_string_literal: true
104+
105+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
106+
107+
# @summary DEPRECATED. Use the namespaced function [`stdlib::#{function_name}`](#stdlib#{function_name}) instead.
108+
Puppet::Functions.create_function(:#{function_name}) do
109+
dispatch :deprecation_gen do
110+
repeated_param 'Any', :args
111+
end
112+
def deprecation_gen(*args)
113+
call_function('deprecation', '#{function_name}', 'This function is deprecated, please use stdlib::#{function_name} instead.')
114+
call_function('stdlib::#{function_name}', *args)
115+
end
116+
end
117+
CODE
118+
end
119+
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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
68
repeated_param 'Any', :args
79
end
810
def deprecation_gen(*args)
9-
call_function('deprecation', 'has_interface_with', 'This method is deprecated, please use stdlib::has_interface_with instead.')
11+
call_function('deprecation', 'has_interface_with', 'This function is deprecated, please use stdlib::has_interface_with instead.')
1012
call_function('stdlib::has_interface_with', *args)
1113
end
1214
end

0 commit comments

Comments
 (0)