Commit 6cbe3867 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'dm-blob-file-type' into 'master'

Add Blob#file_type convenience method

See merge request !11982
parents 299a3a9a 369d681e
Pipeline #8871702 failed with stages
in 181 minutes and 42 seconds
...@@ -155,6 +155,10 @@ class Blob < SimpleDelegator ...@@ -155,6 +155,10 @@ class Blob < SimpleDelegator
@extension ||= extname.downcase.delete('.') @extension ||= extname.downcase.delete('.')
end end
def file_type
Gitlab::FileDetector.type_of(path)
end
def video? def video?
UploaderHelper::VIDEO_EXT.include?(extension) UploaderHelper::VIDEO_EXT.include?(extension)
end end
......
...@@ -52,7 +52,7 @@ module BlobViewer ...@@ -52,7 +52,7 @@ module BlobViewer
def self.can_render?(blob, verify_binary: true) def self.can_render?(blob, verify_binary: true)
return false if verify_binary && binary? != blob.binary? return false if verify_binary && binary? != blob.binary?
return true if extensions&.include?(blob.extension) 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 false
end end
......
...@@ -199,6 +199,14 @@ describe Blob do ...@@ -199,6 +199,14 @@ describe Blob do
end end
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 describe '#simple_viewer' do
context 'when the blob is empty' do context 'when the blob is empty' do
it 'returns an empty viewer' do it 'returns an empty viewer' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment