Class: BoringBackup::Tee

Inherits:
Object
  • Object
show all
Defined in:
lib/boring_backup/tee.rb

Defined Under Namespace

Classes: Sink

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sinks, progress: nil) ⇒ Tee

Returns a new instance of Tee.



27
28
29
30
31
# File 'lib/boring_backup/tee.rb', line 27

def initialize(sinks, progress: nil)
  @sinks = sinks
  @progress = progress
  @bytes = 0
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



25
26
27
# File 'lib/boring_backup/tee.rb', line 25

def bytes
  @bytes
end

Instance Method Details

#write(chunk) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/boring_backup/tee.rb', line 33

def write(chunk)
  @sinks.each { |sink| sink.write(chunk) }

  @bytes += chunk.bytesize
  @progress&.call(@bytes)

  chunk.bytesize
end