Class: TestBench::Session::Output::Writer

Inherits:
Output::Writer
  • Object
show all
Defined in:
lib/test_bench/session/output/writer.rb,
lib/test_bench/session/output/writer/buffer.rb,
lib/test_bench/session/output/writer/defaults.rb,
lib/test_bench/session/output/writer/substitute.rb,
lib/test_bench/session/output/writer/buffer/interactive.rb,
lib/test_bench/session/output/writer/buffer/interactive/viewport.rb

Direct Known Subclasses

Substitute::Writer

Defined Under Namespace

Modules: Buffer, Defaults, Substitute

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alternate_deviceObject



7
8
9
# File 'lib/test_bench/session/output/writer.rb', line 7

def alternate_device
  @alternate_device ||= TestBench::Output::Device::Substitute.build
end

#indentation_depthObject



12
13
14
# File 'lib/test_bench/session/output/writer.rb', line 12

def indentation_depth
  @indentation_depth ||= 0
end

#peerObject

Returns the value of attribute peer.



5
6
7
# File 'lib/test_bench/session/output/writer.rb', line 5

def peer
  @peer
end

Class Method Details

.follow(previous_writer) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/test_bench/session/output/writer.rb', line 25

def self.follow(previous_writer)
  device = previous_writer

  alternate_device = previous_writer.peer
  alternate_device ||= TestBench::Output::Device::Null.build

  previous_digest = previous_writer.digest
  digest = previous_digest.clone

  writer = new
  writer.sync = false
  writer.device = device
  writer.alternate_device = alternate_device
  writer.styling_policy = previous_writer.styling_policy
  writer.digest = digest
  writer.sequence = previous_writer.sequence
  writer.column_sequence = previous_writer.column_sequence
  writer.indentation_depth = previous_writer.indentation_depth
  writer.digest = previous_writer.digest.clone
  writer
end

Instance Method Details

#branchObject



47
48
49
50
51
52
53
54
# File 'lib/test_bench/session/output/writer.rb', line 47

def branch
  alternate = self.class.follow(self)
  primary = self.class.follow(self)

  primary.peer = alternate

  return primary, alternate
end

#configureObject



17
18
19
20
21
22
23
# File 'lib/test_bench/session/output/writer.rb', line 17

def configure
  device = self.device

  self.alternate_device = TestBench::Output::Device::Null.build

  Buffer.configure(self, device:)
end

#decrease_indentationObject Also known as: deindent!



76
77
78
# File 'lib/test_bench/session/output/writer.rb', line 76

def decrease_indentation
  self.indentation_depth -= 1
end

#flushObject



62
63
64
# File 'lib/test_bench/session/output/writer.rb', line 62

def flush
  buffer.flush(device, alternate_device)
end

#follows?(other_writer) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/test_bench/session/output/writer.rb', line 81

def follows?(other_writer)
  if sequence < other_writer.sequence
    false
  elsif device == other_writer
    true
  elsif device == other_writer.peer
    true
  else
    false
  end
end

#increase_indentationObject Also known as: indent!



71
72
73
# File 'lib/test_bench/session/output/writer.rb', line 71

def increase_indentation
  self.indentation_depth += 1
end

#indentObject



56
57
58
59
60
# File 'lib/test_bench/session/output/writer.rb', line 56

def indent
  indentation = '  ' * indentation_depth

  print(indentation)
end

#write!(data) ⇒ Object



66
67
68
69
# File 'lib/test_bench/session/output/writer.rb', line 66

def write!(data)
  device.write(data)
  alternate_device.write(data)
end