diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-09 19:02:59 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-26 15:48:30 -0400 |
commit | b06dc74d611192744d34acda944d7ed9e554342a (patch) | |
tree | 37987bcfc18b6bcccad339271c065471b29e91ac /app/models/concerns/referable.rb | |
parent | 38cd3d64514655c508eba980b7abc216ef2a1c0b (diff) | |
download | gitlab-ce-b06dc74d611192744d34acda944d7ed9e554342a.tar.gz |
Add Referable concern
Diffstat (limited to 'app/models/concerns/referable.rb')
-rw-r--r-- | app/models/concerns/referable.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/app/models/concerns/referable.rb b/app/models/concerns/referable.rb new file mode 100644 index 00000000000..b41df301c3f --- /dev/null +++ b/app/models/concerns/referable.rb @@ -0,0 +1,52 @@ +# == Referable concern +# +# Contains functionality related to making a model referable in Markdown, such +# as "#1", "!2", "~3", etc. +module Referable + extend ActiveSupport::Concern + + # Returns the String necessary to reference this object in Markdown + # + # from_project - Refering Project object + # + # This should be overridden by the including class. + # + # Examples: + # + # Issue.first.to_reference # => "#1" + # Issue.last.to_reference(other_project) # => "cross-project#1" + # + # Returns a String + def to_reference(_from_project = nil) + '' + end + + module ClassMethods + # The character that prefixes the actual reference identifier + # + # This should be overridden by the including class. + # + # Examples: + # + # Issue.reference_prefix # => '#' + # MergeRequest.reference_prefix # => '!' + # + # Returns a String + def reference_prefix + '' + end + end + + private + + # Check if a reference is being done cross-project + # + # from_project - Refering Project object + def cross_project_reference?(from_project) + if Project === self + self != from_project + else + from_project && project && project != from_project + end + end +end |