Created
March 14, 2014 05:42
-
-
Save jessereynolds/9542669 to your computer and use it in GitHub Desktop.
ruby refactoring multiple unlesses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # before: | |
| if command == 'move' | |
| unless options.destination | |
| puts "Error - 'move' requires a --destination" | |
| puts "\n#{optparse}" | |
| end | |
| unless File.exist?(options.destination) | |
| puts "Error - destination does not exist" | |
| puts "\n#{optparse}" | |
| end | |
| unless File.directory?(options.destination) | |
| puts "Error - destination is not a directory" | |
| puts "\n#{optparse}" | |
| end | |
| unless File.writeable?(options.destination) | |
| puts "Error - destination directory is not writeable" | |
| puts "\n#{optparse}" | |
| end | |
| end | |
| # after | |
| if command == 'move' | |
| error = case | |
| when !options.destination | |
| "Error - 'move' requires a --destination" | |
| when !File.exist?(options.destination) | |
| "Error - destination does not exist" | |
| when !File.directory?(options.destination) | |
| "Error - destination is not a directory" | |
| when !File.writeable?(options.destination) | |
| "Error - destination directory is not writeable" | |
| end | |
| if error | |
| puts "#{error}\n#{optparse}" | |
| exit 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment