class Tina::RestorePlan::ObjectCollection

Attributes

total_size[R]

Public Class Methods

new(objects) click to toggle source
# File lib/tina/restore_plan.rb, line 38
def initialize(objects)
  @objects = objects
  @total_size = objects.map(&:size).reduce(&:+)
end

Public Instance Methods

chunk(max_chunk_size) click to toggle source
# File lib/tina/restore_plan.rb, line 47
def chunk(max_chunk_size)
  @chunks ||= begin
    chunks = @objects.chunk(sum: 0, index: 0) do |object, state|
      state[:sum] += object.size
      if state[:sum] > max_chunk_size
        state[:sum] = object.size
        state[:index] += 1
      end
      state[:index]
    end
    chunks.map(&:last)
  end
end
size() click to toggle source
# File lib/tina/restore_plan.rb, line 43
def size
  @objects.size
end