Class: Sus::Output::Buffered
- Inherits:
-
Object
- Object
- Sus::Output::Buffered
- Defined in:
- lib/sus/output/buffered.rb
Overview
Represents a buffered output handler that stores output operations for later replay.
Constant Summary collapse
- INDENT =
The indent operation marker.
[:indent].freeze
- OUTDENT =
The outdent operation marker.
[:outdent].freeze
Instance Attribute Summary collapse
-
#chunks ⇒ Object
readonly
Returns the value of attribute chunks.
-
#tee ⇒ Object
readonly
Returns the value of attribute tee.
- #The stored output chunks.(storedoutputchunks.) ⇒ Object readonly
Instance Method Summary collapse
-
#append(buffer) ⇒ Object
Append chunks from another buffer.
-
#assert(*arguments) ⇒ Object
Record an assertion.
-
#buffered ⇒ Object
Create a nested buffered output handler.
-
#each(&block) ⇒ Object
Iterate over stored chunks.
-
#error(*arguments) ⇒ Object
Record an error.
-
#indent ⇒ Object
Increase indentation level.
-
#indented ⇒ Object
Execute a block with increased indentation.
-
#inform(*arguments) ⇒ Object
Record an informational message.
-
#initialize(tee = nil) ⇒ Buffered
constructor
Initialize a new Buffered output handler.
- #inspect ⇒ Object
-
#outdent ⇒ Object
Decrease indentation level.
-
#puts(*arguments) ⇒ Object
Write output followed by a newline.
-
#skip(*arguments) ⇒ Object
Record a skip.
- #string ⇒ Object
- #The output handler to tee to.=(outputhandlertoteeto. = (value)) ⇒ Object
-
#write(*arguments) ⇒ Object
Write output.
Constructor Details
#initialize(tee = nil) ⇒ Buffered
Initialize a new Buffered output handler.
15 16 17 18 |
# File 'lib/sus/output/buffered.rb', line 15 def initialize(tee = nil) @chunks = Array.new @tee = tee end |
Instance Attribute Details
#chunks ⇒ Object (readonly)
Returns the value of attribute chunks.
21 22 23 |
# File 'lib/sus/output/buffered.rb', line 21 def chunks @chunks end |
#tee ⇒ Object (readonly)
Returns the value of attribute tee.
24 25 26 |
# File 'lib/sus/output/buffered.rb', line 24 def tee @tee end |
#The stored output chunks.(storedoutputchunks.) ⇒ Object (readonly)
21 |
# File 'lib/sus/output/buffered.rb', line 21 attr :chunks |
Instance Method Details
#append(buffer) ⇒ Object
Append chunks from another buffer.
49 50 51 52 |
# File 'lib/sus/output/buffered.rb', line 49 def append(buffer) @chunks.concat(buffer.chunks) @tee&.append(buffer) end |
#assert(*arguments) ⇒ Object
Record an assertion.
104 105 106 107 |
# File 'lib/sus/output/buffered.rb', line 104 def assert(*arguments) @chunks << [:assert, *arguments] @tee&.assert(*arguments) end |
#buffered ⇒ Object
Create a nested buffered output handler.
37 38 39 |
# File 'lib/sus/output/buffered.rb', line 37 def buffered self.class.new(self) end |
#each(&block) ⇒ Object
Iterate over stored chunks.
43 44 45 |
# File 'lib/sus/output/buffered.rb', line 43 def each(&block) @chunks.each(&block) end |
#error(*arguments) ⇒ Object
Record an error.
118 119 120 121 |
# File 'lib/sus/output/buffered.rb', line 118 def error(*arguments) @chunks << [:error, *arguments] @tee&.error(*arguments) end |
#indent ⇒ Object
Increase indentation level.
65 66 67 68 |
# File 'lib/sus/output/buffered.rb', line 65 def indent @chunks << INDENT @tee&.indent end |
#indented ⇒ Object
Execute a block with increased indentation.
81 82 83 84 85 86 |
# File 'lib/sus/output/buffered.rb', line 81 def indented self.indent yield ensure self.outdent end |
#inform(*arguments) ⇒ Object
Record an informational message.
125 126 127 128 |
# File 'lib/sus/output/buffered.rb', line 125 def inform(*arguments) @chunks << [:inform, *arguments] @tee&.inform(*arguments) end |
#inspect ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sus/output/buffered.rb', line 27 def inspect if @tee "\#<#{self.class.name} #{@chunks.size} chunks -> #{@tee.class}>" else "\#<#{self.class.name} #{@chunks.size} chunks>" end end |
#outdent ⇒ Object
Decrease indentation level.
74 75 76 77 |
# File 'lib/sus/output/buffered.rb', line 74 def outdent @chunks << OUTDENT @tee&.outdent end |
#puts(*arguments) ⇒ Object
Write output followed by a newline.
97 98 99 100 |
# File 'lib/sus/output/buffered.rb', line 97 def puts(*arguments) @chunks << [:puts, *arguments] @tee&.puts(*arguments) end |
#skip(*arguments) ⇒ Object
Record a skip.
111 112 113 114 |
# File 'lib/sus/output/buffered.rb', line 111 def skip(*arguments) @chunks << [:skip, *arguments] @tee&.skip(*arguments) end |
#string ⇒ Object
55 56 57 58 59 |
# File 'lib/sus/output/buffered.rb', line 55 def string io = StringIO.new Text.new(io).append(@chunks) return io.string end |
#The output handler to tee to.=(outputhandlertoteeto. = (value)) ⇒ Object
24 |
# File 'lib/sus/output/buffered.rb', line 24 attr :tee |
#write(*arguments) ⇒ Object
Write output.
90 91 92 93 |
# File 'lib/sus/output/buffered.rb', line 90 def write(*arguments) @chunks << [:write, *arguments] @tee&.write(*arguments) end |