Class: Diffs::StatsComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Diffs::StatsComponent
- Defined in:
- app/components/diffs/stats_component.rb
Instance Attribute Summary collapse
-
#diff_files ⇒ Object
readonly
Returns the value of attribute diff_files.
Instance Method Summary collapse
- #diff_file_path_text(diff_file, max: 60) ⇒ Object
- #diff_files_data ⇒ Object
-
#initialize(diff_files:) ⇒ StatsComponent
constructor
A new instance of StatsComponent.
Constructor Details
#initialize(diff_files:) ⇒ StatsComponent
Returns a new instance of StatsComponent.
7 8 9 10 11 12 |
# File 'app/components/diffs/stats_component.rb', line 7 def initialize(diff_files:) @diff_files = diff_files @changed ||= diff_files.size @added ||= diff_files.sum(&:added_lines) @removed ||= diff_files.sum(&:removed_lines) end |
Instance Attribute Details
#diff_files ⇒ Object (readonly)
Returns the value of attribute diff_files.
5 6 7 |
# File 'app/components/diffs/stats_component.rb', line 5 def diff_files @diff_files end |
Instance Method Details
#diff_file_path_text(diff_file, max: 60) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/components/diffs/stats_component.rb', line 31 def diff_file_path_text(diff_file, max: 60) path = diff_file.new_path return path unless path.size > max && max > 3 "...#{path[-(max - 3)..]}" end |
#diff_files_data ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/diffs/stats_component.rb', line 14 def diff_files_data diffs_map = @diff_files.map do |f| { href: "##{helpers.hexdigest(f.file_path)}", title: f.new_path, name: f.file_path, path: diff_file_path_text(f), icon: diff_file_changed_icon(f), iconColor: diff_file_changed_icon_color(f).to_s, added: f.added_lines, removed: f.removed_lines } end Gitlab::Json.dump(diffs_map) end |