diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index b0053daf..744685a5 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -4,8 +4,9 @@ module Linguist class FileBlob include BlobHelper - def initialize(path, name = path) - @path, @name = path, name + def initialize(path, base_path = nil) + @path = path + @name = base_path ? path.sub("#{base_path}/", '') : path end attr_reader :name diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 2306e42b..2dfd52b3 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -10,8 +10,8 @@ module Linguist def self.from_directory(base_path) paths = Dir["#{base_path}/**/*"].inject({}) do |h, path| if File.file?(path) - name = path.sub("#{base_path}/", '') - h[name] = FileBlob.new(path, name) + blob = FileBlob.new(path, base_path) + h[blob.name] = blob end h end diff --git a/test/test_blob.rb b/test/test_blob.rb index 55ace58d..6592ecd8 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -6,9 +6,12 @@ require 'mime/types' class TestBlob < Test::Unit::TestCase include Linguist + def fixtures_path + File.expand_path("../fixtures/blob", __FILE__) + end + def blob(name) - path = File.expand_path("../fixtures/blob/#{name}", __FILE__) - FileBlob.new(path, name) + FileBlob.new(File.join(fixtures_path, name), fixtures_path) end def test_name