diff options
author | Mark Chao <mchao@gitlab.com> | 2018-10-04 12:16:51 +0300 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2018-10-30 10:44:55 +0300 |
commit | a4ba973e24ef6767d635c0291c9b6ce8085aef28 (patch) | |
tree | 28efdf13b834db6267fd8bd64d798d8e694b0109 /app/models | |
parent | bc14e4ed1024efa1e0a411bd59e1339fb1af20c0 (diff) |
Allow FoundBlob to access language from gitattributes
Extract language_from_git_attributes as a concern so it can
ben included in two blob classes.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob.rb | 8 | ||||
-rw-r--r-- | app/models/concerns/blob_language_from_git_attributes.rb | 13 |
2 files changed, 14 insertions, 7 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 57c813e3775..4f310e70f4f 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -3,6 +3,7 @@ # Blob is a Rails-specific wrapper around Gitlab::Git::Blob, SnippetBlob and Ci::ArtifactBlob class Blob < SimpleDelegator include Presentable + include BlobLanguageFromGitAttributes CACHE_TIME = 60 # Cache raw blobs referred to by a (mutable) ref for 1 minute CACHE_TIME_IMMUTABLE = 3600 # Cache blobs referred to by an immutable reference for 1 hour @@ -180,13 +181,6 @@ class Blob < SimpleDelegator Gitlab::FileDetector.type_of(path) || Gitlab::FileDetector.type_of(name) end - def language_from_gitattributes - return nil unless project - - repository = project.repository - repository.gitattribute(path, 'gitlab-language') - end - def video? UploaderHelper::VIDEO_EXT.include?(extension) end diff --git a/app/models/concerns/blob_language_from_git_attributes.rb b/app/models/concerns/blob_language_from_git_attributes.rb new file mode 100644 index 00000000000..70213d22147 --- /dev/null +++ b/app/models/concerns/blob_language_from_git_attributes.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Applicable for blob classes with project attribute +module BlobLanguageFromGitAttributes + extend ActiveSupport::Concern + + def language_from_gitattributes + return nil unless project + + repository = project.repository + repository.gitattribute(path, 'gitlab-language') + end +end |