Class: Tina::RestorePlan::ObjectCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/tina/restore_plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects) ⇒ ObjectCollection

Returns a new instance of ObjectCollection.



38
39
40
41
# File 'lib/tina/restore_plan.rb', line 38

def initialize(objects)
  @objects = objects
  @total_size = objects.map(&:size).reduce(&:+)
end

Instance Attribute Details

#total_sizeObject (readonly)

Returns the value of attribute total_size.



36
37
38
# File 'lib/tina/restore_plan.rb', line 36

def total_size
  @total_size
end

Instance Method Details

#chunk(max_chunk_size) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

#sizeObject



43
44
45
# File 'lib/tina/restore_plan.rb', line 43

def size
  @objects.size
end