From 0328b1cb3c7c5540617fd30479f11f3e5c46afff Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 14 Jan 2015 08:54:49 -0500 Subject: [PATCH] Use the original FileBlob path for filesystem access FileBlob now remembers the full path that was passed to its constructor, and uses that for performing filesystem access. FileBlob#path continues to return a relative path as before. This ensures that you can call methods like #size and #mode on FileBlobs with relative paths, regardless of the current working directory. --- lib/linguist/file_blob.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 55a420ef..2ca74c2d 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -14,6 +14,7 @@ module Linguist # # Returns a FileBlob. def initialize(path, base_path = nil) + @fullpath = path @path = base_path ? path.sub("#{base_path}/", '') : path end @@ -35,28 +36,28 @@ module Linguist # # Returns a String like '100644' def mode - File.stat(@path).mode.to_s(8) + File.stat(@fullpath).mode.to_s(8) end # Public: File name # # Returns a String def name - File.basename(path) + File.basename(@fullpath) end # Public: Read file contents. # # Returns a String. def data - File.read(@path) + File.read(@fullpath) end # Public: Get byte size # # Returns an Integer. def size - File.size(@path) + File.size(@fullpath) end # Public: Get file extension. @@ -73,7 +74,7 @@ module Linguist # # Returns an Array def extensions - basename, *segments = File.basename(path).split(".") + basename, *segments = name.split(".") segments.map.with_index do |segment, index| "." + segments[index..-1].join(".")