Skip to content
Snippets Groups Projects
Commit 369d681e authored by Douwe Maan's avatar Douwe Maan
Browse files

Add Blob#file_type convenience method

parent 1bc80c25
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -155,6 +155,10 @@ class Blob < SimpleDelegator
@extension ||= extname.downcase.delete('.')
end
 
def file_type
Gitlab::FileDetector.type_of(path)
end
def video?
UploaderHelper::VIDEO_EXT.include?(extension)
end
Loading
Loading
Loading
Loading
@@ -52,7 +52,7 @@ module BlobViewer
def self.can_render?(blob, verify_binary: true)
return false if verify_binary && binary? != blob.binary?
return true if extensions&.include?(blob.extension)
return true if file_types&.include?(Gitlab::FileDetector.type_of(blob.path))
return true if file_types&.include?(blob.file_type)
 
false
end
Loading
Loading
Loading
Loading
@@ -199,6 +199,14 @@ describe Blob do
end
end
 
describe '#file_type' do
it 'returns the file type' do
blob = fake_blob(path: 'README.md')
expect(blob.file_type).to eq(:readme)
end
end
describe '#simple_viewer' do
context 'when the blob is empty' do
it 'returns an empty viewer' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment