Class: Bringit::DiffCollection
- Inherits:
-
Object
- Object
- Bringit::DiffCollection
- Includes:
- Enumerable
- Defined in:
- lib/bringit/diff_collection.rb
Constant Summary collapse
- DEFAULT_LIMITS =
{ max_files: 100, max_lines: 5000 }.freeze
Instance Method Summary collapse
- #decorate! ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(iterator, options = {}) ⇒ DiffCollection
constructor
A new instance of DiffCollection.
- #overflow? ⇒ Boolean
- #real_size ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(iterator, options = {}) ⇒ DiffCollection
Returns a new instance of DiffCollection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bringit/diff_collection.rb', line 7 def initialize(iterator, = {}) @iterator = iterator @max_files = .fetch(:max_files, DEFAULT_LIMITS[:max_files]) @max_lines = .fetch(:max_lines, DEFAULT_LIMITS[:max_lines]) @max_bytes = @max_files * 5120 # Average 5 KB per file @safe_max_files = [@max_files, DEFAULT_LIMITS[:max_files]].min @safe_max_lines = [@max_lines, DEFAULT_LIMITS[:max_lines]].min @safe_max_bytes = @safe_max_files * 5120 # Average 5 KB per file @all_diffs = !!.fetch(:all_diffs, false) @no_collapse = !!.fetch(:no_collapse, true) @deltas_only = !!.fetch(:deltas_only, false) @line_count = 0 @byte_count = 0 @overflow = false @array = Array.new end |
Instance Method Details
#decorate! ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/bringit/diff_collection.rb', line 59 def decorate! collection = each_with_index do |element, i| @array[i] = yield(element) end @populated = true collection end |
#each(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bringit/diff_collection.rb', line 25 def each(&block) if @populated # @iterator.each is slower than just iterating the array in place @array.each(&block) elsif @deltas_only each_delta(&block) else each_patch(&block) end end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/bringit/diff_collection.rb', line 36 def empty? !@iterator.any? end |
#overflow? ⇒ Boolean
40 41 42 43 |
# File 'lib/bringit/diff_collection.rb', line 40 def overflow? populate! !!@overflow end |
#real_size ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bringit/diff_collection.rb', line 49 def real_size populate! if @overflow "#{size}+" else size.to_s end end |
#size ⇒ Object
45 46 47 |
# File 'lib/bringit/diff_collection.rb', line 45 def size @size ||= count # forces a loop using each method end |