summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-05-15 13:13:25 +0000
committerRobert Speicher <robert@gitlab.com>2017-05-15 13:13:25 +0000
commite2ffb8698751769879e21626c79f9c607a630bf5 (patch)
treead503aec3e0a3c0aa4109b46af09a44813770ffc /lib
parent709ce8a4eccc1e3839d613dc9dff92d477d06df2 (diff)
parent38d84f83600d890f4227fc510a484554f009a1c0 (diff)
downloadgitlab-ce-e2ffb8698751769879e21626c79f9c607a630bf5.tar.gz
Merge branch 'dm-dependency-linker-file-type' into 'master'
Select dependency linker based on file type See merge request !11357
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/dependency_linker/base_linker.rb10
-rw-r--r--lib/gitlab/dependency_linker/gemfile_linker.rb4
-rw-r--r--lib/gitlab/file_detector.rb1
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/gitlab/dependency_linker/base_linker.rb b/lib/gitlab/dependency_linker/base_linker.rb
index 40a4ad11372..5f4027e7e81 100644
--- a/lib/gitlab/dependency_linker/base_linker.rb
+++ b/lib/gitlab/dependency_linker/base_linker.rb
@@ -1,8 +1,14 @@
module Gitlab
module DependencyLinker
class BaseLinker
- def self.link(plain_text, highlighted_text)
- new(plain_text, highlighted_text).link
+ class_attribute :file_type
+
+ def self.support?(blob_name)
+ Gitlab::FileDetector.type_of(blob_name) == file_type
+ end
+
+ def self.link(*args)
+ new(*args).link
end
attr_accessor :plain_text, :highlighted_text
diff --git a/lib/gitlab/dependency_linker/gemfile_linker.rb b/lib/gitlab/dependency_linker/gemfile_linker.rb
index 45be760d89e..9b82e126528 100644
--- a/lib/gitlab/dependency_linker/gemfile_linker.rb
+++ b/lib/gitlab/dependency_linker/gemfile_linker.rb
@@ -1,9 +1,7 @@
module Gitlab
module DependencyLinker
class GemfileLinker < BaseLinker
- def self.support?(blob_name)
- blob_name == 'Gemfile' || blob_name == 'gems.rb'
- end
+ self.file_type = :gemfile
private
diff --git a/lib/gitlab/file_detector.rb b/lib/gitlab/file_detector.rb
index f8b3d0b4965..c6a89597b23 100644
--- a/lib/gitlab/file_detector.rb
+++ b/lib/gitlab/file_detector.rb
@@ -12,6 +12,7 @@ module Gitlab
version: 'version',
gitignore: '.gitignore',
koding: '.koding.yml',
+ gemfile: /\A(Gemfile|gems\.rb)\z/,
gitlab_ci: '.gitlab-ci.yml',
avatar: /\Alogo\.(png|jpg|gif)\z/,
route_map: 'route-map.yml'