Class: TestBench::Output::Writer
- Inherits:
-
Object
- Object
- TestBench::Output::Writer
- Defined in:
- lib/test_bench/output/writer.rb,
lib/test_bench/output/writer/assertions.rb,
lib/test_bench/output/writer/assertions/line.rb
Defined Under Namespace
Modules: Assertions
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
- #device ⇒ Object
-
#indentation ⇒ Object
Returns the value of attribute indentation.
- #level ⇒ Object
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Class Method Summary collapse
Instance Method Summary collapse
- #color? ⇒ Boolean
- #decrease_indentation ⇒ Object
- #increase_indentation ⇒ Object
-
#initialize(level = nil) ⇒ Writer
constructor
A new instance of Writer.
- #lower_verbosity ⇒ Object
- #normal(prose, **arguments) ⇒ Object
- #quiet(prose, **arguments) ⇒ Object
- #raise_verbosity ⇒ Object
- #verbose(prose, **arguments) ⇒ Object
- #write(prose, bg: nil, fg: nil, render: nil) ⇒ Object
Constructor Details
#initialize(level = nil) ⇒ Writer
Returns a new instance of Writer.
10 11 12 13 14 |
# File 'lib/test_bench/output/writer.rb', line 10 def initialize level=nil @level = level @indentation = 0 @mutex = Mutex.new end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
4 5 6 |
# File 'lib/test_bench/output/writer.rb', line 4 def color @color end |
#device ⇒ Object
33 34 35 |
# File 'lib/test_bench/output/writer.rb', line 33 def device @device ||= StringIO.new end |
#indentation ⇒ Object
Returns the value of attribute indentation.
6 7 8 |
# File 'lib/test_bench/output/writer.rb', line 6 def indentation @indentation end |
#level ⇒ Object
43 44 45 |
# File 'lib/test_bench/output/writer.rb', line 43 def level @level ||= :normal end |
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
8 9 10 |
# File 'lib/test_bench/output/writer.rb', line 8 def mutex @mutex end |
Class Method Details
.build(device) ⇒ Object
16 17 18 19 20 |
# File 'lib/test_bench/output/writer.rb', line 16 def self.build device instance = new instance.device = device instance end |
Instance Method Details
#color? ⇒ Boolean
22 23 24 25 |
# File 'lib/test_bench/output/writer.rb', line 22 def color? return color unless color.nil? device.tty? end |
#decrease_indentation ⇒ Object
27 28 29 30 31 |
# File 'lib/test_bench/output/writer.rb', line 27 def decrease_indentation mutex.synchronize do self.indentation -= 1 end end |
#increase_indentation ⇒ Object
37 38 39 40 41 |
# File 'lib/test_bench/output/writer.rb', line 37 def increase_indentation mutex.synchronize do self.indentation += 1 end end |
#lower_verbosity ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/test_bench/output/writer.rb', line 47 def lower_verbosity if level == :verbose self.level = :normal elsif level == :normal self.level = :quiet end end |
#normal(prose, **arguments) ⇒ Object
55 56 57 58 |
# File 'lib/test_bench/output/writer.rb', line 55 def normal prose, **arguments arguments[:render] = false if level == :quiet write prose, **arguments end |
#quiet(prose, **arguments) ⇒ Object
60 61 62 |
# File 'lib/test_bench/output/writer.rb', line 60 def quiet prose, **arguments write prose, **arguments end |
#raise_verbosity ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/test_bench/output/writer.rb', line 64 def raise_verbosity if level == :quiet self.level = :normal elsif level == :normal self.level = :verbose end end |
#verbose(prose, **arguments) ⇒ Object
72 73 74 75 |
# File 'lib/test_bench/output/writer.rb', line 72 def verbose prose, **arguments arguments[:render] = false unless level == :verbose write prose, **arguments end |
#write(prose, bg: nil, fg: nil, render: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/test_bench/output/writer.rb', line 77 def write prose, bg: nil, fg: nil, render: nil render = true if render.nil? if render text = String.new prose indentation = ' ' * self.indentation prose = Palette.apply prose, bg: bg, fg: fg if color? text = "#{indentation}#{prose}#{$INPUT_RECORD_SEPARATOR}" device.write text end end |