mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Change FileBlob to accept a base path
This commit is contained in:
@@ -4,8 +4,9 @@ module Linguist
|
|||||||
class FileBlob
|
class FileBlob
|
||||||
include BlobHelper
|
include BlobHelper
|
||||||
|
|
||||||
def initialize(path, name = path)
|
def initialize(path, base_path = nil)
|
||||||
@path, @name = path, name
|
@path = path
|
||||||
|
@name = base_path ? path.sub("#{base_path}/", '') : path
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ module Linguist
|
|||||||
def self.from_directory(base_path)
|
def self.from_directory(base_path)
|
||||||
paths = Dir["#{base_path}/**/*"].inject({}) do |h, path|
|
paths = Dir["#{base_path}/**/*"].inject({}) do |h, path|
|
||||||
if File.file?(path)
|
if File.file?(path)
|
||||||
name = path.sub("#{base_path}/", '')
|
blob = FileBlob.new(path, base_path)
|
||||||
h[name] = FileBlob.new(path, name)
|
h[blob.name] = blob
|
||||||
end
|
end
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ require 'mime/types'
|
|||||||
class TestBlob < Test::Unit::TestCase
|
class TestBlob < Test::Unit::TestCase
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
|
def fixtures_path
|
||||||
|
File.expand_path("../fixtures/blob", __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
def blob(name)
|
def blob(name)
|
||||||
path = File.expand_path("../fixtures/blob/#{name}", __FILE__)
|
FileBlob.new(File.join(fixtures_path, name), fixtures_path)
|
||||||
FileBlob.new(path, name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
|
|||||||
Reference in New Issue
Block a user