How can I get the following Ruby code to return a nil
, if the regvalue
doesn't exist?
Right now it works fine when there is something to return, but when there isn't it spits out this Error:
Could not retrieve fact='notepadpp', resolution='': The system cannot find the file specified.
I would expect it to just not output anything if the entry doesn't exist.
Facter.add(:notepadpp) do
# restricts module to windows
confine :kernel => :windows
setcode do
require 'facter/util/registry'
notepadpp = nil
regvalue = Facter::Util::Registry.hklm_read('SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++', 'Display')
notepadpp = regvalue if regvalue && !regvalue.empty?
# if regvalue and not regvalue.empty?
# notepadpp = regvalue
# else nil end
end
end