diff options
| author | Robert Speicher <rspeicher@gmail.com> | 2015-05-02 23:11:21 -0400 |
|---|---|---|
| committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-26 15:48:30 -0400 |
| commit | c0faf91ff23815404a95cf4510b43dcf5e331c4f (patch) | |
| tree | 81769f125569dd6ea012920544ada1e8666ba4e5 /app/models/label.rb | |
| parent | b06dc74d611192744d34acda944d7ed9e554342a (diff) | |
| download | gitlab-ce-c0faf91ff23815404a95cf4510b43dcf5e331c4f.tar.gz | |
Add `to_reference` for models that support references
Now there is a single source of information for which attribute a model
uses to be referenced, and its special character.
Diffstat (limited to 'app/models/label.rb')
| -rw-r--r-- | app/models/label.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index eee28acefc1..013e6bf5978 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -11,6 +11,8 @@ # class Label < ActiveRecord::Base + include Referable + DEFAULT_COLOR = '#428BCA' default_value_for :color, DEFAULT_COLOR @@ -34,6 +36,31 @@ class Label < ActiveRecord::Base alias_attribute :name, :title + def self.reference_prefix + '~' + end + + # Returns the String necessary to reference this Label in Markdown + # + # format - Symbol format to use (default: :id, optional: :name) + # + # Note that its argument differs from other objects implementing Referable. If + # a non-Symbol argument is given (such as a Project), it will default to :id. + # + # Examples: + # + # Label.first.to_reference # => "~1" + # Label.first.to_reference(:name) # => "~\"bug\"" + # + # Returns a String + def to_reference(format = :id) + if format == :name + %(#{self.class.reference_prefix}"#{name}") + else + "#{self.class.reference_prefix}#{id}" + end + end + def open_issues_count issues.opened.count end |
