cosmetic rewrite of Depot#read_link
authorLunar <lunar@anargeek.net>
Tue, 6 Mar 2012 15:27:10 +0000 (16:27 +0100)
committerLunar <lunar@anargeek.net>
Fri, 23 Mar 2012 17:11:29 +0000 (18:11 +0100)
lib/coquelicot/depot.rb

index d2068a9..4c0dbaf 100644 (file)
@@ -130,17 +130,14 @@ module Coquelicot
     end
 
     def read_link(src)
-      dst = nil
       File.open(links_path) do |f|
-        begin
-          line = f.readline rescue break
-          if line.start_with? "#{src} " then
-            dst = line.split[1]
-            break
-          end
-        end until line.empty?
-      end if File.exists?(links_path)
-      dst
+        until f.eof?
+          return $1 if f.readline =~ /^#{Regexp.escape(src)}\s+(.+)$/
+        end
+      end
+      nil
+    rescue Errno::ENOENT
+      nil
     end
 
     def files