Class: Gitlab::TreeSummary
- Inherits:
-
Object
- Object
- Gitlab::TreeSummary
- Includes:
- Utils::StrongMemoize, MarkupHelper
- Defined in:
- lib/gitlab/tree_summary.rb
Constant Summary collapse
- CACHE_EXPIRE_IN =
1.hour
- MAX_OFFSET =
2**31 - 1
Instance Attribute Summary collapse
-
#commit ⇒ Object
readonly
Returns the value of attribute commit.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#resolved_commits ⇒ Object
readonly
Returns the value of attribute resolved_commits.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #fetch_logs ⇒ Object
-
#initialize(commit, project, user, params = {}) ⇒ TreeSummary
constructor
A new instance of TreeSummary.
-
#summarize ⇒ Object
Creates a summary of the tree entries for a commit, within the window of entries defined by the offset and limit parameters.
Methods included from MarkupHelper
#cross_project_reference, #first_line_in_markdown, #link_to_html, #link_to_markdown, #link_to_markdown_field, #markdown, #markdown_field, #markup, #render_wiki_content
Constructor Details
#initialize(commit, project, user, params = {}) ⇒ TreeSummary
Returns a new instance of TreeSummary.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gitlab/tree_summary.rb', line 13 def initialize(commit, project, user, params = {}) @commit = commit @project = project @user = user @path = params.fetch(:path, nil).presence @offset = [params.fetch(:offset, 0).to_i, MAX_OFFSET].min @limit = (params.fetch(:limit, 25) || 25).to_i # Ensure that if multiple tree entries share the same last commit, they share # a ::Commit instance. This prevents us from rendering the same commit title # multiple times @resolved_commits = {} end |
Instance Attribute Details
#commit ⇒ Object (readonly)
Returns the value of attribute commit.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def commit @commit end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def offset @offset end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def path @path end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def project @project end |
#resolved_commits ⇒ Object (readonly)
Returns the value of attribute resolved_commits.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def resolved_commits @resolved_commits end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'lib/gitlab/tree_summary.rb', line 11 def user @user end |
Instance Method Details
#fetch_logs ⇒ Object
55 56 57 58 59 |
# File 'lib/gitlab/tree_summary.rb', line 55 def fetch_logs logs = summarize [logs.first(limit).as_json, next_offset(logs.size)] end |
#summarize ⇒ Object
Creates a summary of the tree entries for a commit, within the window of entries defined by the offset and limit parameters. This consists of two return values:
- An Array of Hashes containing the following keys:
- file_name: The full path of the tree entry
- commit: The last ::Commit to touch this entry in the tree
- commit_path: URI of the commit in the web interface
- commit_title_html: Rendered commit title
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gitlab/tree_summary.rb', line 37 def summarize return [] if offset < 0 commits_hsh = fetch_last_cached_commits_list prerender_commit_full_titles!(commits_hsh.values) commits_hsh.map do |path_key, commit| commit = cache_commit(commit) { file_name: File.basename(path_key).force_encoding(Encoding::UTF_8), commit: commit, commit_path: commit_path(commit), commit_title_html: markdown_field(commit, :full_title) } end end |