Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 00:48:12 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 00:48:12 +0400
commitbbfbff3add4c78ce1256ac3bbe787cc6eb9fe1b9 (patch)
tree52fca95c2741559ab0961962a863c7ccb1a7e42b /app/models/commit.rb
parentb53557aca64fbf55f9bbd59849d83daa10b7361f (diff)
Extend models functionality with old decorator methods. Use Repository model
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb51
1 files changed, 47 insertions, 4 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index ea5b451b28f..96c8577f90e 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -10,10 +10,6 @@ class Commit
attr_accessor :raw
- def self.decorate(commits)
- commits.map { |c| Commit.new(c) }
- end
-
def initialize(raw_commit)
raise "Nil as raw commit passed" unless raw_commit
@@ -24,7 +20,54 @@ class Commit
@raw.id
end
+ # Returns a string describing the commit for use in a link title
+ #
+ # Example
+ #
+ # "Commit: Alex Denisov - Project git clone panel"
+ def link_title
+ "Commit: #{author_name} - #{title}"
+ end
+
+ # Returns the commits title.
+ #
+ # Usually, the commit title is the first line of the commit message.
+ # In case this first line is longer than 80 characters, it is cut off
+ # after 70 characters and ellipses (`&hellp;`) are appended.
+ def title
+ title = safe_message
+
+ return no_commit_message if title.blank?
+
+ title_end = title.index(/\n/)
+ if (!title_end && title.length > 80) || (title_end && title_end > 80)
+ title[0..69] << "&hellip;".html_safe
+ else
+ title.split(/\n/, 2).first
+ end
+ end
+
+ # Returns the commits description
+ #
+ # cut off, ellipses (`&hellp;`) are prepended to the commit message.
+ def description
+ description = safe_message
+
+ title_end = description.index(/\n/)
+ if (!title_end && description.length > 80) || (title_end && title_end > 80)
+ "&hellip;".html_safe << description[70..-1]
+ else
+ description.split(/\n/, 2)[1].try(:chomp)
+ end
+ end
+
def method_missing(m, *args, &block)
@raw.send(m, *args, &block)
end
+
+ def respond_to?(method)
+ return true if @raw.respond_to?(method)
+
+ super
+ end
end