Fix rubygems credentials restoration.

Obviously, we don't need to restore credentials if they didn't exist before.
Improve function naming and efficiency.