Skip to content

Commit f54aa32

Browse files
committed
Simplify variable assignment
Prior to this commit when reading a registry value, Puppet would assign the result to the "result" variable in every single instance of a case expression. This commit simplifies that assignment by moving it outside of the case expression.
1 parent db1edda commit f54aa32

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/puppet/util/windows/registry.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,22 @@ def read(key, name_ptr, *rtype)
239239
string_length = (byte_length / FFI.type_size(:wchar)) - 1 if byte_length > 0
240240

241241
begin
242-
case type
243-
when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ
244-
result = [ type, data_ptr.read_wide_string(string_length, Encoding::UTF_8, true) ]
245-
when Win32::Registry::REG_MULTI_SZ
246-
result = [ type, data_ptr.read_wide_string(string_length).split(/\0/) ]
247-
when Win32::Registry::REG_BINARY
248-
result = [ type, data_ptr.read_bytes(byte_length) ]
249-
when Win32::Registry::REG_DWORD
250-
result = [ type, data_ptr.read_dword ]
251-
when Win32::Registry::REG_DWORD_BIG_ENDIAN
252-
result = [ type, data_ptr.order(:big).read_dword ]
253-
when Win32::Registry::REG_QWORD
254-
result = [ type, data_ptr.read_qword ]
255-
else
256-
raise TypeError, _("Type %{type} is not supported.") % { type: type }
257-
end
242+
result = case type
243+
when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ
244+
[ type, data_ptr.read_wide_string(string_length, Encoding::UTF_8, true) ]
245+
when Win32::Registry::REG_MULTI_SZ
246+
[ type, data_ptr.read_wide_string(string_length).split(/\0/) ]
247+
when Win32::Registry::REG_BINARY
248+
[ type, data_ptr.read_bytes(byte_length) ]
249+
when Win32::Registry::REG_DWORD
250+
[ type, data_ptr.read_dword ]
251+
when Win32::Registry::REG_DWORD_BIG_ENDIAN
252+
[ type, data_ptr.order(:big).read_dword ]
253+
when Win32::Registry::REG_QWORD
254+
[ type, data_ptr.read_qword ]
255+
else
256+
raise TypeError, _("Type %{type} is not supported.") % { type: type }
257+
end
258258
rescue IndexError => ex
259259
raise if (ex.message !~ /^Memory access .* is out of bounds$/i)
260260
parent_key_name = key.parent ? "#{key.parent.keyname}\\" : ""

0 commit comments

Comments
 (0)