Class: StoryTeller::IO::OutputBuffer
- Defined in:
- lib/story_teller/session.rb
Overview
The OutputBuffer class
Instance Method Summary collapse
- #drain ⇒ Object
-
#initialize ⇒ OutputBuffer
constructor
A new instance of OutputBuffer.
- #reset ⇒ Object
- #write(value) ⇒ Object
Constructor Details
#initialize ⇒ OutputBuffer
Returns a new instance of OutputBuffer.
149 150 151 152 |
# File 'lib/story_teller/session.rb', line 149 def initialize @content = String.new # rubocop: disable Style/EmptyLiteral @mutex = Mutex.new end |
Instance Method Details
#drain ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/story_teller/session.rb', line 160 def drain @mutex.synchronize do content = @content.dup @content.clear content.strip.length.positive? ? content : '' end end |
#reset ⇒ Object
168 169 170 |
# File 'lib/story_teller/session.rb', line 168 def reset @mutex.synchronize { @content.clear } end |
#write(value) ⇒ Object
154 155 156 157 158 |
# File 'lib/story_teller/session.rb', line 154 def write(value) return if value.nil? @mutex.synchronize { @content << value.to_s } end |