summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert "ar" Gerus <ar@bash.org.pl>2013-05-23 08:28:49 +0200
committerRobert "ar" Gerus <ar@bash.org.pl>2013-05-23 08:28:49 +0200
commitc5b5c9b7758433c23d2984445a0421efe060e352 (patch)
tree449a2a37a3a0973a169a9b117c930a97a8888f1d
parent6feefbe5922b945d567006c760b2a1df94b4ece4 (diff)
downloadup-master.tar.gz
up-master.tar.bz2
up-master.zip
Simplify the code by using a ternary operator.HEADmaster
-rwxr-xr-xup.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/up.rb b/up.rb
index f14dcb4..83492cd 100755
--- a/up.rb
+++ b/up.rb
@@ -15,15 +15,11 @@ ARGV.each do |path|
# add the dot here, so that if we get a file without dot, we don't have
# to conditionally add the dot later on
ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/)
+ # make sure ext isn't nil
+ ext = ext.nil? ? "" : ext
content = open(path).read
md5 = Digest::MD5.hexdigest(content)
- # basically a glorified syntax sugar for (ext.nil? ? "" : ext)
- begin
- Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
- # we probably tried to add nil to a string ("ext" could possibly be nil)
- rescue TypeError
- Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5)
- end
+ Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext)
}
end