Class: Aireview::ContextBudget::Packer
- Inherits:
-
Object
- Object
- Aireview::ContextBudget::Packer
- Defined in:
- lib/aireview/context_budget.rb
Overview
Files without hunks go first: they are cheap and always useful for the picture of the MR. Text files go in GitLab order while they fit; the first file that does not fit is shown partially, everything after it is not shown. A hunk that would not fit even into an empty budget is skipped with a mark instead of stopping the layout.
Instance Method Summary collapse
-
#initialize(entries, budget:, coverage:) ⇒ Packer
constructor
A new instance of Packer.
- #pack ⇒ Object
Constructor Details
#initialize(entries, budget:, coverage:) ⇒ Packer
Returns a new instance of Packer.
50 51 52 53 54 55 |
# File 'lib/aireview/context_budget.rb', line 50 def initialize(entries, budget:, coverage:) @non_text, @text = entries.partition { |entry| !entry.text? } @budget = budget @coverage = coverage @total_hunks = @text.sum { |entry| entry.hunks.size } end |
Instance Method Details
#pack ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/aireview/context_budget.rb', line 57 def pack @non_text.each { |entry| @coverage.files_unavailable << entry.path if entry.unavailable? } full = (@non_text + @text).map(&:render).join("\n") return Packed.new(text: full, shown_hunks: @total_hunks, total_hunks: @total_hunks) if full.length <= @budget pack_within_limit end |