I have a method that looks like the method below, and I can't help but shake the feeling that it can be improved. It doesn't really "read" well, and it seems like
checkout could be called only once, somehow.
def ensure_correctness if exist? unless correct_version? delete! checkout end else checkout end end def checkout run_command(['git', 'clone', '--depth', '1', url, path]) end def exist? Dir.exist?(path) end def delete! FileUtils.rm_rf(path) end def correct_version? commit_sha_short == desired_commit_sha_short end
The best I could come up with is moving the code from failing
correct_version? to a new method (which probably isn't a terrible idea, but I wonder if I can do better).
I feel like I'm missing something really obvious here...